// File: /workspace/github_cpp_makefile_star2_O2/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
leaq 0x58(%rsp), %r12
movq %r12, %rdi
callq 0x6342a
leaq 0x10(%rbx), %r15
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x5f1a4
movsd (%r14), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x8(%r14), %xmm0
movaps %xmm0, 0x30(%rsp)
movsd 0x10(%r13), %xmm0
movaps %xmm0, (%rsp)
movsd 0x18(%r13), %xmm0
movaps %xmm0, 0x10(%rsp)
movsd 0x20(%r13), %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x6343e
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x5f1a4
movupd (%r14), %xmm0
movupd 0x10(%r13), %xmm1
unpcklpd (%rsp), %xmm1           # xmm1 = xmm1[0],mem[0]
movupd 0x18(%r13), %xmm2
unpcklpd 0x10(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
movsd 0x20(%r13), %xmm3
unpcklpd 0x20(%rsp), %xmm3       # xmm3 = xmm3[0],mem[0]
movapd %xmm0, %xmm4
shufpd $0x1, 0x30(%rsp), %xmm4 # xmm4 = xmm4[1],mem[0]
mulpd %xmm2, %xmm4
unpcklpd 0x40(%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 0x6391f
ucomisd %xmm1, %xmm0
ja 0x6393c
movsd 0x30(%rbx), %xmm0
subsd 0x28(%rbx), %xmm0
leaq 0x37641(%rip), %rax     # 0x9af48
ucomisd (%rax), %xmm0
ja 0x6393c
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6343e
jmp 0x63972
ucomisd %xmm1, %xmm0
jbe 0x6393c
movsd 0x30(%rbx), %xmm0
subsd 0x28(%rbx), %xmm0
leaq 0x37612(%rip), %rax     # 0x9af48
ucomisd (%rax), %xmm0
jbe 0x63962
movq %r15, %rdi
movq %r14, %rsi
callq 0x63469
movapd %xmm0, %xmm1
subsd 0x20(%rbx), %xmm1
movapd 0x2f6d8(%rip), %xmm0    # 0x93030
xorpd %xmm1, %xmm0
maxsd %xmm1, %xmm0
jmp 0x6397d
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6342a
movq %r15, %rdi
movq %r14, %rsi
callq 0x63469
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq