// File: thierry7100[P]CutOptim/src/Geometry.cpp
// Function: Polygon::BreakLongerEdges(double, double)
void Polygon::BreakLongerEdges(double max_length, double Diff)
{
std::vector<Point>::iterator it;
double Sign = 1;
int Modified = 0;

    do {
        Modified = 0;
        //  Do it reverse to avoid problem with indexes when inserting new points
        for ( int i = nVertices - 1; i > 0; i-- )
        {
            double l = _Vertices[i].Distance(_Vertices[i-1]);       //  Segment length
            if ( l > max_length )
            {
                //  Too long, break it
                int nSegment = (int)(l / max_length) + 1;       //  Number of segments, will add nSegment - 1 vertices
                //  Compute Delta off line
                //  For each segment create a segment which is parallel to the original segment, but translated at distance Diff
                //  Original segment
                double a = _Vertices[i-1].y - _Vertices[i].y;
                double b = _Vertices[i].x - _Vertices[i-1].x;
                double c = _Vertices[i-1].x * _Vertices[i].y - _Vertices[i].x * _Vertices[i-1].y;
                //  If equation of first segment is ax + by + c = 0, the translated segment has an equation like ax + by + C = 0 where C = c + Diff*sqrt(a*a + b*b)
                //  Here we will first build a segment which begins in A' and end in B' where A' is the point on the line perpendicular to the segment and which starts in A
                double C = c + Diff*sqrt(a*a+b*b);
                Line A1B1 = Line(a, b, C);
                //  Now the lines which are perpendicular in A or B to the segment
                Line AB_perpendicular_A = Line(-b, a, b*_Vertices[i-1].x - a*_Vertices[i-1].y);
                // Compute intersection of AB_perpendicular_A and A1B1 (point A1)
                Point A1 = A1B1.Intersect(AB_perpendicular_A);
                Point Delta = Point(A1.x - _Vertices[i-1].x, A1.y - _Vertices[i-1].y );
                //  Insert only one point at a time to avoid indices mismatch
                Point As = Point(_Vertices[i-1].x + (_Vertices[i].x-_Vertices[i-1].x) / double(nSegment), _Vertices[i-1].y + (_Vertices[i].y-_Vertices[i-1].y) / double(nSegment));
                As.x += Sign * Delta.x;
                As.y += Sign * Delta.y;
                As.x = round(As.x/precision)*precision;
                As.y = round(As.y/precision)*precision;
                Sign *= -1;
                it = _Vertices.begin();
                _Vertices.insert(it + i, As);
                BoundingBox.A.x = fmin(BoundingBox.A.x, As.x);
                BoundingBox.A.y = fmin(BoundingBox.A.y, As.y);
                BoundingBox.B.x = fmax(BoundingBox.B.x, As.x);
                BoundingBox.B.y = fmax(BoundingBox.B.y, As.y);
                Modified = 1;
                poly_changed = 1;
                nVertices = _Vertices.size();
                break;
            }
        }
    } while ( Modified );
    ReCalcArea();
    ReCalcBoundingBox();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x64d70
movsd 0x20fd3(%rip), %xmm0    # 0x840f8
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0xe8(%rbp), %rax
movl $0x0, -0x2c(%rbp)
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x6385f
movq -0xe8(%rbp), %rdi
addq $0x10, %rdi
movslq -0x30(%rbp), %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movq %rax, -0xf0(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x63d00
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
ucomisd -0x10(%rbp), %xmm0
jbe 0x6384f
movq -0xe8(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
divsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x198(%rbp)
addq $0x10, %rdi
movslq -0x30(%rbp), %rsi
callq 0x63990
movsd -0x198(%rbp), %xmm0
movq -0xe8(%rbp), %rdi
subsd 0x8(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
addq $0x10, %rdi
movslq -0x30(%rbp), %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movsd -0x190(%rbp), %xmm0
movq -0xe8(%rbp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x180(%rbp)
addq $0x10, %rdi
movslq -0x30(%rbp), %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
addq $0x10, %rdi
movslq -0x30(%rbp), %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movsd -0x188(%rbp), %xmm1
movsd -0x180(%rbp), %xmm0
movsd -0x178(%rbp), %xmm2
mulsd 0x8(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x168(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x48(%rbp), %xmm2
movsd -0x50(%rbp), %xmm1
mulsd -0x50(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x9460
movsd -0x170(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x168(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
leaq -0x78(%rbp), %rdi
callq 0x63b70
movq -0xe8(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x148(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x140(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x158(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x150(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movsd -0x160(%rbp), %xmm3
movsd -0x158(%rbp), %xmm2
movsd -0x150(%rbp), %xmm4
movsd -0x148(%rbp), %xmm0
movsd -0x140(%rbp), %xmm1
mulsd 0x8(%rax), %xmm3
movq %xmm3, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm3
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
leaq -0x90(%rbp), %rdi
callq 0x63b70
leaq -0x78(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x63bb0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0xa0(%rbp)
movsd %xmm1, -0x98(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x138(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movsd -0x138(%rbp), %xmm0
movq -0xe8(%rbp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movsd -0x130(%rbp), %xmm1
movsd -0x128(%rbp), %xmm0
subsd 0x8(%rax), %xmm1
leaq -0xb0(%rbp), %rdi
callq 0x5b520
movq -0xe8(%rbp), %rdi
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
addq $0x10, %rdi
movslq -0x30(%rbp), %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x120(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movsd -0x120(%rbp), %xmm1
movsd -0x118(%rbp), %xmm0
movq -0xe8(%rbp), %rdi
subsd (%rax), %xmm1
cvtsi2sdl -0x3c(%rbp), %xmm2
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x108(%rbp)
addq $0x10, %rdi
movslq -0x30(%rbp), %rsi
callq 0x63990
movq -0xe8(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
addq $0x10, %rdi
movl -0x30(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x63990
movsd -0x110(%rbp), %xmm2
movsd -0x108(%rbp), %xmm1
movsd -0x100(%rbp), %xmm0
subsd 0x8(%rax), %xmm2
cvtsi2sdl -0x3c(%rbp), %xmm3
divsd %xmm3, %xmm2
addsd %xmm2, %xmm1
leaq -0xc0(%rbp), %rdi
callq 0x5b520
movq -0xe8(%rbp), %rax
movsd -0x28(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm2
movsd -0xc0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x28(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm2
movsd -0xb8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xc0(%rbp), %xmm0
divsd 0xa0(%rax), %xmm0
callq 0x9220
movq -0xe8(%rbp), %rax
mulsd 0xa0(%rax), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xb8(%rbp), %xmm0
divsd 0xa0(%rax), %xmm0
callq 0x9220
movq -0xe8(%rbp), %rdi
mulsd 0xa0(%rdi), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd 0x20a2b(%rip), %xmm0    # 0x84108
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
addq $0x10, %rdi
callq 0x5b490
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movq %rcx, -0xc8(%rbp)
movq -0xc8(%rbp), %rcx
movq %rcx, -0x20(%rbp)
addq $0x10, %rax
movq %rax, -0xf8(%rbp)
movslq -0x30(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x5c560
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x5b380
movq -0xf8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x64d90
movq -0xe8(%rbp), %rdi
movq %rax, -0xe0(%rbp)
movsd 0x58(%rdi), %xmm3
movsd -0xc0(%rbp), %xmm2
movaps %xmm2, %xmm4
movaps %xmm3, %xmm0
cmpunordsd %xmm0, %xmm0
movaps %xmm0, %xmm1
pand %xmm4, %xmm1
minsd %xmm3, %xmm2
pandn %xmm2, %xmm0
por %xmm1, %xmm0
movsd %xmm0, 0x58(%rdi)
movsd 0x60(%rdi), %xmm3
movsd -0xb8(%rbp), %xmm2
movaps %xmm2, %xmm4
movaps %xmm3, %xmm0
cmpunordsd %xmm0, %xmm0
movaps %xmm0, %xmm1
pand %xmm4, %xmm1
minsd %xmm3, %xmm2
pandn %xmm2, %xmm0
por %xmm1, %xmm0
movsd %xmm0, 0x60(%rdi)
movsd 0x68(%rdi), %xmm3
movsd -0xc0(%rbp), %xmm2
movaps %xmm2, %xmm4
movaps %xmm3, %xmm0
cmpunordsd %xmm0, %xmm0
movaps %xmm0, %xmm1
pand %xmm4, %xmm1
maxsd %xmm3, %xmm2
pandn %xmm2, %xmm0
por %xmm1, %xmm0
movsd %xmm0, 0x68(%rdi)
movsd 0x70(%rdi), %xmm3
movsd -0xb8(%rbp), %xmm2
movaps %xmm2, %xmm4
movaps %xmm3, %xmm0
cmpunordsd %xmm0, %xmm0
movaps %xmm0, %xmm1
pand %xmm4, %xmm1
maxsd %xmm3, %xmm2
pandn %xmm2, %xmm0
por %xmm1, %xmm0
movsd %xmm0, 0x70(%rdi)
movl $0x1, -0x2c(%rbp)
movl $0x1, 0x9c(%rdi)
addq $0x10, %rdi
callq 0x5add0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x6385f
jmp 0x63851
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x63148
jmp 0x63861
cmpl $0x0, -0x2c(%rbp)
jne 0x63131
movq -0xe8(%rbp), %rdi
callq 0x612f0
movq -0xe8(%rbp), %rdi
callq 0x60860
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopl (%rax)