// File: /workspace/github_cpp_makefile_star2_O1/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 0x31c4e
movq 0x40(%rdx), %rax
movslq %ecx, %rcx
leaq (%rax,%rcx,8), %rax
movsd 0xb3d9(%rip), %xmm0     # 0x3d020
movsd -0x8(%rax), %xmm2
jmp 0x31c64
movslq 0x8(%rdx), %rcx
movq 0x40(%rdx), %rax
movsd 0xb3c2(%rip), %xmm0     # 0x3d020
movsd -0x10(%rax,%rcx,8), %xmm2
addsd %xmm0, %xmm2
movsd 0xd560(%rip), %xmm1     # 0x3f1d0
addsd %xmm2, %xmm1
cmpltsd %xmm2, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
testl %esi, %esi
je 0x31ca3
movq 0x40(%rdi), %rcx
movslq %esi, %rdx
leaq (%rcx,%rdx,8), %rcx
movsd 0xb384(%rip), %xmm2     # 0x3d020
movsd -0x8(%rcx), %xmm3
jmp 0x31cb9
movslq 0x8(%rdi), %rdx
movq 0x40(%rdi), %rcx
movsd 0xb36d(%rip), %xmm2     # 0x3d020
movsd -0x10(%rcx,%rdx,8), %xmm3
addsd %xmm2, %xmm3
movsd 0xd50b(%rip), %xmm1     # 0x3f1d0
addsd %xmm3, %xmm1
cmpltsd %xmm3, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
movsd (%rax), %xmm1
movsd (%rcx), %xmm4
cmpl $0x3, %r8d
movapd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm4, (%rsp)
ja 0x31db0
movl %r8d, %eax
leaq 0xd611(%rip), %rcx      # 0x3f318
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movapd %xmm0, %xmm3
jmp 0x31d1a
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
jmp 0x31d2e
movapd %xmm1, %xmm3
jmp 0x31d2a
movapd %xmm0, %xmm3
subsd %xmm4, %xmm3
movsd %xmm3, (%rbx)
movsd (%rbx), %xmm3
movsd %xmm3, 0x38(%rsp)
addsd %xmm3, %xmm2
movapd %xmm2, 0x10(%rsp)
callq 0x31bd5
testb %al, %al
je 0x31da8
movsd (%rsp), %xmm2
addsd 0x38(%rsp), %xmm2
movapd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd %xmm2, (%rsp)
callq 0x31bd5
testb %al, %al
je 0x31da8
movapd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movapd 0x20(%rsp), %xmm2
callq 0x31bd5
testb %al, %al
je 0x31da8
movaps 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addq $0x40, %rsp
popq %rbx
jmp 0x31bd5
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
retq
leaq 0xf19c(%rip), %rdi      # 0x40f53
movapd %xmm2, 0x10(%rsp)
callq 0x7630
movsd 0x8(%rsp), %xmm1
movapd 0x10(%rsp), %xmm2
movapd 0x20(%rsp), %xmm0
movl $0x0, 0x8
jmp 0x31d32