// File: /workspace/github_cpp_makefile_star2_O1/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 0x28104
movq %rsi, %r12
movq %rbx, 0x50(%rsp)
leaq 0x10db26(%rip), %rsi    # 0x1359c8
leaq 0x18(%rsp), %rdi
callq 0x6df88
cmpl $0x0, 0x10(%r12)
jle 0x27f97
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 0x84d7e
movq %r14, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x84fe0
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x85aae
movsd %xmm0, 0x68(%rsp)
movq %r14, %rdi
movq 0x58(%rsp), %rsi
callq 0x85aae
movsd %xmm0, 0x60(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x85aae
movapd %xmm0, %xmm2
movq %rbx, %rdi
movsd 0x68(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
callq 0x84d7e
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x6e9a6
incq %r13
movslq 0x10(%r12), %rax
addq $0x10, %r15
cmpq %rax, %r13
jl 0x27ee0
movsd 0x20(%rsp), %xmm0
ucomisd 0x38(%rsp), %xmm0
ja 0x27fc1
movsd 0x28(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
ja 0x27fc1
movsd 0x30(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x27fe7
leaq 0x20(%rsp), %rdi
leaq 0x10d953(%rip), %rbx    # 0x135920
leaq 0x8(%rbx), %rsi
callq 0x850ec
leaq 0x38(%rsp), %rdi
addq $0x20, %rbx
movq %rbx, %rsi
callq 0x850ec
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x6e7ca
movsd 0x70(%rsp), %xmm0
leaq 0xd0(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x861e6
movq 0x50(%rsp), %r14
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
movq 0x10(%rsp), %rsi
callq 0x850c9
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %rbx
movsd 0x78(%rsp), %xmm0
leaq 0xb8(%rsp), %rdi
movq %rbx, %rsi
callq 0x861e6
leaq 0x100(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x850c9
movq 0x8(%rsp), %rax
leaq 0x30(%rax), %rsi
movsd 0x80(%rsp), %xmm0
leaq 0xa0(%rsp), %rdi
callq 0x861e6
leaq 0x88(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x850c9
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
subsd 0x20(%rsp), %xmm0
movsd 0xb6081(%rip), %xmm3    # 0xde140
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 0x6cc2c
leaq 0x18(%rsp), %rdi
callq 0x6ede0
movq %r14, %rax
jmp 0x28116
leaq 0x10d685(%rip), %rsi    # 0x135790
movq %rbx, %rdi
callq 0x6cb2e
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
jmp 0x2813c
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x6ede0
movq %rbx, %rdi
callq 0x138b0