// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3OrientedBox.cpp
// Function: gaps::R3OrientedBox::Reset(gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, double, double, double)
void R3OrientedBox::
Reset(const R3Point& center, 
    const R3Vector& axis0, const R3Vector& axis1, 
    RNLength radius0, RNLength radius1, RNLength radius2)
{
    // Check axes
    assert(RNIsPositive(axis0.Length()));
    assert(RNIsPositive(axis1.Length()));

    // Normalize and orthogonalize axes
    R3Vector axis[3];
    axis[0] = axis0;
    axis[0].Normalize();
    axis[1] = axis1;
    axis[1].Normalize();
    axis[1] = axis[0] % axis[1];
    axis[1] = axis[1] % axis[0];
    axis[1].Normalize();
    axis[2] = axis[0] % axis[1];
    axis[2].Normalize();

    // Assign radii
    radius[0] = radius0;
    radius[1] = radius1;
    radius[2] = radius2;

#if 0
    // Sort axes
    // This works, but is not always desirable
    R3Vector swap_axis;
    RNScalar swap_radius;
    if (radius[1] > radius[0]) {
      swap_axis = axis[0]; swap_radius = radius[0];
      axis[0] = axis[1]; radius[0] = radius[1];
      axis[1] = swap_axis; radius[1] = swap_radius;
    }
    if (radius[2] > radius[0]) {
      swap_axis = axis[0]; swap_radius = radius[0];
      axis[0] = axis[2]; radius[0] = radius[2];
      axis[2] = swap_axis; radius[2] = swap_radius;
    }
    if (radius[2] > radius[1]) {
      swap_axis = axis[1]; swap_radius = radius[1];
      axis[1] = axis[2]; radius[1] = radius[2];
      axis[2] = swap_axis; radius[2] = swap_radius;
    }
    
    // Ensure right-handed coordinate system
    axis[2] = axis[0] % axis[1];
    axis[2].Normalize();
#endif

    // Set coordinate system
    cs.Reset(center, R3Triad(axis[0], axis[1], axis[2]));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm2, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
leaq (%rsp,%r15), %rdi
addq $0x20, %rdi
callq 0x3cfc4
addq $0x18, %r15
cmpq $0x48, %r15
jne 0x56b44
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x3d752
movq %r15, %rdi
callq 0x3d2dc
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x3d752
movq %r12, %rdi
callq 0x3d2dc
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3d8fa
movq %r12, %rdi
movq %r13, %rsi
callq 0x3d752
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3d8fa
movq %r12, %rdi
movq %r13, %rsi
callq 0x3d752
movq %r12, %rdi
callq 0x3d2dc
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3d8fa
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3d752
movq %rbp, %rdi
callq 0x3d2dc
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x68(%r14)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x70(%r14)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x78(%r14)
addq $0x8, %r14
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x2ab98
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2a870
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq