// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movsd %xmm1, 0x68(%rsp)
movapd %xmm0, %xmm2
movq %rdi, %rbx
leaq 0x10(%rdi), %r14
movsd 0x136c6(%rip), %xmm0    # 0x3d008
movapd %xmm0, 0x50(%rsp)
movapd 0x15730(%rip), %xmm3    # 0x3f080
movsd %xmm2, 0x8(%rsp)
movl 0x8(%rbx), %r15d
leal 0x1(%r15), %ebp
shlq $0x4, %r15
addq $-0x10, %r15
xorl %r12d, %r12d
decl %ebp
cmpl $0x2, %ebp
jl 0x29d44
movq (%r14), %rax
movsd (%rax,%r15), %xmm0
subsd -0x10(%rax,%r15), %xmm0
movsd 0x8(%rax,%r15), %xmm1
subsd -0x8(%rax,%r15), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x15732(%rip), %xmm0    # 0x3f0d8
jb 0x299ae
sqrtsd %xmm0, %xmm0
jmp 0x299c1
callq 0x7370
movapd 0x156c5(%rip), %xmm3    # 0x3f080
movsd 0x8(%rsp), %xmm2
ucomisd %xmm2, %xmm0
jbe 0x29d36
movsd %xmm0, 0x48(%rsp)
movq (%r14), %rax
movsd -0x10(%rax,%r15), %xmm9
movsd -0x8(%rax,%r15), %xmm10
movsd 0x8(%rax,%r15), %xmm11
movapd %xmm10, %xmm5
subsd %xmm11, %xmm5
movsd (%rax,%r15), %xmm12
movapd %xmm12, %xmm8
subsd %xmm9, %xmm8
movapd %xmm8, %xmm0
mulsd %xmm8, %xmm0
movapd %xmm5, %xmm4
mulsd %xmm5, %xmm4
addsd %xmm4, %xmm0
ucomisd 0x156b7(%rip), %xmm0    # 0x3f0d8
jb 0x29a2f
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0x29ab0
movapd %xmm5, 0x10(%rsp)
movapd %xmm8, 0x30(%rsp)
movsd %xmm9, 0x88(%rsp)
movsd %xmm10, 0x80(%rsp)
movsd %xmm11, 0x78(%rsp)
movsd %xmm12, 0x70(%rsp)
movapd %xmm4, 0x90(%rsp)
callq 0x7370
movapd 0x90(%rsp), %xmm4
movsd 0x70(%rsp), %xmm12
movsd 0x78(%rsp), %xmm11
movsd 0x80(%rsp), %xmm10
movsd 0x88(%rsp), %xmm9
movapd 0x30(%rsp), %xmm8
movapd 0x10(%rsp), %xmm5
movapd 0x155d4(%rip), %xmm3    # 0x3f080
movapd %xmm0, %xmm1
movapd %xmm8, %xmm2
xorpd %xmm3, %xmm2
movq (%r14), %r12
movsd -0x10(%r12,%r15), %xmm7
movsd -0x8(%r12,%r15), %xmm6
mulsd %xmm8, %xmm2
subsd %xmm4, %xmm2
movapd %xmm2, %xmm0
andpd 0x15551(%rip), %xmm0    # 0x3f030
movsd 0x155e1(%rip), %xmm4    # 0x3f0c8
ucomisd %xmm0, %xmm4
jbe 0x29b17
leaq 0x1673d(%rip), %rdi     # 0x40231
movsd %xmm6, 0x10(%rsp)
movsd %xmm7, 0x30(%rsp)
callq 0x70b0
movsd 0x30(%rsp), %xmm7
movsd 0x10(%rsp), %xmm6
movapd %xmm0, %xmm4
jmp 0x29b74
movapd %xmm5, %xmm0
xorpd %xmm3, %xmm0
mulsd %xmm6, %xmm0
movapd %xmm8, %xmm4
mulsd %xmm7, %xmm4
addsd %xmm0, %xmm4
mulsd %xmm12, %xmm10
mulsd %xmm11, %xmm9
subsd %xmm10, %xmm9
mulsd 0x68(%rsp), %xmm1
addsd %xmm9, %xmm1
movapd %xmm8, %xmm3
mulsd %xmm4, %xmm3
movapd %xmm5, %xmm0
mulsd %xmm1, %xmm0
subsd %xmm3, %xmm0
divsd %xmm2, %xmm0
mulsd %xmm8, %xmm1
mulsd %xmm5, %xmm4
addsd %xmm1, %xmm4
divsd %xmm2, %xmm4
movsd 0x48(%rsp), %xmm1
divsd 0x8(%rsp), %xmm1
cvttsd2si %xmm1, %eax
incl %eax
subsd %xmm7, %xmm0
subsd %xmm6, %xmm4
leaq (%r12,%r15), %r13
movsd (%r12,%r15), %xmm1
movsd -0x10(%r12,%r15), %xmm2
movsd -0x8(%r12,%r15), %xmm3
subsd %xmm2, %xmm1
movapd %xmm4, %xmm5
xorps %xmm4, %xmm4
cvtsi2sd %eax, %xmm4
divsd %xmm4, %xmm1
addsd %xmm2, %xmm1
movsd 0x8(%r12,%r15), %xmm2
subsd %xmm3, %xmm2
divsd %xmm4, %xmm2
addsd %xmm3, %xmm2
movapd 0x50(%rsp), %xmm3
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
mulsd %xmm3, %xmm5
addsd %xmm2, %xmm5
movapd %xmm5, 0x30(%rsp)
movsd %xmm5, 0x28(%rsp)
movsd 0xa0(%rbx), %xmm1
movsd %xmm1, 0x10(%rsp)
divsd %xmm1, %xmm0
callq 0x71c0
movsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movapd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x71c0
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movaps 0x50(%rsp), %xmm0
xorps 0x1543a(%rip), %xmm0    # 0x3f080
movaps %xmm0, 0x50(%rsp)
movq %r14, %rdi
movq %r13, %rsi
leaq 0x20(%rsp), %rdx
callq 0x2a184
movsd 0x58(%rbx), %xmm1
movsd 0x20(%rsp), %xmm0
movapd %xmm0, %xmm2
minsd %xmm1, %xmm2
cmpunordsd %xmm1, %xmm1
movapd %xmm1, %xmm3
andpd %xmm0, %xmm3
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
movlpd %xmm1, 0x58(%rbx)
movsd 0x60(%rbx), %xmm2
movsd 0x28(%rsp), %xmm1
movapd %xmm1, %xmm3
minsd %xmm2, %xmm3
cmpunordsd %xmm2, %xmm2
movapd %xmm2, %xmm4
andpd %xmm1, %xmm4
andnpd %xmm3, %xmm2
orpd %xmm4, %xmm2
movlpd %xmm2, 0x60(%rbx)
movsd 0x68(%rbx), %xmm2
movapd %xmm2, %xmm3
cmpunordsd %xmm2, %xmm3
movapd %xmm3, %xmm4
andpd %xmm0, %xmm4
maxsd %xmm2, %xmm0
andnpd %xmm0, %xmm3
orpd %xmm4, %xmm3
movlpd %xmm3, 0x68(%rbx)
movsd 0x70(%rbx), %xmm0
movapd %xmm0, %xmm2
cmpunordsd %xmm0, %xmm2
movapd %xmm2, %xmm3
andpd %xmm1, %xmm3
maxsd %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movlpd %xmm2, 0x70(%rbx)
movsd 0x8(%rsp), %xmm2
movl $0x1, 0x9c(%rbx)
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
shrq $0x4, %rax
movl %eax, 0x8(%rbx)
movl $0x1, %r12d
movapd 0x1534a(%rip), %xmm3    # 0x3f080
addq $-0x10, %r15
ucomisd %xmm2, %xmm0
jbe 0x29969
testl %r12d, %r12d
jne 0x29956
movl $0x1, 0x9c(%rbx)
movq %rbx, %rdi
callq 0x26926
movq %rbx, %rdi
callq 0x27c90
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop