// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Isect.cpp
// Function: gaps::R3Intersects(gaps::R3Plane const&, gaps::R3Plane const&, gaps::R3Plane const&, gaps::R3Point*)
RNClassID R3Intersects(const R3Plane& plane1, const R3Plane& plane2, const R3Plane& plane3, 
    R3Point *hit_point)
{
    // From Graphics Gems I, page 305
    RNScalar denom = R4MatrixDet3(plane1.Normal().X(), plane2.Normal().X(), plane3.Normal().X(), 
				  plane1.Normal().Y(), plane2.Normal().Y(), plane3.Normal().Y(), 
				  plane1.Normal().Z(), plane2.Normal().Z(), plane3.Normal().Z());

    // Check for any two parallel planes 
    if (RNIsZero(denom)) {
	// Check for case of all planes coincident
	if (R3Contains(plane1, plane2) && R3Contains(plane1, plane3)) return R3_PLANE_CLASS_ID;
	else return RN_NULL_CLASS_ID;
    }

    // Compute unique intersection point
    if (hit_point) {
	*hit_point = R3zero_point;
	*hit_point += (plane2.Normal() % plane3.Normal()) * -(plane1.D());
	*hit_point += (plane3.Normal() % plane1.Normal()) * -(plane2.D());
	*hit_point += (plane1.Normal() % plane2.Normal()) * -(plane3.D());
	*hit_point /= denom;
    }

    // Return intersection type
    return R3_POINT_CLASS_ID;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x118(%rsp)
movq %rsi, 0x110(%rsp)
movq %rdx, 0x108(%rsp)
movq %rcx, 0x100(%rsp)
movq 0x118(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c20
movsd %xmm0, 0x60(%rsp)
movq 0x110(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c20
movsd %xmm0, 0x28(%rsp)
movq 0x108(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c20
movsd %xmm0, 0x30(%rsp)
movq 0x118(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c30
movsd %xmm0, 0x38(%rsp)
movq 0x110(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c30
movsd %xmm0, 0x40(%rsp)
movq 0x108(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c30
movsd %xmm0, 0x48(%rsp)
movq 0x118(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c40
movsd %xmm0, 0x50(%rsp)
movq 0x110(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c40
movsd %xmm0, 0x58(%rsp)
movq 0x108(%rsp), %rdi
callq 0x13e60
movq %rax, %rdi
callq 0x38c40
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movsd 0x40(%rsp), %xmm4
movsd 0x48(%rsp), %xmm5
movsd 0x50(%rsp), %xmm6
movsd 0x58(%rsp), %xmm7
movaps %xmm0, %xmm8
movsd 0x60(%rsp), %xmm0
movsd %xmm8, (%rsp)
callq 0x53160
movsd %xmm0, 0xf8(%rsp)
movsd 0xf8(%rsp), %xmm0
leaq 0xf8ec4(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x36b80
cmpl $0x0, %eax
je 0x7f67e
movq 0x118(%rsp), %rdi
movq 0x110(%rsp), %rsi
callq 0x83420
cmpl $0x0, %eax
je 0x7f66e
movq 0x118(%rsp), %rdi
movq 0x108(%rsp), %rsi
callq 0x83420
cmpl $0x0, %eax
je 0x7f66e
movl $0x5, 0x124(%rsp)
jmp 0x7f842
movl $0x0, 0x124(%rsp)
jmp 0x7f842
cmpq $0x0, 0x100(%rsp)
je 0x7f837
movq 0x100(%rsp), %rdi
leaq 0x4f9e14(%rip), %rsi    # 0x5794b0
callq 0x6f1e0
movq 0x110(%rsp), %rdi
callq 0x13e60
movq %rax, 0x10(%rsp)
movq 0x108(%rsp), %rdi
callq 0x13e60
movq 0x10(%rsp), %rsi
movq %rax, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x70af0
movq 0x118(%rsp), %rdi
callq 0x4e330
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
leaq 0xe0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x70b80
movq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x6f290
movq 0x108(%rsp), %rdi
callq 0x13e60
movq %rax, 0x18(%rsp)
movq 0x118(%rsp), %rdi
callq 0x13e60
movq 0x18(%rsp), %rsi
movq %rax, %rdx
leaq 0x98(%rsp), %rdi
callq 0x70af0
movq 0x110(%rsp), %rdi
callq 0x4e330
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x70b80
movq 0x100(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x6f290
movq 0x118(%rsp), %rdi
callq 0x13e60
movq %rax, 0x20(%rsp)
movq 0x110(%rsp), %rdi
callq 0x13e60
movq 0x20(%rsp), %rsi
movq %rax, %rdx
leaq 0x68(%rsp), %rdi
callq 0x70af0
movq 0x108(%rsp), %rdi
callq 0x4e330
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
leaq 0x80(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x70b80
movq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x6f290
movsd 0xf8(%rsp), %xmm0
movq 0x100(%rsp), %rdi
callq 0x6f960
movl $0x1, 0x124(%rsp)
movl 0x124(%rsp), %eax
addq $0x128, %rsp            # imm = 0x128
retq
nopw %cs:(%rax,%rax)