// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, 0x18(%rsp)
movq %rdi, %rbx
cmpl $0x0, 0x10(%rsi)
je 0x25f56
movq %rcx, %r14
movq %rsi, %rbp
movq %rbx, 0x58(%rsp)
leaq 0xffc9a(%rip), %rsi     # 0x1259e8
leaq 0x20(%rsp), %rdi
callq 0x63ce6
leaq 0x18(%r14), %rax
movq %rax, 0x8(%rsp)
movq %r14, %r13
leaq 0x30(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x88(%rsp), %rbx
leaq 0x70(%rsp), %r15
xorl %r12d, %r12d
movslq 0x10(%rbp), %rax
cmpq %rax, %r12
jge 0x25e0e
movq 0x8(%rbp), %rsi
addq %r14, %rsi
movq %rbx, %rdi
callq 0x16310
movq %r15, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
callq 0x78399
movq %r15, %rdi
movq %r13, %rsi
callq 0x78bf6
movsd %xmm0, 0x68(%rsp)
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x78bf6
movsd %xmm0, 0x60(%rsp)
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x78bf6
movapd %xmm0, %xmm2
movq %rbx, %rdi
movsd 0x68(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
callq 0x781bc
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x6464c
incq %r12
addq $0x10, %r14
jmp 0x25d80
movsd 0x28(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
ja 0x25e38
movsd 0x30(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
ja 0x25e38
movsd 0x38(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
jbe 0x25e49
leaq 0xffb01(%rip), %rsi     # 0x125940
leaq 0x20(%rsp), %rdi
callq 0x177ee
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x644c2
movq 0x58(%rsp), %rbx
movsd 0x70(%rsp), %xmm0
leaq 0xd0(%rsp), %rdi
movq %r13, %rsi
callq 0x79072
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
movq 0x18(%rsp), %rsi
callq 0x78483
movsd 0x78(%rsp), %xmm0
leaq 0xb8(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x79072
leaq 0x100(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x78483
movsd 0x80(%rsp), %xmm0
leaq 0xa0(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x79072
leaq 0x88(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x78483
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
subsd 0x28(%rsp), %xmm0
movsd 0xa2224(%rip), %xmm3    # 0xc8138
mulsd %xmm3, %xmm0
subsd 0x30(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd 0x50(%rsp), %xmm2
subsd 0x38(%rsp), %xmm2
mulsd %xmm3, %xmm2
leaq 0x88(%rsp), %rsi
movq %rbx, %rdi
movq %r13, %rdx
movq 0x8(%rsp), %rcx
callq 0x62aea
leaq 0x20(%rsp), %rdi
callq 0x649ae
jmp 0x25f65
leaq 0xff853(%rip), %rsi     # 0x1257b0
movq %rbx, %rdi
callq 0x629ec
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
jmp 0x25f8e
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x649ae
movq %rbx, %rdi
callq 0x138f0