// File: /workspace/github_cpp_makefile_star2_O2/thierry7100[P]CutOptim/src/SvgDoc.cpp
// Function: ComputeFreeRotAngle(Polygon*, int, Polygon*, int, int, double&)
bool ComputeFreeRotAngle(Polygon *FloatPoly, int iVertexFloat, Polygon *FixedPoly, int iVertexFixed, int iRot, double &angle)
{
double sf1, sf2;
double sm1, sm2;

    //  First compute angles of edges ogf Fixed polygon
    if ( iVertexFixed == 0)
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sf1 = FixedPoly->getSlope(FixedPoly->nVertices-2) + M_PI;
        if ( sf1 > M_PI ) sf1 -= 2*M_PI;
        sf2 = FixedPoly->getSlope(0);
    }
    else
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sf1 = FixedPoly->getSlope(iVertexFixed-1) + M_PI;
        if ( sf1 > M_PI ) sf1 -= 2*M_PI;
        sf2 = FixedPoly->getSlope(iVertexFixed);
    }
    //  Then angles for the floating polygon
    if ( iVertexFloat == 0)
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sm1 = FloatPoly->getSlope(FloatPoly->nVertices-2) + M_PI;
        if ( sm1 > M_PI ) sm1 -= 2*M_PI;
        sm2 = FloatPoly->getSlope(0);
    }
    else
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sm1 = FloatPoly->getSlope(iVertexFloat-1) + M_PI;
        if ( sm1 > M_PI ) sm1 -= 2*M_PI;
        sm2 = FloatPoly->getSlope(iVertexFloat);
    }
    switch ( iRot )
    {
    case 0:
    //  if iRot is 0, align sm1 on sf1
        angle = sf1 - sm1;
        break;
    case 1:
    //  if iRot is 1, align sm2 on sf1
        angle = sf1 - sm2;
        break;
    case 2:
    //  if iRot is 2, align sm1 on sf2
        angle = sf2 - sm1;
        break;
    case 3:
    //  if iRot is 3, align sm2 on sf2
        angle = sf2 - sm2;
        break;
    default:
        printf("Invalid choice !!\n");
        FloatPoly = 0;
        FloatPoly->nVertices = 0;           //  Segment violation
    }
    sm1 += angle;
    sm2 += angle;
    //  check if sm1 is OK, given angles sm1, smé, sf1 and sf2
    int res1 = CheckOKAngles(sf1, sf2, sm1);
    if ( res1 == 0 ) return false;
    //  Idem with sm2
    int res2 = CheckOKAngles(sf1, sf2, sm2);
    if (res2 == 0 ) return false;
    //  Also check sf1 upon sm1 and sm2
    int res3 = CheckOKAngles(sm1, sm2, sf1);
    if ( res3 == 0 ) return false;
    //  and finally sf2 upon sm1 and sm2
    int res4 = CheckOKAngles(sm1, sm2, sf2);
    if (res4 == 0 ) return false;
    //  All is OK, return true
    return true;
}

// Assembly:
pushq %rbx
subq $0x40, %rsp
movq %r9, %rbx
testl %ecx, %ecx
je 0x2aaae
movq 0x40(%rdx), %rdx
movslq %ecx, %rcx
leaq (%rdx,%rcx,8), %rax
leaq (%rdx,%rcx,8), %rcx
addq $-0x8, %rcx
jmp 0x2aabe
movslq 0x8(%rdx), %rcx
movq 0x40(%rdx), %rax
leaq (%rax,%rcx,8), %rcx
addq $-0x10, %rcx
movsd 0x955a(%rip), %xmm2     # 0x34020
movsd (%rcx), %xmm3
addsd %xmm2, %xmm3
movsd 0xb752(%rip), %xmm1     # 0x36228
addsd %xmm3, %xmm1
movapd %xmm2, %xmm0
cmpltsd %xmm3, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm3, %xmm0
orpd %xmm1, %xmm0
testl %esi, %esi
je 0x2ab08
movq 0x40(%rdi), %rdx
movslq %esi, %rsi
leaq (%rdx,%rsi,8), %rcx
leaq (%rdx,%rsi,8), %rdx
addq $-0x8, %rdx
jmp 0x2ab18
movslq 0x8(%rdi), %rdx
movq 0x40(%rdi), %rcx
leaq (%rcx,%rdx,8), %rdx
addq $-0x10, %rdx
movsd (%rax), %xmm1
movsd (%rdx), %xmm3
addsd %xmm2, %xmm3
movsd 0xb6fc(%rip), %xmm4     # 0x36228
addsd %xmm3, %xmm4
cmpltsd %xmm3, %xmm2
andpd %xmm2, %xmm4
andnpd %xmm3, %xmm2
orpd %xmm4, %xmm2
movsd (%rcx), %xmm3
cmpl $0x3, %r8d
movapd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm3, (%rsp)
ja 0x2ac0f
movl %r8d, %eax
leaq 0xb80e(%rip), %rcx      # 0x36378
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movapd %xmm0, %xmm4
jmp 0x2ab7d
movapd %xmm1, %xmm4
subsd %xmm2, %xmm4
jmp 0x2ab91
movapd %xmm1, %xmm4
jmp 0x2ab8d
movapd %xmm0, %xmm4
subsd %xmm3, %xmm4
movsd %xmm4, (%rbx)
movsd %xmm4, 0x38(%rsp)
addsd %xmm4, %xmm2
movapd %xmm2, 0x10(%rsp)
callq 0x2aa3a
testb %al, %al
je 0x2ac07
movsd (%rsp), %xmm2
addsd 0x38(%rsp), %xmm2
movapd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd %xmm2, (%rsp)
callq 0x2aa3a
testb %al, %al
je 0x2ac07
movapd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movapd 0x20(%rsp), %xmm2
callq 0x2aa3a
testb %al, %al
je 0x2ac07
movaps 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addq $0x40, %rsp
popq %rbx
jmp 0x2aa3a
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
retq
leaq 0xd37b(%rip), %rdi      # 0x37f91
movapd %xmm2, 0x10(%rsp)
callq 0x8660
movsd 0x8(%rsp), %xmm1
movapd 0x20(%rsp), %xmm0
movapd 0x10(%rsp), %xmm2
andl $0x0, 0x8
movsd (%rbx), %xmm4
jmp 0x2ab95