// File: /workspace/github_cpp_makefile_star2_O3/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 %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, 0x8(%rsp)
movl 0x8(%rbx), %eax
cmpl $0x3, %eax
je 0x28e72
leal -0x2(%rax), %ecx
movq 0x10(%rbx), %rdi
shlq $0x4, %rcx
addq %rdi, %rcx
leal -0x1(%rax), %esi
decl %esi
testl %esi, %esi
jle 0x28cd4
movapd %xmm13, %xmm3
movapd %xmm12, %xmm1
movsd (%rcx), %xmm12
movsd 0x8(%rcx), %xmm13
movsd -0x10(%rcx), %xmm6
movsd -0x8(%rcx), %xmm5
movapd %xmm6, %xmm2
subsd %xmm1, %xmm2
movapd %xmm12, %xmm10
subsd %xmm1, %xmm10
movapd %xmm5, %xmm7
subsd %xmm3, %xmm7
movapd %xmm13, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm4, %xmm7
movapd %xmm2, %xmm8
mulsd %xmm10, %xmm8
addsd %xmm7, %xmm8
ucomisd %xmm8, %xmm11
jbe 0x28c15
mulsd %xmm4, %xmm4
mulsd %xmm10, %xmm10
addsd %xmm4, %xmm10
jmp 0x28ca4
movapd %xmm3, %xmm4
subsd %xmm5, %xmm4
movapd %xmm1, %xmm8
subsd %xmm6, %xmm8
movapd %xmm12, %xmm10
subsd %xmm6, %xmm10
movapd %xmm13, %xmm7
subsd %xmm5, %xmm7
movapd %xmm4, %xmm9
mulsd %xmm7, %xmm9
mulsd %xmm10, %xmm8
addsd %xmm9, %xmm8
ucomisd %xmm8, %xmm11
jbe 0x28c65
mulsd %xmm7, %xmm7
mulsd %xmm10, %xmm10
addsd %xmm7, %xmm10
jmp 0x28ca4
mulsd %xmm6, %xmm3
mulsd %xmm5, %xmm1
subsd %xmm3, %xmm1
movapd %xmm13, %xmm3
mulsd %xmm2, %xmm3
movapd %xmm4, %xmm10
mulsd %xmm12, %xmm10
addsd %xmm3, %xmm10
addsd %xmm1, %xmm10
mulsd %xmm10, %xmm10
mulsd %xmm2, %xmm2
mulsd %xmm4, %xmm4
addsd %xmm2, %xmm4
divsd %xmm4, %xmm10
addq $-0x10, %rcx
ucomisd %xmm10, %xmm0
jbe 0x28b9c
movq %rbx, %rdi
callq 0x27ba8
xorpd %xmm11, %xmm11
movsd 0x8(%rsp), %xmm0
movq 0x10(%rbx), %rdi
movl 0x8(%rbx), %eax
movl $0x1, %ecx
jmp 0x28cd6
xorl %ecx, %ecx
movsd 0x10(%rdi), %xmm12
movsd 0x18(%rdi), %xmm13
movsd (%rdi), %xmm10
movsd 0x8(%rdi), %xmm2
movslq %eax, %rdx
movq %rdx, %rsi
shlq $0x4, %rsi
movsd -0x20(%rdi,%rsi), %xmm5
movsd -0x18(%rdi,%rsi), %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 0x28d52
mulsd %xmm6, %xmm6
mulsd %xmm4, %xmm4
addsd %xmm6, %xmm4
jmp 0x28ddb
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 0x28d9f
mulsd %xmm7, %xmm7
mulsd %xmm4, %xmm4
addsd %xmm7, %xmm4
jmp 0x28ddb
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 0x28e6a
cmpl $0x4, %eax
jl 0x28e57
leaq 0x10(%rdi), %rsi
movq 0x18(%rbx), %rdx
cmpq %rdx, %rsi
je 0x28e2e
subq %rsi, %rdx
movsd %xmm12, 0x18(%rsp)
movsd %xmm13, 0x10(%rsp)
callq 0x76a0
movsd 0x10(%rsp), %xmm13
movsd 0x18(%rsp), %xmm12
xorpd %xmm11, %xmm11
movsd 0x8(%rsp), %xmm0
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rdx
addq $-0x10, %rdx
movq %rdx, 0x18(%rbx)
subq %rdi, %rdx
shrq $0x4, %rdx
movl %edx, 0x8(%rbx)
movl $0x1, 0x9c(%rbx)
movl $0x0, 0x90(%rbx)
movslq %edx, %rdx
shlq $0x4, %rdx
movupd (%rdi), %xmm1
movupd %xmm1, -0x10(%rdi,%rdx)
movl $0x1, %ecx
testl %ecx, %ecx
jne 0x28b7f
movl $0x1, 0x9c(%rbx)
movq %rbx, %rdi
callq 0x266bc
movq %rbx, %rdi
addq $0x20, %rsp
popq %rbx
jmp 0x276c8
nop