// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelConstraint.cpp
// Function: gaps::R3SurfelPlanarGridConstraint::Check(gaps::R3Point const&) const
int R3SurfelPlanarGridConstraint::
Check(const R3Point& point) const
{
  // Check distance from point to plane
  RNLength offplane_distance = R3Distance(grid->Plane(), point);
  if (offplane_distance > max_offplane_distance) return R3_SURFEL_CONSTRAINT_FAIL;

  // Get grid value
  RNScalar grid_value = grid_operand;
  if (grid_value_type != R3_SURFEL_CONSTRAINT_OPERAND) grid_value = grid->WorldValue(point);
  if (grid_value == R2_GRID_UNKNOWN_VALUE) return R3_SURFEL_CONSTRAINT_FAIL;

  // Get surfel value
  RNScalar surfel_value = surfel_operand;
  if (surfel_value_type == R3_SURFEL_CONSTRAINT_X) surfel_value = point.X();
  else if (surfel_value_type == R3_SURFEL_CONSTRAINT_Y) surfel_value = point.Y();
  else if (surfel_value_type == R3_SURFEL_CONSTRAINT_Z) surfel_value = point.Z();

  // Compare values
  switch (comparison_type) {
  case R3_SURFEL_CONSTRAINT_NOT_EQUAL: 
    return (RNIsNotEqual(surfel_value, grid_value, epsilon)) ?
      R3_SURFEL_CONSTRAINT_PASS : R3_SURFEL_CONSTRAINT_FAIL;
  case R3_SURFEL_CONSTRAINT_EQUAL: 
    return (RNIsEqual(surfel_value, grid_value, epsilon)) ?
      R3_SURFEL_CONSTRAINT_PASS : R3_SURFEL_CONSTRAINT_FAIL;
  case R3_SURFEL_CONSTRAINT_GREATER: 
    return (RNIsGreater(surfel_value, grid_value, epsilon)) ?
      R3_SURFEL_CONSTRAINT_PASS : R3_SURFEL_CONSTRAINT_FAIL;
  case R3_SURFEL_CONSTRAINT_GREATER_OR_EQUAL: 
    return (RNIsGreaterOrEqual(surfel_value, grid_value, epsilon)) ?
      R3_SURFEL_CONSTRAINT_PASS : R3_SURFEL_CONSTRAINT_FAIL;
  case R3_SURFEL_CONSTRAINT_LESS: 
    return (RNIsLess(surfel_value, grid_value, epsilon)) ?
      R3_SURFEL_CONSTRAINT_PASS : R3_SURFEL_CONSTRAINT_FAIL;
  case R3_SURFEL_CONSTRAINT_LESS_OR_EQUAL: 
    return (RNIsLessOrEqual(surfel_value, grid_value, epsilon)) ?
      R3_SURFEL_CONSTRAINT_PASS : R3_SURFEL_CONSTRAINT_FAIL;
  }

  // Did not pass test
  return R3_SURFEL_CONSTRAINT_FAIL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq 0x8(%rdi), %rsi
movq %r15, %rdi
callq 0x500ce
xorl %ebx, %ebx
ucomisd 0x10(%r14), %xmm0
ja 0x30bea
cmpl $0x0, 0x20(%r14)
je 0x30ada
movq 0x8(%r14), %r12
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x83dd2
leaq 0x20(%r12), %rsi
movq %r13, %rdi
callq 0x846d8
addq $0x130, %r12            # imm = 0x130
movsd (%r13), %xmm0
movsd 0x8(%r13), %xmm1
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x97ff6
movsd (%r13), %xmm0
movsd 0x8(%r13), %xmm1
movq %r12, %rdi
callq 0x9205c
jmp 0x30ae0
movsd 0x30(%r14), %xmm0
ucomisd 0xad7b8(%rip), %xmm0    # 0xde2a0
jne 0x30af0
jnp 0x30bea
movl 0x1c(%r14), %eax
cmpl $0x4, %eax
je 0x30b0f
cmpl $0x3, %eax
je 0x30b09
cmpl $0x2, %eax
je 0x30b13
leaq 0x28(%r14), %r15
jmp 0x30b13
addq $0x8, %r15
jmp 0x30b13
addq $0x10, %r15
movl 0x18(%r14), %eax
cmpq $0x5, %rax
ja 0x30bea
movsd (%r15), %xmm1
leaq 0xad793(%rip), %rcx     # 0xde2c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsd 0x38(%r14), %xmm2
subsd %xmm0, %xmm1
movapd 0xac858(%rip), %xmm0    # 0xdd3a0
xorpd %xmm2, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
addl %eax, %eax
ucomisd %xmm2, %xmm1
movl $0x2, %ebx
cmovbel %eax, %ebx
jmp 0x30bea
movsd 0x38(%r14), %xmm2
xorpd 0xac82a(%rip), %xmm2    # 0xdd3a0
subsd %xmm0, %xmm1
xorl %ebx, %ebx
ucomisd %xmm1, %xmm2
jmp 0x30b8e
subsd %xmm0, %xmm1
xorl %ebx, %ebx
ucomisd 0x38(%r14), %xmm1
seta %bl
jmp 0x30be8
subsd %xmm0, %xmm1
movsd 0x38(%r14), %xmm0
xorpd 0xac7fb(%rip), %xmm0    # 0xdd3a0
xorl %ebx, %ebx
ucomisd %xmm0, %xmm1
jmp 0x30be5
movsd 0x38(%r14), %xmm2
subsd %xmm0, %xmm1
xorl %eax, %eax
ucomisd %xmm1, %xmm2
setae %al
xorpd 0xac7d8(%rip), %xmm2    # 0xdd3a0
addl %eax, %eax
xorl %ebx, %ebx
ucomisd %xmm2, %xmm1
cmovael %eax, %ebx
jmp 0x30bea
movsd 0x38(%r14), %xmm2
subsd %xmm0, %xmm1
xorl %ebx, %ebx
ucomisd %xmm1, %xmm2
setae %bl
addl %ebx, %ebx
movl %ebx, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq