// File: /workspace/github_cpp_makefile_star2_O1/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:
cvtsd2ss (%rsi), %xmm2
cvtsd2ss 0x8(%rsi), %xmm1
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x2d1f3
movq 0x38(%rcx), %r8
testq %r8, %r8
je 0x2d1f3
leaq 0x10(%rsi), %rax
xorl %edi, %edi
movaps %xmm2, %xmm3
movaps %xmm1, %xmm4
movaps %xmm1, %xmm5
movaps %xmm2, %xmm6
movq %r8, %rdx
xorps %xmm9, %xmm9
cvtss2sd %xmm6, %xmm9
movsd 0x8(%r8), %xmm10
movsd 0x10(%r8), %xmm7
xorps %xmm8, %xmm8
cvtss2sd %xmm5, %xmm8
movaps %xmm8, %xmm11
subsd %xmm7, %xmm11
mulsd %xmm10, %xmm8
subsd %xmm9, %xmm10
mulsd %xmm7, %xmm9
subsd %xmm8, %xmm9
movsd 0x8(%rcx), %xmm7
movsd 0x10(%rcx), %xmm8
movapd %xmm10, %xmm12
mulsd %xmm8, %xmm12
movapd %xmm11, %xmm13
mulsd %xmm7, %xmm13
addsd %xmm12, %xmm13
addsd %xmm9, %xmm13
mulsd %xmm13, %xmm13
mulsd %xmm10, %xmm10
mulsd %xmm11, %xmm11
addsd %xmm10, %xmm11
divsd %xmm11, %xmm13
ucomisd %xmm13, %xmm0
jbe 0x2d163
leaq 0x38(%rdi), %rcx
testq %rdi, %rdi
cmoveq %rax, %rcx
movq %rdx, (%rcx)
decl 0x18(%rsi)
jmp 0x2d1e1
xorps %xmm6, %xmm6
cvtsd2ss %xmm7, %xmm6
xorps %xmm5, %xmm5
cvtsd2ss %xmm8, %xmm5
movaps %xmm6, %xmm7
minss %xmm2, %xmm7
cmpunordss %xmm2, %xmm2
movaps %xmm2, %xmm8
andps %xmm6, %xmm8
andnps %xmm7, %xmm2
orps %xmm8, %xmm2
movaps %xmm6, %xmm7
maxss %xmm3, %xmm7
cmpunordss %xmm3, %xmm3
movaps %xmm3, %xmm8
andps %xmm6, %xmm8
andnps %xmm7, %xmm3
orps %xmm8, %xmm3
movaps %xmm5, %xmm7
minss %xmm1, %xmm7
cmpunordss %xmm1, %xmm1
movaps %xmm1, %xmm8
andps %xmm5, %xmm8
andnps %xmm7, %xmm1
orps %xmm8, %xmm1
movaps %xmm5, %xmm7
maxss %xmm4, %xmm7
cmpunordss %xmm4, %xmm4
movaps %xmm4, %xmm8
andps %xmm5, %xmm8
andnps %xmm7, %xmm4
orps %xmm8, %xmm4
movq %rcx, %rdi
movq 0x38(%rdx), %r8
movq %rdx, %rcx
testq %r8, %r8
jne 0x2d0c9
jmp 0x2d1f9
movaps %xmm2, %xmm3
movaps %xmm1, %xmm4
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movq 0x50(%rsi), %rax
movsd %xmm0, 0x28(%rax)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x30(%rax)
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
movsd %xmm0, 0x38(%rax)
xorps %xmm0, %xmm0
cvtss2sd %xmm4, %xmm0
movsd %xmm0, 0x40(%rax)
retq