// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x70, %rsp
movaps %xmm1, 0x60(%rsp)
movapd %xmm0, %xmm8
movq %rdi, %rbx
leaq 0x10(%rdi), %r14
movl 0x8(%rdi), %eax
movq 0x10(%rdi), %rcx
movsd 0x12f5b(%rip), %xmm1    # 0x3c008
movapd 0x1500a(%rip), %xmm9    # 0x3e0c0
movapd 0x14f71(%rip), %xmm10   # 0x3e030
movsd 0x14f98(%rip), %xmm11   # 0x3e060
leaq 0x161fe(%rip), %r15     # 0x3f2cd
movapd 0x14fe8(%rip), %xmm12   # 0x3e0c0
leaq 0x50(%rsp), %r12
movl %eax, %edx
incl %eax
shlq $0x4, %rdx
addq %rcx, %rdx
decl %eax
cmpl $0x2, %eax
jl 0x29386
leaq -0x10(%rdx), %r13
movupd -0x20(%rdx), %xmm14
movupd -0x10(%rdx), %xmm2
movapd %xmm2, %xmm13
subpd %xmm14, %xmm13
movapd %xmm13, %xmm0
mulpd %xmm13, %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm13, %xmm4
mulsd %xmm13, %xmm4
addsd %xmm4, %xmm0
xorps %xmm15, %xmm15
sqrtsd %xmm0, %xmm15
ucomisd %xmm8, %xmm15
movq %r13, %rdx
jbe 0x290e8
movaps %xmm1, (%rsp)
movapd %xmm14, %xmm5
unpckhpd %xmm14, %xmm5           # xmm5 = xmm5[1],xmm14[1]
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
movapd %xmm5, %xmm0
subsd %xmm3, %xmm0
movapd %xmm13, %xmm1
xorpd %xmm9, %xmm1
movapd %xmm0, %xmm6
mulsd %xmm0, %xmm6
mulsd %xmm13, %xmm1
subsd %xmm6, %xmm1
movapd %xmm1, %xmm7
andpd %xmm10, %xmm7
ucomisd %xmm7, %xmm11
movsd %xmm8, 0x18(%rsp)
jbe 0x291ca
movq %r15, %rdi
movapd %xmm13, 0x40(%rsp)
movapd %xmm14, 0x30(%rsp)
movsd %xmm15, 0x20(%rsp)
callq 0x70b0
movsd 0x20(%rsp), %xmm15
movapd 0x30(%rsp), %xmm14
movapd 0x40(%rsp), %xmm13
movsd 0x18(%rsp), %xmm8
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
jmp 0x2923e
movapd %xmm0, %xmm7
xorpd %xmm9, %xmm7
addsd %xmm4, %xmm6
xorps %xmm4, %xmm4
sqrtsd %xmm6, %xmm4
mulsd %xmm5, %xmm7
mulsd %xmm5, %xmm2
mulsd %xmm14, %xmm3
subsd %xmm2, %xmm3
unpcklpd %xmm7, %xmm3            # xmm3 = xmm3[0],xmm7[0]
movapd 0x60(%rsp), %xmm2
unpcklpd %xmm13, %xmm2           # xmm2 = xmm2[0],xmm13[0]
unpcklpd %xmm14, %xmm4           # xmm4 = xmm4[0],xmm14[0]
mulpd %xmm2, %xmm4
addpd %xmm3, %xmm4
movapd %xmm4, %xmm2
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
xorpd %xmm12, %xmm2
movapd %xmm13, %xmm3
unpcklpd %xmm13, %xmm3           # xmm3 = xmm3[0],xmm13[0]
unpcklpd %xmm4, %xmm2            # xmm2 = xmm2[0],xmm4[0]
mulpd %xmm3, %xmm2
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm4, %xmm0
addpd %xmm2, %xmm0
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm0
movapd (%rsp), %xmm2
divsd %xmm8, %xmm15
cvttsd2si %xmm15, %eax
incl %eax
subpd %xmm14, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movupd 0xa0(%rbx), %xmm3
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm13
addpd %xmm14, %xmm13
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm0, %xmm2
addpd %xmm13, %xmm2
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
movapd %xmm3, 0x40(%rsp)
divpd %xmm3, %xmm2
movapd %xmm2, 0x20(%rsp)
movapd %xmm2, %xmm0
callq 0x71c0
movapd %xmm0, 0x30(%rsp)
movapd 0x20(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
callq 0x71c0
movapd 0x30(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
mulpd 0x40(%rsp), %xmm1
movapd %xmm1, 0x50(%rsp)
movaps 0x14df3(%rip), %xmm1    # 0x3e0c0
movaps (%rsp), %xmm0
xorps %xmm1, %xmm0
movaps %xmm0, (%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x297ca
movsd 0x18(%rsp), %xmm8
movapd 0x50(%rsp), %xmm0
movupd 0x58(%rbx), %xmm1
movapd %xmm0, %xmm2
minpd %xmm1, %xmm2
cmpunordpd %xmm1, %xmm1
movapd %xmm0, %xmm3
andpd %xmm1, %xmm3
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
movupd %xmm1, 0x58(%rbx)
movupd 0x68(%rbx), %xmm1
movapd %xmm0, %xmm2
maxpd %xmm1, %xmm2
cmpunordpd %xmm1, %xmm1
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movupd %xmm1, 0x68(%rbx)
movl $0x1, 0x9c(%rbx)
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rax
subq %rcx, %rax
shrq $0x4, %rax
movl %eax, 0x8(%rbx)
movaps (%rsp), %xmm1
movapd 0x14d5a(%rip), %xmm9    # 0x3e0c0
movapd 0x14cc1(%rip), %xmm10   # 0x3e030
movsd 0x14ce8(%rip), %xmm11   # 0x3e060
movapd 0x14d3f(%rip), %xmm12   # 0x3e0c0
jmp 0x290dd
movl $0x1, 0x9c(%rbx)
movq %rbx, %rdi
callq 0x266bc
movq %rbx, %rdi
callq 0x276c8
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq