// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Cont.cpp
// Function: gaps::R3Contains(gaps::R3Triangle const&, gaps::R3Point const&)
RNBoolean R3Contains(const R3Triangle& triangle, const R3Point& point)
{
    // Check whether triangle bounding shape contains point
    if (!R3Contains(triangle.Box(), point)) return FALSE;
  
    // Check whether triangle plane contains point
    if (!R3Contains(triangle.Plane(), point)) return FALSE;
  
    // Compute whether point is on correct side of each edge
    const R3Point& p0 = triangle.Vertex(0)->Position();
    const R3Point& p1 = triangle.Vertex(1)->Position();
    const R3Point& p2 = triangle.Vertex(2)->Position();
    R3Plane h01(p1, triangle.Normal(), p1 - p0);
    if (RNIsNegative(R3SignedDistance(h01, point))) return FALSE;
    R3Plane plane01(p1, triangle.Normal(), p1 - p0);
    if (RNIsNegative(R3SignedDistance(plane01, point))) return FALSE;
    R3Plane plane12(p2, triangle.Normal(), p2 - p1);
    if (RNIsNegative(R3SignedDistance(plane12, point))) return FALSE;
    R3Plane plane20(p0, triangle.Normal(), p0 - p2);
    if (RNIsNegative(R3SignedDistance(plane20, point))) return FALSE;
  
    // Triangle contains point
    return TRUE;
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x148(%rsp)
movq %rsi, 0x140(%rsp)
movq 0x148(%rsp), %rdi
callq 0x86b50
movq %rax, %rdi
movq 0x140(%rsp), %rsi
callq 0x83a20
cmpl $0x0, %eax
jne 0x83729
movl $0x0, 0x154(%rsp)
jmp 0x83a0e
movq 0x148(%rsp), %rdi
callq 0x81b30
movq %rax, %rdi
movq 0x140(%rsp), %rsi
callq 0x83240
cmpl $0x0, %eax
jne 0x8375b
movl $0x0, 0x154(%rsp)
jmp 0x83a0e
movq 0x148(%rsp), %rdi
xorl %esi, %esi
callq 0x81eb0
movq %rax, %rdi
callq 0x78950
movq %rax, 0x138(%rsp)
movq 0x148(%rsp), %rdi
movl $0x1, %esi
callq 0x81eb0
movq %rax, %rdi
callq 0x78950
movq %rax, 0x130(%rsp)
movq 0x148(%rsp), %rdi
movl $0x2, %esi
callq 0x81eb0
movq %rax, %rdi
callq 0x78950
movq %rax, 0x128(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x148(%rsp), %rdi
callq 0x78960
movq %rax, 0x40(%rsp)
movq 0x130(%rsp), %rsi
movq 0x138(%rsp), %rdx
leaq 0xf0(%rsp), %rdi
callq 0x6eeb0
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
leaq 0x108(%rsp), %rdi
leaq 0xf0(%rsp), %rcx
callq 0x6c4c0
movq 0x140(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x86f90
leaq 0xf4cab(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x38fd0
cmpl $0x0, %eax
je 0x83853
movl $0x0, 0x154(%rsp)
jmp 0x83a0e
movq 0x130(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x148(%rsp), %rdi
callq 0x78960
movq %rax, 0x30(%rsp)
movq 0x130(%rsp), %rsi
movq 0x138(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x6eeb0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0xd0(%rsp), %rdi
leaq 0xb8(%rsp), %rcx
callq 0x6c4c0
movq 0x140(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0x86f90
leaq 0xf4c16(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x38fd0
cmpl $0x0, %eax
je 0x838e8
movl $0x0, 0x154(%rsp)
jmp 0x83a0e
movq 0x128(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x148(%rsp), %rdi
callq 0x78960
movq %rax, 0x20(%rsp)
movq 0x128(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x80(%rsp), %rdi
callq 0x6eeb0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x98(%rsp), %rdi
leaq 0x80(%rsp), %rcx
callq 0x6c4c0
movq 0x140(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x86f90
leaq 0xf4b81(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x38fd0
cmpl $0x0, %eax
je 0x8397d
movl $0x0, 0x154(%rsp)
jmp 0x83a0e
movq 0x138(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x148(%rsp), %rdi
callq 0x78960
movq %rax, 0x10(%rsp)
movq 0x138(%rsp), %rsi
movq 0x128(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x6eeb0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rcx
callq 0x6c4c0
movq 0x140(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x86f90
leaq 0xf4af8(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x38fd0
cmpl $0x0, %eax
je 0x83a03
movl $0x0, 0x154(%rsp)
jmp 0x83a0e
movl $0x1, 0x154(%rsp)
movl 0x154(%rsp), %eax
addq $0x158, %rsp            # imm = 0x158
retq
nopl (%rax)