// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelConstraint.cpp
// Function: gaps::R3SurfelCylinderConstraint::Check(gaps::R3Box const&) const
int R3SurfelCylinderConstraint::
Check(const R3Box& box) const
{
  // Should check whether cylinder contains box
  // ???

  // Return whether cylinder intersects box
  RNScalar dx = 0, dy = 0;
  if (center.X() < box.XMin()) dx = box.XMin() - center.X();
  else if (center.X() > box.XMax()) dx = center.X() - box.XMax();
  if (center.Y() < box.YMin()) dy = box.YMin() - center.Y();
  else if (center.Y() > box.YMax()) dy = center.Y() - box.YMax();
  RNScalar d_squared = dx*dx + dy*dy;
  if (d_squared > radius_squared) return R3_SURFEL_CONSTRAINT_FAIL;
  if (box.ZMax() < zmin) return R3_SURFEL_CONSTRAINT_FAIL;
  if (box.ZMin() > zmax) return R3_SURFEL_CONSTRAINT_FAIL;
  return R3_SURFEL_CONSTRAINT_MAYBE;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq 0x68(%rsp), %rdi
movq %rdi, 0x38(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
addq $0x8, %rdi
callq 0x187b0
movsd %xmm0, 0x40(%rsp)
movq 0x60(%rsp), %rdi
callq 0x446e0
movsd 0x40(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x51062
movq 0x60(%rsp), %rdi
callq 0x446e0
movq 0x38(%rsp), %rdi
movsd %xmm0, 0x30(%rsp)
addq $0x8, %rdi
callq 0x187b0
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
jmp 0x510c2
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
callq 0x187b0
movsd %xmm0, 0x28(%rsp)
movq 0x60(%rsp), %rdi
callq 0x44e00
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x510c0
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
callq 0x187b0
movsd %xmm0, 0x20(%rsp)
movq 0x60(%rsp), %rdi
callq 0x44e00
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
jmp 0x510c2
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
callq 0x187c0
movsd %xmm0, 0x18(%rsp)
movq 0x60(%rsp), %rdi
callq 0x44700
movsd 0x18(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5111f
movq 0x60(%rsp), %rdi
callq 0x44700
movq 0x38(%rsp), %rdi
movsd %xmm0, 0x10(%rsp)
addq $0x8, %rdi
callq 0x187c0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
jmp 0x5117d
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
callq 0x187c0
movsd %xmm0, 0x8(%rsp)
movq 0x60(%rsp), %rdi
callq 0x44e20
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5117b
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
callq 0x187c0
movsd %xmm0, (%rsp)
movq 0x60(%rsp), %rdi
callq 0x44e20
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
jmp 0x5117d
movq 0x38(%rsp), %rax
movsd 0x58(%rsp), %xmm0
movsd 0x58(%rsp), %xmm2
movsd 0x50(%rsp), %xmm1
mulsd 0x50(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
ucomisd 0x20(%rax), %xmm0
jbe 0x511bf
movl $0x0, 0x74(%rsp)
jmp 0x5120e
movq 0x60(%rsp), %rdi
callq 0x44e40
movq 0x38(%rsp), %rax
movaps %xmm0, %xmm1
movsd 0x28(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x511e6
movl $0x0, 0x74(%rsp)
jmp 0x5120e
movq 0x60(%rsp), %rdi
callq 0x435e0
movq 0x38(%rsp), %rax
ucomisd 0x30(%rax), %xmm0
jbe 0x51206
movl $0x0, 0x74(%rsp)
jmp 0x5120e
movl $0x1, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw (%rax,%rax)