// File: /workspace/github_cpp_makefile_star2_O1/thierry7100[P]CutOptim/src/Geometry.cpp
// Function: Polygon::Simplify(double)
void Polygon::Simplify(double max_error)
{
Point A = _Vertices[nVertices-1];           //  Start at end of polygon, to keep indexes OK
Point B;
Point C;
int hasSimplify = 1;

    while ( hasSimplify )
    {
        hasSimplify = 0;
        if ( nVertices == 3 ) break;    //  Not able to remove one more vertex
        //  Now walk through all path elements to delete vertices if they are aligned
        for ( int i = nVertices-2; i > 0; i--)
        {
            B = _Vertices[i];
            C = _Vertices[i-1];
            Segment AC = Segment(A, C);
            if ( AC.sqrDistancePoint(B) < max_error)
            {
                //  Point B is not necessary, remove
                delVertex(i);
                hasSimplify = 1;
                break;              //  Will start a new loop
            }
            A = B;
        }
        //  Now the case of first vertex (and last one)
        A = _Vertices[1];
        B = _Vertices[0];
        C = _Vertices[nVertices-2];
        Segment AC = Segment(A, C);
        if ( AC.sqrDistancePoint(B) < max_error)
        {
            //  Point B, with index 0 is not neceassry, remove it
            delVertex(0);               // Beware, this is also index nVertices - 1
            _Vertices[nVertices-1] = _Vertices[0];  //  New index 0, was 1 before removing point
            hasSimplify = 1;
        }
    }
    ReCalcArea();
    ReCalcBoundingBox();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movslq 0x8(%rdi), %rax
movq 0x10(%rdi), %rcx
shlq $0x4, %rax
movsd -0x10(%rcx,%rax), %xmm12
movsd -0x8(%rcx,%rax), %xmm13
xorpd %xmm11, %xmm11
movsd %xmm0, 0x10(%rsp)
movl 0x8(%rbx), %r14d
cmpl $0x3, %r14d
je 0x296e1
addl $-0x2, %r14d
movq %r14, %r15
shlq $0x4, %r15
xorl %eax, %eax
testl %r14d, %r14d
jle 0x29540
movq 0x10(%rbx), %rcx
movsd (%rcx,%r15), %xmm9
movsd 0x8(%rcx,%r15), %xmm1
movsd -0x10(%rcx,%r15), %xmm4
movsd -0x8(%rcx,%r15), %xmm3
movapd %xmm4, %xmm2
subsd %xmm12, %xmm2
movapd %xmm9, %xmm10
subsd %xmm12, %xmm10
movapd %xmm3, %xmm6
subsd %xmm13, %xmm6
movapd %xmm1, %xmm5
subsd %xmm13, %xmm5
mulsd %xmm5, %xmm6
movapd %xmm2, %xmm7
mulsd %xmm10, %xmm7
addsd %xmm6, %xmm7
ucomisd %xmm7, %xmm11
jbe 0x2944c
mulsd %xmm5, %xmm5
mulsd %xmm10, %xmm10
addsd %xmm5, %xmm10
jmp 0x294db
movapd %xmm13, %xmm5
subsd %xmm3, %xmm5
movapd %xmm12, %xmm7
subsd %xmm4, %xmm7
movapd %xmm9, %xmm10
subsd %xmm4, %xmm10
movapd %xmm1, %xmm6
subsd %xmm3, %xmm6
movapd %xmm5, %xmm8
mulsd %xmm6, %xmm8
mulsd %xmm10, %xmm7
addsd %xmm8, %xmm7
ucomisd %xmm7, %xmm11
jbe 0x2949b
mulsd %xmm6, %xmm6
mulsd %xmm10, %xmm10
addsd %xmm6, %xmm10
jmp 0x294db
mulsd %xmm13, %xmm4
mulsd %xmm12, %xmm3
subsd %xmm4, %xmm3
movapd %xmm1, %xmm4
mulsd %xmm2, %xmm4
movapd %xmm5, %xmm10
mulsd %xmm9, %xmm10
addsd %xmm4, %xmm10
addsd %xmm3, %xmm10
mulsd %xmm10, %xmm10
mulsd %xmm2, %xmm2
mulsd %xmm5, %xmm5
addsd %xmm2, %xmm5
divsd %xmm5, %xmm10
ucomisd %xmm10, %xmm0
jbe 0x29524
movq %rbx, %rdi
movl %r14d, %esi
movsd %xmm12, 0x8(%rsp)
movsd %xmm13, (%rsp)
movsd %xmm10, 0x18(%rsp)
callq 0x281be
movsd 0x18(%rsp), %xmm10
xorpd %xmm11, %xmm11
movsd 0x10(%rsp), %xmm0
movl $0x1, %eax
movsd 0x8(%rsp), %xmm9
movsd (%rsp), %xmm1
addq $-0x10, %r15
decl %r14d
ucomisd %xmm10, %xmm0
movapd %xmm9, %xmm12
movapd %xmm1, %xmm13
jbe 0x293d4
movq 0x10(%rbx), %rdi
movsd 0x10(%rdi), %xmm12
movsd 0x18(%rdi), %xmm13
movsd (%rdi), %xmm10
movsd 0x8(%rdi), %xmm2
movslq 0x8(%rbx), %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
movsd -0x20(%rdi,%rdx), %xmm5
movsd -0x18(%rdi,%rdx), %xmm3
movapd %xmm5, %xmm1
subsd %xmm12, %xmm1
movapd %xmm10, %xmm4
subsd %xmm12, %xmm4
movapd %xmm3, %xmm7
subsd %xmm13, %xmm7
movapd %xmm2, %xmm6
subsd %xmm13, %xmm6
mulsd %xmm6, %xmm7
movapd %xmm1, %xmm8
mulsd %xmm4, %xmm8
addsd %xmm7, %xmm8
ucomisd %xmm8, %xmm11
jbe 0x295c1
mulsd %xmm6, %xmm6
mulsd %xmm4, %xmm4
addsd %xmm6, %xmm4
jmp 0x2964a
movapd %xmm13, %xmm6
subsd %xmm3, %xmm6
movapd %xmm12, %xmm8
subsd %xmm5, %xmm8
movapd %xmm10, %xmm4
subsd %xmm5, %xmm4
movapd %xmm2, %xmm7
subsd %xmm3, %xmm7
movapd %xmm6, %xmm9
mulsd %xmm7, %xmm9
mulsd %xmm4, %xmm8
addsd %xmm9, %xmm8
ucomisd %xmm8, %xmm11
jbe 0x2960e
mulsd %xmm7, %xmm7
mulsd %xmm4, %xmm4
addsd %xmm7, %xmm4
jmp 0x2964a
mulsd %xmm13, %xmm5
mulsd %xmm12, %xmm3
subsd %xmm5, %xmm3
mulsd %xmm1, %xmm2
mulsd %xmm6, %xmm10
addsd %xmm2, %xmm10
addsd %xmm3, %xmm10
mulsd %xmm10, %xmm10
mulsd %xmm1, %xmm1
mulsd %xmm6, %xmm6
addsd %xmm1, %xmm6
divsd %xmm6, %xmm10
movapd %xmm10, %xmm4
ucomisd %xmm4, %xmm0
jbe 0x296d9
cmpl $0x4, %ecx
jl 0x296be
leaq 0x10(%rdi), %rsi
movq 0x18(%rbx), %rdx
cmpq %rdx, %rsi
je 0x29693
subq %rsi, %rdx
movsd %xmm12, 0x8(%rsp)
movsd %xmm13, (%rsp)
callq 0x7690
movsd (%rsp), %xmm13
movsd 0x8(%rsp), %xmm12
xorpd %xmm11, %xmm11
movsd 0x10(%rsp), %xmm0
movq 0x18(%rbx), %rax
addq $-0x10, %rax
movq %rax, 0x18(%rbx)
subq 0x10(%rbx), %rax
shrq $0x4, %rax
movl %eax, 0x8(%rbx)
movl $0x1, 0x9c(%rbx)
movl $0x0, 0x90(%rbx)
movq 0x10(%rbx), %rax
movslq 0x8(%rbx), %rcx
shlq $0x4, %rcx
movupd (%rax), %xmm1
movupd %xmm1, -0x10(%rax,%rcx)
movl $0x1, %eax
testl %eax, %eax
jne 0x293b9
movl $0x1, 0x9c(%rbx)
movq %rbx, %rdi
callq 0x26926
movq %rbx, %rdi
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x27c90