// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Span.cpp
// Function: gaps::R3Span::Clip(gaps::R3Plane const&)
RNClassID R3Span::
Clip(const R3Plane& plane)
{
    // Characterize endpoints with respect to plane
    RNScalar d1 = R3SignedDistance(plane, Start());
    RNScalar d2 = R3SignedDistance(plane, End());

    // Clip span to plane
    if (RNIsNegative(d1)) {
	if (RNIsNegative(d2)) {
	    // Both points are below plane ???
	    Reset(Start(), Start());
	    return RN_NULL_CLASS_ID;
	}
	else if (RNIsPositive(d2)) {
	    // Start is below, end is above -- move start to plane
	    Reset((Start() * d2 + End() * -d1) / (d2 - d1), End());
	    return R3_SPAN_CLASS_ID;
	}
	else {
	    // Start is below, end is on -- move start to end
	    Reset(End(), End());
	    return R3_POINT_CLASS_ID;
	}
    }
    else if (RNIsPositive(d1)) {
	if (RNIsNegative(d2)) {
	    // Start is above, end is below -- move end to plane
	    Reset(Start(), (Start() * -d2 + End() * d1) / (d1 - d2));
	    return R3_SPAN_CLASS_ID;
	}
	else {
	    // Start is above, end is on or above
	    return R3_SPAN_CLASS_ID;
	}
    }
    else {
	if (RNIsNegative(d2)) {
	    // Start is on, end is below -- move end to start
	    Reset(Start(), Start());
	    return R3_POINT_CLASS_ID;
	}
	else if (RNIsPositive(d2)){
	    // Start is on, End is above
	    return R3_SPAN_CLASS_ID;
	}
	else {
	    // Start is on, end is on
	    return R3_POINT_CLASS_ID;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, %rdi
movq %rbx, %rsi
callq 0x4a10f
movapd %xmm0, (%rsp)
leaq 0x30(%rbx), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x4a10f
movapd (%rsp), %xmm2
movapd %xmm0, %xmm3
leaq 0xa976a(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x65be6(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
ja 0x3c467
ucomisd %xmm0, %xmm2
ja 0x3c489
ucomisd %xmm3, %xmm1
ja 0x3c524
xorl %eax, %eax
ucomisd %xmm0, %xmm3
seta %al
leal (%rax,%rax,2), %ebp
incl %ebp
jmp 0x3c5af
ucomisd %xmm3, %xmm1
ja 0x3c50f
ucomisd %xmm0, %xmm3
ja 0x3c539
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
jmp 0x3c52d
movl $0x4, %ebp
ucomisd %xmm3, %xmm1
jbe 0x3c5af
movapd 0x65b80(%rip), %xmm0    # 0xa2020
xorpd %xmm3, %xmm0
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movapd %xmm3, 0x10(%rsp)
callq 0x3d470
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movaps (%rsp), %xmm0
callq 0x3d470
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3d42a
movapd (%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x3d492
movq %rbx, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3c386
jmp 0x3c5af
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x3c386
xorl %ebp, %ebp
jmp 0x3c5af
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x3c386
movl $0x1, %ebp
jmp 0x3c5af
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movapd %xmm3, %xmm0
movapd %xmm3, 0x10(%rsp)
callq 0x3d470
movaps 0x65ac6(%rip), %xmm0    # 0xa2020
xorps (%rsp), %xmm0
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x3d470
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3d42a
movapd 0x10(%rsp), %xmm0
subsd (%rsp), %xmm0
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x3d492
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3c386
movl $0x4, %ebp
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop