// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Span.cpp
// Function: gaps::R2Span::Clip(gaps::R2Line const&)
RNClassID R2Span::
Clip(const R2Line& line)
{
    // Characterize endpoints with respect to line
    RNScalar d1 = R2SignedDistance(line, Start());
    RNScalar d2 = R2SignedDistance(line, End());

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x28(%rdi), %r14
movq %rsi, %rdi
movq %r14, %rsi
callq 0x63638
movapd %xmm0, (%rsp)
leaq 0x38(%rbx), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x63638
movapd (%rsp), %xmm2
movapd %xmm0, %xmm3
leaq 0x7c073(%rip), %rax     # 0xdaba8
movsd (%rax), %xmm1
movapd 0x344ef(%rip), %xmm0    # 0x93030
xorpd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
ja 0x5eb66
ucomisd %xmm1, %xmm2
ja 0x5eb8f
ucomisd %xmm3, %xmm0
jbe 0x5ec96
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
jmp 0x5eb83
ucomisd %xmm3, %xmm0
ja 0x5ec13
ucomisd %xmm1, %xmm3
ja 0x5ec25
movq %rbx, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x5ea9a
pushq $0x1
jmp 0x5ec98
pushq $0x4
popq %rbp
ucomisd %xmm3, %xmm0
jbe 0x5ec99
movapd 0x3448c(%rip), %xmm0    # 0x93030
xorpd %xmm3, %xmm0
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movapd %xmm3, 0x10(%rsp)
callq 0x5f833
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movaps (%rsp), %xmm0
callq 0x5f833
leaq 0x48(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x5f7a1
movapd (%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5f847
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x5ea9a
jmp 0x5ec99
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0x5ea9a
xorl %ebp, %ebp
jmp 0x5ec99
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movapd %xmm3, %xmm0
movapd %xmm3, 0x10(%rsp)
callq 0x5f833
movaps 0x343ea(%rip), %xmm0    # 0x93030
xorps (%rsp), %xmm0
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x5f833
leaq 0x48(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5f7a1
movapd 0x10(%rsp), %xmm0
subsd (%rsp), %xmm0
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x5f847
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x5ea9a
pushq $0x4
popq %rbp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq