// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelUtils.cpp
// Function: gaps::EstimateOrientedBBox(gaps::R3SurfelPointSet*, gaps::R3Point const&, gaps::R3Triad const&)
R3OrientedBox 
EstimateOrientedBBox(R3SurfelPointSet *pointset,
  const R3Point& centroid, const R3Triad& axes)
{
  // Check pointset
  if (pointset->NPoints() == 0) return R3null_oriented_box;
    
  // Compute ranges
  R3Box range = R3null_box;
  for (int i = 0; i < pointset->NPoints(); i++) {
    R3SurfelPoint *point = pointset->Point(i);
    R3Vector v = point->Position() - 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));
  }

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

  // Return oriented box
  return R3OrientedBox(center, axes[0], axes[1],
    range.XRadius(), range.YRadius(), range.ZRadius());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rcx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdi, %rbx
cmpl $0x0, 0x10(%rsi)
je 0x27daa
movq %rsi, %r12
movq %rbx, 0x50(%rsp)
leaq 0x10ce80(%rip), %rsi    # 0x1349c8
leaq 0x18(%rsp), %rdi
callq 0x6d354
cmpl $0x0, 0x10(%r12)
jle 0x27c3d
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rcx
movq %rcx, 0x58(%rsp)
leaq 0x30(%rax), %rbp
movl $0x8, %r15d
xorl %r13d, %r13d
leaq 0x88(%rsp), %rbx
leaq 0x70(%rsp), %r14
movq 0x8(%r12), %rax
movq -0x8(%rax,%r15), %rcx
movq (%rax,%r15), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
addsd 0x10(%rcx), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax), %xmm1
addsd 0x18(%rcx), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax), %xmm2
addsd 0x20(%rcx), %xmm2
movq %rbx, %rdi
callq 0x83dc2
movq %r14, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x8401e
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x84ae2
movsd %xmm0, 0x68(%rsp)
movq %r14, %rdi
movq 0x58(%rsp), %rsi
callq 0x84ae2
movsd %xmm0, 0x60(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x84ae2
movapd %xmm0, %xmm2
movq %rbx, %rdi
movsd 0x68(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
callq 0x83dc2
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x6dd46
incq %r13
movslq 0x10(%r12), %rax
addq $0x10, %r15
cmpq %rax, %r13
jl 0x27b86
movsd 0x20(%rsp), %xmm0
ucomisd 0x38(%rsp), %xmm0
ja 0x27c67
movsd 0x28(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
ja 0x27c67
movsd 0x30(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x27c8d
leaq 0x20(%rsp), %rdi
leaq 0x10ccad(%rip), %rbx    # 0x134920
leaq 0x8(%rbx), %rsi
callq 0x8412a
leaq 0x38(%rsp), %rdi
addq $0x20, %rbx
movq %rbx, %rsi
callq 0x8412a
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x6db6a
movsd 0x70(%rsp), %xmm0
leaq 0xd0(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x851f2
movq 0x50(%rsp), %r14
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
movq 0x10(%rsp), %rsi
callq 0x84107
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rbx
movsd 0x78(%rsp), %xmm0
leaq 0xb8(%rsp), %rdi
movq %rbx, %rsi
callq 0x851f2
leaq 0x100(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x84107
movq 0x8(%rsp), %rax
leaq 0x30(%rax), %rsi
movsd 0x80(%rsp), %xmm0
leaq 0xa0(%rsp), %rdi
callq 0x851f2
leaq 0x88(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x84107
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
subsd 0x20(%rsp), %xmm0
movsd 0xb53d3(%rip), %xmm3    # 0xdd138
mulsd %xmm3, %xmm0
subsd 0x28(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd 0x48(%rsp), %xmm2
subsd 0x30(%rsp), %xmm2
mulsd %xmm3, %xmm2
leaq 0x88(%rsp), %rsi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
movq %rbx, %rcx
callq 0x6c008
leaq 0x18(%rsp), %rdi
callq 0x6e174
movq %r14, %rax
jmp 0x27dbc
leaq 0x10c9df(%rip), %rsi    # 0x134790
movq %rbx, %rdi
callq 0x6bf0a
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
jmp 0x27de2
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x6e174
movq %rbx, %rdi
callq 0x138b0