// File: thierry7100[P]CutOptim/src/SvgDoc.cpp
// Function: SvgDoc::SimplifyPath(NSVGpath*, double)
void SvgDoc::SimplifyPath(NSVGpath *path, double max_error)
{
NSVGPathElt *Elt, *Elt2, *oldElt = NULL;
float x, y;
float xmin, xmax, ymin, ymax;

    //  Now walk through all path elements to delete vertices if they are aligned
    x = path->StartX;
    y = path->StartY;
    xmin = x;
    xmax = x;
    ymin = y;
    ymax = y;
    Elt = path->PathElts;
    while ( Elt != NULL )
    {
        Elt2 = Elt->next;
        if ( Elt2 != NULL )
        {
            //  Build segment x,y --> Elt2->EndX, EndY
            //  Compute parameters of the line segment between Start and End
            double b = Elt2->EndX - x;
            double a = y - Elt2->EndY;
            double c = x * Elt2->EndY - Elt2->EndX*y;
            //  Compute distance between Elt->EndX, EndY and the segment
            // Distance between point and line is (a * p.x + b * p.y + c)*(a * p.x + b * p.y + c)/(a*a + b*b)
            double d1 = a * Elt->EndX + b * Elt->EndY + c;
            d1 *= d1;
            d1 /= a*a + b*b;
            if ( d1 < max_error )
            {
                //  remove Elt
                if ( oldElt == NULL)
                    path->PathElts = Elt2;
                else
                    oldElt->next = Elt2;
                path->nElts--;
                Elt = Elt2;
                continue;
            }
            else
            {
                x = Elt->EndX;
                y = Elt->EndY;
                xmin = fmin(xmin, x);
                xmax = fmax(xmax, x);
                ymin = fmin(ymin, y);
                ymax = fmax(ymax, y);
                //  Then next element
                oldElt = Elt;
                Elt = Elt2;
                continue;
            }
        }
        break;
    }
    path->PolyLine->bounds[0] = xmin;
    path->PolyLine->bounds[1] = ymin;
    path->PolyLine->bounds[2] = xmax;
    path->PolyLine->bounds[3] = ymax;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x3c(%rbp)
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x38(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x38(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x69321
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6931f
movq -0x28(%rbp), %rax
movsd 0x8(%rax), %xmm0
movss -0x34(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x28(%rbp), %rax
subsd 0x10(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x28(%rbp), %rax
movsd 0x10(%rax), %xmm2
movq -0x28(%rbp), %rax
movsd 0x8(%rax), %xmm1
movss -0x38(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd 0x8(%rax), %xmm2
movsd -0x50(%rbp), %xmm1
movq -0x20(%rbp), %rax
mulsd 0x10(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
mulsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x58(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
movsd -0x50(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x69296
cmpq $0x0, -0x30(%rbp)
jne 0x69270
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x6927c
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x69144
movq -0x20(%rbp), %rax
movsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x20(%rbp), %rax
movsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x3c(%rbp), %xmm0
movss -0x34(%rbp), %xmm1
callq 0x7fbf0
movss %xmm0, -0x3c(%rbp)
movss -0x40(%rbp), %xmm0
movss -0x34(%rbp), %xmm1
callq 0x7fc30
movss %xmm0, -0x40(%rbp)
movss -0x44(%rbp), %xmm0
movss -0x38(%rbp), %xmm1
callq 0x7fbf0
movss %xmm0, -0x44(%rbp)
movss -0x48(%rbp), %xmm0
movss -0x38(%rbp), %xmm1
callq 0x7fc30
movss %xmm0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x69144
jmp 0x69321
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movsd %xmm0, 0x28(%rax)
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movsd %xmm0, 0x30(%rax)
movss -0x40(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movsd %xmm0, 0x38(%rax)
movss -0x48(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movsd %xmm0, 0x40(%rax)
addq $0x70, %rsp
popq %rbp
retq
nop