// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2Distance(gaps::R2Point const&, gaps::R2Arc const&)
RNLength R2Distance(const R2Point& point, const R2Arc& arc)
{
    // Figure sector - positive ds are inside arc sector
    RNLength d1 = R2SignedDistance(R2Line(arc.StartPoint(), arc.Center()), point);
    RNLength d2 = R2SignedDistance(R2Line(arc.Center(), arc.StopPoint()), point);
    if (d1 > 0.0) {
        if (d2 > 0.0) {
  	    // Point is in arc sector
	    RNLength d = R2Distance(arc.Center(), point) - arc.Radius();
	    return (d < 0) ? -d : d;
	}
        else {
	    // Point may be in arc sector 
	    if (arc.SweepAngle() > RN_PI) {
	        // Point is in arc sector
	        RNLength d = R2Distance(arc.Center(), point) - arc.Radius();
		return (d < 0) ? -d : d;
	    }
	    else {
	        // Point is closest to stop point
	        return R2Distance(arc.StopPoint(), point);
	    }
        }
    }
    else {
        if (d2 > 0.0) {
	    // Point may be in arc sector 
	    if (arc.SweepAngle() > RN_PI) {
	        // Point is in arc sector
	        RNLength d = R2Distance(arc.Center(), point) - arc.Radius();
		return (d < 0) ? -d : d;
	    }
	    else {
	        // Point is closest to start point
	        return R2Distance(arc.StartPoint(), point);
	    }
        }
        else {
  	    // Point is outside arc sector
	    RNLength d = R2Distance(arc.Center(), point) - arc.Radius();
	    return (d < 0) ? -d : d;
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x28(%rsi), %xmm0
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x6f936
leaq 0x10(%rbx), %r15
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x689ba
movsd (%r14), %xmm0
movaps %xmm0, 0x80(%rsp)
movsd 0x8(%r14), %xmm0
movaps %xmm0, 0x70(%rsp)
movsd 0x10(%r13), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x18(%r13), %xmm0
movaps %xmm0, 0x50(%rsp)
movsd 0x20(%r13), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0x30(%rbx), %xmm0
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x6f936
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x689ba
movupd (%r14), %xmm0
movupd 0x10(%r13), %xmm1
unpcklpd 0x40(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movupd 0x18(%r13), %xmm2
unpcklpd 0x50(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
movsd 0x20(%r13), %xmm3
unpcklpd 0x60(%rsp), %xmm3       # xmm3 = xmm3[0],mem[0]
movapd %xmm0, %xmm4
shufpd $0x1, 0x70(%rsp), %xmm4 # xmm4 = xmm4[1],mem[0]
mulpd %xmm2, %xmm4
unpcklpd 0x80(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
mulpd %xmm1, %xmm0
addpd %xmm4, %xmm0
addpd %xmm3, %xmm0
xorpd %xmm1, %xmm1
cmpltpd %xmm0, %xmm1
pextrw $0x4, %xmm1, %eax
xorpd %xmm1, %xmm1
testb $0x1, %al
je 0x6d819
ucomisd %xmm1, %xmm0
ja 0x6d83a
movsd 0x30(%rbx), %xmm0
movapd %xmm0, %xmm1
subsd 0x28(%rbx), %xmm1
jmp 0x6d82d
ucomisd %xmm1, %xmm0
jbe 0x6d83a
movsd 0x28(%rbx), %xmm0
movsd 0x30(%rbx), %xmm1
subsd %xmm0, %xmm1
leaq 0x3c774(%rip), %rax     # 0xa9fa8
ucomisd (%rax), %xmm1
jbe 0x6d870
leaq 0x18(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6906b
movq %r12, %rdi
callq 0x691fe
movapd %xmm0, %xmm1
subsd 0x20(%rbx), %xmm1
movapd 0x347ba(%rip), %xmm0    # 0xa2020
xorpd %xmm1, %xmm0
maxsd %xmm1, %xmm0
jmp 0x6d89b
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6f936
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6906b
movq %rbx, %rdi
callq 0x691fe
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq