// File: /workspace/github_cpp_makefile_star2_O2/thierry7100[P]CutOptim/src/SvgDoc.cpp
// Function: SvgDoc::PlaceFirst(Polygon*, int, double)
Polygon *SvgDoc::PlaceFirst(Polygon *p, int FirstPos, double StepAngle)
{
Rectangle BBox;
Polygon *Rot = NULL;
Polygon *cur;

    if ( debug_level > 0 )
    {
        OutDebug << "Entering PlaceFirst...\n";
    }
    //  If possible place polygon at page center
    for (double angle = 0; angle < 2*M_PI - 0.001; angle += StepAngle)
    {
        if ( angle > 0 )
        {
            if (Rot != NULL) delete Rot;
            Rot = p->Rotate(angle);
            cur = Rot;
        }
        else
        {
            cur = p;
        }
        BBox = cur->GetBoundingBox();
        double xSize = BBox.B.x - BBox.A.x;
        double ySize = BBox.B.y - BBox.A.y;
        if ( xSize < SheetSizeX && ySize < SheetSizeY )
        {
            //  Possible, compute new position. new Bounding box point A will be in
            Point newA = ComputeRefPoint(FirstPos, xSize, ySize);
            Point Translation = newA - BBox.A;
            Translation.align_grid();
            Point newPt0 = *(cur->GetVertex(0)) + Translation;
            newPt0.align_grid();
            Polygon *Translated = cur->Translate(&newPt0, 0);        //  Move point 0 to this point
            if ( Rot != NULL ) delete Rot;
            if ( debug_level > 0 )
            {
                OutDebug << "First polygon placed with rotation " <<  round(angle*180/M_PI) << "° and translation " << newPt0 << "\n";
            }
            return Translated;
        }
    }
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm0, (%rsp)
movl %edx, 0x20(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
cmpl $0x0, 0x60(%rdi)
jle 0x2b75f
leaq 0x68(%rbx), %rdi
leaq 0xc2e5(%rip), %rsi      # 0x37a3f
callq 0x8420
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbp
xorpd %xmm0, %xmm0
xorl %r15d, %r15d
movsd 0xaaba(%rip), %xmm1     # 0x36230
ucomisd %xmm0, %xmm1
jbe 0x2b92b
ucomisd 0xaa78(%rip), %xmm0     # 0x36200
movsd %xmm0, 0x18(%rsp)
jbe 0x2b7b4
testq %r15, %r15
je 0x2b7a4
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movsd 0x18(%rsp), %xmm0
movq %r13, %rdi
callq 0x23738
movq %rax, %r12
movq %rax, %r15
jmp 0x2b7b7
movq %r13, %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2329a
movapd 0x30(%rsp), %xmm3
movapd 0x40(%rsp), %xmm0
subpd %xmm3, %xmm0
movupd 0x10(%rbx), %xmm1
movapd %xmm0, %xmm2
cmpltpd %xmm1, %xmm2
movmskpd %xmm2, %eax
cmpl $0x3, %eax
je 0x2b7f9
movsd 0x18(%rsp), %xmm0
addsd (%rsp), %xmm0
jmp 0x2b76e
cvttsd2si %xmm0, %edx
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
cvttsd2si %xmm0, %ecx
movq %rbx, %rdi
movl 0x20(%rsp), %esi
movapd %xmm3, (%rsp)
callq 0x2dca4
movq 0x10(%r12), %r14
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
subpd (%rsp), %xmm0
divpd 0xa954(%rip), %xmm0     # 0x36180
movapd %xmm0, 0x20(%rsp)
callq 0x81a0
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
callq 0x81a0
movapd (%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0xa924(%rip), %xmm2     # 0x36180
mulpd %xmm2, %xmm1
movupd (%r14), %xmm0
addpd %xmm1, %xmm0
divpd %xmm2, %xmm0
movapd %xmm0, 0x20(%rsp)
callq 0x81a0
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
callq 0x81a0
movapd (%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
mulpd 0xa8e3(%rip), %xmm1     # 0x36180
leaq 0x30(%rsp), %rsi
movapd %xmm1, (%rsi)
movq %r12, %rdi
xorl %edx, %edx
callq 0x235aa
movq %rax, %r14
testq %r15, %r15
je 0x2b8c1
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
cmpl $0x0, 0x60(%rbx)
jle 0x2b92b
addq $0x68, %rbx
leaq 0xc185(%rip), %rsi      # 0x37a57
movq %rbx, %rdi
callq 0x8420
movq %rax, %rbx
movsd 0x18(%rsp), %xmm0
mulsd 0xa8e5(%rip), %xmm0     # 0x361d0
divsd 0x872d(%rip), %xmm0     # 0x34020
callq 0x81a0
movq %rbx, %rdi
callq 0x86b0
leaq 0xc174(%rip), %rsi      # 0x37a7b
movq %rax, %rdi
callq 0x8420
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x333fd
leaq 0xb969(%rip), %rsi      # 0x3728c
movq %rax, %rdi
callq 0x8420
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop