// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
movslq 0x8(%rdi), %rax
movq 0x10(%rdi), %rcx
shlq $0x4, %rax
movupd -0x10(%rcx,%rax), %xmm0
leaq 0x10(%rsp), %rax
movapd %xmm0, (%rax)
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %r15
movapd %xmm0, (%r15)
leaq 0x30(%rsp), %r12
movapd %xmm0, (%r12)
pushq $0x1
popq %rbp
leaq 0x40(%rsp), %r13
testl %ebp, %ebp
je 0x23f9f
movl 0x8(%rbx), %r14d
cmpl $0x3, %r14d
je 0x23f9f
addl $-0x2, %r14d
movq %r14, %rbp
shlq $0x4, %rbp
testl %r14d, %r14d
jle 0x23f11
movq 0x10(%rbx), %rax
movups (%rax,%rbp), %xmm0
movaps %xmm0, 0x20(%rsp)
movupd -0x10(%rax,%rbp), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x24340
movq %r13, %rdi
movq %r15, %rsi
callq 0x24a0c
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x23f15
movapd 0x20(%rsp), %xmm0
movapd %xmm0, 0x10(%rsp)
addq $-0x10, %rbp
decl %r14d
jmp 0x23eb7
xorl %ebp, %ebp
jmp 0x23f23
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2324a
pushq $0x1
popq %rbp
movq 0x10(%rbx), %rax
movups 0x10(%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x20(%rsp)
movslq 0x8(%rbx), %rcx
shlq $0x4, %rcx
movupd -0x20(%rax,%rcx), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x24340
movq %r13, %rdi
movq %r15, %rsi
callq 0x24a0c
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x23e96
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2324a
movq 0x10(%rbx), %rax
movslq 0x8(%rbx), %rcx
shlq $0x4, %rcx
movupd (%rax), %xmm0
movupd %xmm0, -0x10(%rax,%rcx)
pushq $0x1
popq %rbp
jmp 0x23e96
movq %rbx, %rdi
callq 0x2328a
movq %rbx, %rdi
callq 0x22da8
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop