// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3OrientedBox.cpp
// Function: gaps::R3OrientedBox::R3OrientedBox(gaps::RNArray<gaps::R3Point*> const&)
R3OrientedBox::
R3OrientedBox(const RNArray<R3Point *>& points)
{
#if 0
    // This is correct, but produces bboxes that are too big (diagonal)
  
    // Compute coordinate system
    R3Point centroid = R3Centroid(points);
    R3Triad axes = R3PrincipleAxes(centroid, points);

    // Compute ranges
    R3Box r = R3null_box;
    for (int i = 0; i < points.NEntries(); i++) {
      R3Point *point = points.Kth(i);
      R3Vector v = *point - centroid;
      RNLength r0 = v.Dot(axes[0]);
      RNLength r1 = v.Dot(axes[1]);
      RNLength r2 = v.Dot(axes[2]);
      r.Union(R3Point(r0, r1, r2));
    }

    // Compute center
    R3Point c = r.Centroid();
    R3Point center = centroid + axes[0]*c[0] + axes[1]*c[1] + axes[2]*c[2];

    // Initialize everything
    Reset(center, axes[0], axes[1], r.XRadius(), r.YRadius(), r.ZRadius());
#else
    // Get centroid 
    R3Point centroid = R3Centroid(points);

    // Search for best axes
    R3Box best_range = R3null_box;
    R3Triad best_axes = R3xyz_triad;
    int nxsteps = 2;
    int nysteps = 2;
    int nzsteps = 4;
    for (int ix = 0; ix < nxsteps; ix++) {
      for (int iy = 0; iy < nysteps; iy++) {
        for (int iz = 0; iz < nzsteps; iz++) {
          R3Triad axes = R3xyz_triad;
          axes.Rotate(RN_Z, ix*0.5*RN_PI/nxsteps);
          axes.Rotate(RN_Z, iy*0.5*RN_PI/nysteps);
          axes.Rotate(RN_Z, iz*0.5*RN_PI/nzsteps);
    
          // Compute ranges
          R3Box range = R3null_box;
          for (int i = 0; i < points.NEntries(); i++) {
            R3Point *point = points.Kth(i);
            R3Vector v = *point - centroid;
            RNLength r0 = v.Dot(axes[0]);
            RNLength r1 = v.Dot(axes[1]);
            RNLength r2 = v.Dot(axes[2]);
            range.Union(R3Point(r0, r1, r2));
          }

          // Check if range is best
          if (best_range.IsEmpty() || (range.Volume() < best_range.Volume())) {
            best_range = range;
            best_axes = axes;
          }
        }
      }
    }
      
    // Compute center
    if (best_range.IsEmpty()) best_range = R3zero_box;
    R3Point c = best_range.Centroid();
    R3Point center = centroid + best_axes[0]*c[0] + best_axes[1]*c[1] + best_axes[2]*c[2];
           
    // Initialize everything
    Reset(center, best_axes[0], best_axes[1], best_range.XRadius(), best_range.YRadius(), best_range.ZRadius());
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2833c
leaq 0x8d97f(%rip), %rax     # 0xe4078
movq %rax, (%rbx)
movq %rbx, 0x50(%rsp)
leaq 0x8(%rbx), %rdi
callq 0x2a930
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4ccf0
leaq 0x8f775(%rip), %rsi     # 0xe5e98
leaq 0x18(%rsp), %rdi
callq 0x274f0
leaq 0x8fa84(%rip), %rsi     # 0xe61b8
leaq 0x110(%rsp), %rdi
callq 0x2ad8e
leaq 0x53860(%rip), %rax     # 0xa9fa8
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r15d, %r15d
leaq 0xb0(%rsp), %rbp
leaq 0x158(%rsp), %r13
leaq 0x98(%rsp), %rbx
leaq 0x80(%rsp), %r12
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd 0x4b8ab(%rip), %xmm0    # 0xa2030
mulsd %xmm0, %xmm1
mulsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x68(%rsp)
xorl %eax, %eax
movq %r15, 0x60(%rsp)
movq %rax, 0x58(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x4b87c(%rip), %xmm0    # 0xa2030
mulsd %xmm0, %xmm1
mulsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movl $0x0, 0x4(%rsp)
movq %rbp, %rdi
leaq 0x8f9de(%rip), %rsi     # 0xe61b8
callq 0x2ad8e
movq %rbp, %rdi
movl $0x2, %esi
movsd 0x68(%rsp), %xmm0
callq 0x2b01c
movq %rbp, %rdi
movl $0x2, %esi
movsd 0x70(%rsp), %xmm0
callq 0x2b01c
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rsp), %xmm0
mulsd 0x4b81a(%rip), %xmm0    # 0xa2030
mulsd 0x8(%rsp), %xmm0
mulsd 0x4c58c(%rip), %xmm0    # 0xa2db0
movq %rbp, %rdi
movl $0x2, %esi
callq 0x2b01c
movq %r13, %rdi
leaq 0x8f65d(%rip), %rsi     # 0xe5e98
callq 0x274f0
cmpl $0x0, 0xc(%r14)
jle 0x568cb
xorl %r15d, %r15d
movq (%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
leaq 0xf8(%rsp), %rdx
callq 0x3cc88
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3d756
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
leaq 0xc8(%rsp), %rsi
callq 0x3d756
movsd %xmm0, 0x78(%rsp)
movq %rbx, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3d756
movapd %xmm0, %xmm2
movq %r12, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
callq 0x3ca26
movq %r13, %rdi
movq %r12, %rsi
callq 0x27f0e
incq %r15
movslq 0xc(%r14), %rax
cmpq %rax, %r15
jl 0x5684e
movsd 0x20(%rsp), %xmm0
ucomisd 0x38(%rsp), %xmm0
ja 0x56915
movsd 0x28(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
ja 0x56915
movsd 0x30(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
ja 0x56915
movq %r13, %rdi
callq 0x27d0c
movsd %xmm0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x27d0c
ucomisd 0x10(%rsp), %xmm0
jbe 0x56973
leaq 0x20(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x3cd94
leaq 0x38(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x3cd94
leaq 0x110(%rsp), %rdi
movq %rbp, %rsi
callq 0x3dc6a
leaq 0x128(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x3dc6a
leaq 0x140(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3dc6a
movq %r13, %rdi
callq 0x28348
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x4(%rsp)
cmpl $0x4, %eax
movq 0x60(%rsp), %r15
jne 0x567d0
movq 0x58(%rsp), %rcx
leal 0x1(%rcx), %eax
testl %ecx, %ecx
je 0x567a0
leal 0x1(%r15), %eax
testl %r15d, %r15d
movl %eax, %r15d
je 0x56775
movsd 0x20(%rsp), %xmm0
ucomisd 0x38(%rsp), %xmm0
ja 0x569dd
movsd 0x28(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
ja 0x569dd
movsd 0x30(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x56a03
leaq 0x20(%rsp), %rdi
leaq 0x8f407(%rip), %rbx     # 0xe5df0
leaq 0x8(%rbx), %rsi
callq 0x3cd94
leaq 0x38(%rsp), %rdi
addq $0x20, %rbx
movq %rbx, %rsi
callq 0x3cd94
leaq 0xb0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x27d32
movsd 0xb0(%rsp), %xmm0
leaq 0x1c0(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x3de8e
leaq 0x80(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x1c0(%rsp), %rdx
callq 0x3cd71
leaq 0x128(%rsp), %rbx
movsd 0xb8(%rsp), %xmm0
leaq 0x1a8(%rsp), %rdi
movq %rbx, %rsi
callq 0x3de8e
leaq 0x98(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x1a8(%rsp), %rdx
callq 0x3cd71
leaq 0x140(%rsp), %rsi
movsd 0xc0(%rsp), %xmm0
leaq 0x190(%rsp), %rdi
callq 0x3de8e
leaq 0x158(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x190(%rsp), %rdx
callq 0x3cd71
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
subsd 0x20(%rsp), %xmm0
movsd 0x4b54d(%rip), %xmm3    # 0xa2030
mulsd %xmm3, %xmm0
subsd 0x28(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd 0x48(%rsp), %xmm2
subsd 0x30(%rsp), %xmm2
mulsd %xmm3, %xmm2
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
leaq 0x158(%rsp), %rsi
leaq 0x110(%rsp), %rdx
movq %rbx, %rcx
callq *0x268(%rax)
leaq 0x18(%rsp), %rdi
callq 0x28348
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x56b57
jmp 0x56b57
jmp 0x56b57
jmp 0x56b57
jmp 0x56b57
jmp 0x56b57
jmp 0x56b57
jmp 0x56b50
jmp 0x56b50
movq %rax, %rbx
jmp 0x56b80
jmp 0x56b57
movq %rax, %rbx
jmp 0x56b76
jmp 0x56b66
jmp 0x56b66
jmp 0x56b66
jmp 0x56b66
jmp 0x56b66
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x28348
leaq 0x18(%rsp), %rdi
callq 0x28348
movq 0x50(%rsp), %rdi
callq 0x28348
movq %rbx, %rdi
callq 0xe7e0