// File: 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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5b4e0
movq -0xd0(%rbp), %rax
movq $0x0, -0x50(%rbp)
cmpl $0x0, 0x60(%rax)
jle 0x6f11b
movq -0xd0(%rbp), %rdi
addq $0x68, %rdi
leaq 0x1696b(%rip), %rsi     # 0x85a81
callq 0x9530
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x1507d(%rip), %xmm0    # 0x841a8
ucomisd -0x60(%rbp), %xmm0
jbe 0x6f392
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6f187
cmpq $0x0, -0x50(%rbp)
je 0x6f16b
movq -0x50(%rbp), %rax
movq %rax, -0xd8(%rbp)
cmpq $0x0, %rax
je 0x6f169
movq -0xd8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x6f16b
movq -0x18(%rbp), %rdi
movsd -0x60(%rbp), %xmm0
callq 0x61ed0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x6f18f
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x61320
movq -0xd0(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq -0x78(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq -0x70(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movq -0x68(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x30(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x88(%rbp), %xmm1
movsd 0x10(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6f37c
movq -0xd0(%rbp), %rax
movsd -0x90(%rbp), %xmm1
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6f37c
movq -0xd0(%rbp), %rdi
movl -0x1c(%rbp), %esi
cvttsd2si -0x88(%rbp), %edx
cvttsd2si -0x90(%rbp), %ecx
callq 0x72dd0
movsd %xmm0, -0xa0(%rbp)
movsd %xmm1, -0x98(%rbp)
leaq -0x48(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x63e00
movsd %xmm0, -0xb0(%rbp)
movsd %xmm1, -0xa8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x80800
movq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x7ff40
movq %rax, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x63d60
movsd %xmm0, -0xc0(%rbp)
movsd %xmm1, -0xb8(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x80800
movq -0x58(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
xorl %edx, %edx
callq 0x61b20
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x6f2ed
movq -0x50(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, %rax
je 0x6f2eb
movq -0xe0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x6f2ed
movq -0xd0(%rbp), %rax
cmpl $0x0, 0x60(%rax)
jle 0x6f36f
movq -0xd0(%rbp), %rdi
addq $0x68, %rdi
leaq 0x1678d(%rip), %rsi     # 0x85a99
callq 0x9530
movq %rax, -0xe8(%rbp)
movsd 0x14e98(%rip), %xmm0    # 0x841b8
mulsd -0x60(%rbp), %xmm0
movsd 0x12ceb(%rip), %xmm1    # 0x82018
divsd %xmm1, %xmm0
callq 0x9220
movq -0xe8(%rbp), %rdi
callq 0x9a30
movq %rax, %rdi
leaq 0x16771(%rip), %rsi     # 0x85abd
callq 0x9530
movq %rax, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x80760
movq %rax, %rdi
leaq 0x15f51(%rip), %rsi     # 0x852bb
callq 0x9530
movq -0xc8(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f39a
jmp 0x6f37e
movsd -0x28(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x6f123
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)