// File: /workspace/github_cpp_makefile_star2_O1/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, 0x30(%rsp)
movl %edx, 0x24(%rsp)
movq %rsi, %r12
movq %rdi, %r15
cmpl $0x0, 0x60(%rdi)
jle 0x32c89
leaq 0x68(%r15), %rdi
leaq 0xdd64(%rip), %rsi      # 0x409e3
movl $0x17, %edx
callq 0x74d0
leaq 0x68(%r15), %rax
movq %rax, 0x28(%rsp)
leaq 0x38(%rsp), %r13
xorl %ebp, %ebp
xorpd %xmm1, %xmm1
ucomisd 0xc433(%rip), %xmm1     # 0x3f0d8
movsd %xmm1, 0x18(%rsp)
jbe 0x32cd6
testq %rbp, %rbp
je 0x32cc2
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x8(%rax)
movsd 0x18(%rsp), %xmm1
movq %r12, %rdi
movapd %xmm1, %xmm0
callq 0x28904
movq %rax, %r14
movq %rax, %rbp
jmp 0x32cd9
movq %r12, %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x2822c
movsd 0x38(%rsp), %xmm6
movsd 0x40(%rsp), %xmm5
movsd 0x48(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
subsd %xmm6, %xmm0
subsd %xmm5, %xmm1
movsd 0x18(%r15), %xmm2
movsd 0x10(%r15), %xmm3
movapd %xmm0, %xmm4
cmpnltpd %xmm3, %xmm4
movapd %xmm1, %xmm3
cmpnltpd %xmm2, %xmm3
orpd %xmm4, %xmm3
movd %xmm3, %ebx
testb $0x1, %bl
jne 0x32e92
cvttsd2si %xmm0, %edx
cvttsd2si %xmm1, %ecx
movq %r15, %rdi
movl 0x24(%rsp), %esi
movsd %xmm5, 0x8(%rsp)
movsd %xmm6, 0x10(%rsp)
callq 0x35b4a
subsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0xc35b(%rip), %xmm1     # 0x3f0c8
divsd %xmm1, %xmm0
callq 0x71c0
movsd 0xc34a(%rip), %xmm1     # 0x3f0c8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x71c0
movq 0x10(%r14), %rax
movsd 0x8(%rsp), %xmm1
addsd (%rax), %xmm1
movsd 0xc31b(%rip), %xmm2     # 0x3f0c8
mulsd %xmm2, %xmm0
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
divsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x71c0
movsd 0xc2f7(%rip), %xmm1     # 0x3f0c8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x71c0
mulsd 0xc2d6(%rip), %xmm0     # 0x3f0c8
movsd %xmm0, 0x40(%rsp)
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x2869e
movq %rax, 0x8(%rsp)
testq %rbp, %rbp
je 0x32e19
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x8(%rax)
cmpl $0x0, 0x60(%r15)
jle 0x32e92
movl $0x23, %edx
movq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0xdbc7(%rip), %rsi      # 0x409fb
callq 0x74d0
movsd 0x18(%rsp), %xmm0
mulsd 0xc331(%rip), %xmm0     # 0x3f178
divsd 0xa1d1(%rip), %xmm0     # 0x3d020
callq 0x71c0
movq %r14, %rdi
callq 0x7680
movq %rax, %r14
movl $0x13, %edx
movq %rax, %rdi
leaq 0xdbb1(%rip), %rsi      # 0x40a1f
callq 0x74d0
movq %r14, %rdi
movq %r13, %rsi
callq 0x3c96c
movl $0x1, %edx
movq %rax, %rdi
leaq 0xd3a3(%rip), %rsi      # 0x40230
callq 0x74d0
testb $0x1, %bl
je 0x32eb9
movsd 0x18(%rsp), %xmm1
addsd 0x30(%rsp), %xmm1
movsd 0xc32d(%rip), %xmm0     # 0x3f1d8
ucomisd %xmm1, %xmm0
ja 0x32c9d
xorl %eax, %eax
jmp 0x32ebe
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop