// File: thierry7100[P]CutOptim/src/Geometry.cpp
// Function: Polygon::Intersect(Polygon*)
bool Polygon::Intersect(Polygon *Poly2)
{
Segment *pSeg2;
bool ShareSegment = false;      //  If true, one segment is included in another

    for ( int i = 0; i < Poly2->nVertices - 1; i++)
    {
        pSeg2 = &Poly2->_Segments[i];
        if ( pSeg2->xM <= BoundingBox.A.x ) continue;           //  Segment couldn't cross, right from polygon 1
        if ( pSeg2->xm >= BoundingBox.B.x ) continue;           //  Segment couldn't cross, left from polygon 1
        if ( pSeg2->yM <= BoundingBox.A.y ) continue;           //  Segment couldn't cross, below from polygon 1
        if ( pSeg2->ym >= BoundingBox.B.y ) continue;           //  Segment couldn't cross, above from polygon 1
        //  Possible, so check with all edges of polygon 1
        for ( int j = 0; j < nVertices - 1; j++)
        {
            if ( _Segments[j].isCrossingNoEnd(pSeg2, NULL, &ShareSegment) ) //  Cross return true
                return true;
            //  If lines are parallel checks for inclusion, at least partial
            if ( ShareSegment )
            {
                Point ptA1 = pSeg2->getPointA();
                Point ptB1 = pSeg2->getPointB();
                Point ptA2 = _Segments[j].getPointA();
                Point ptB2 = _Segments[j].getPointB();
                if ( _Segments[j].InSegmentNoEnd(ptA1) )
                {
                    //cout << "Shared point A of " << *pSeg2 << " in " << _Segments[j] << " with same rotation side\n";
                    return true;
                }
                if ( _Segments[j].InSegmentNoEnd(ptB1) )
                {
                    //cout << "Shared point B of " << *pSeg2 << " in " << _Segments[j] << " with same rotation side\n";
                    return true;
                }
                if ( pSeg2->InSegmentNoEnd(ptA2) )
                {
                    //cout << "Shared point A of " << _Segments[j] << " in " <<  pSeg2 << " with same rotation side\n";
                    return true;
                }
                if ( pSeg2->InSegmentNoEnd(ptB2) )
                {
                    //cout << "Shared point B of " << _Segments[j] << " in " <<  pSeg2 << " with same rotation side\n";
                    return true;
                }
            }
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movb $0x0, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x62c86
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
movslq -0x28(%rbp), %rsi
callq 0x64810
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movsd 0x40(%rcx), %xmm1
movsd 0x58(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x62ad0
jmp 0x62c78
movq -0x78(%rbp), %rax
movq -0x20(%rbp), %rcx
movsd 0x38(%rcx), %xmm0
ucomisd 0x68(%rax), %xmm0
jb 0x62ae9
jmp 0x62c78
movq -0x78(%rbp), %rax
movq -0x20(%rbp), %rcx
movsd 0x50(%rcx), %xmm1
movsd 0x60(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x62b06
jmp 0x62c78
movq -0x78(%rbp), %rax
movq -0x20(%rbp), %rcx
movsd 0x48(%rcx), %xmm0
ucomisd 0x70(%rax), %xmm0
jb 0x62b1f
jmp 0x62c78
movl $0x0, -0x2c(%rbp)
movq -0x78(%rbp), %rcx
movl -0x2c(%rbp), %eax
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x62c76
movq -0x78(%rbp), %rdi
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x64810
movq %rax, %rdi
movq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x21(%rbp), %rcx
callq 0x64830
cmpl $0x0, %eax
je 0x62b6e
movb $0x1, -0x1(%rbp)
jmp 0x62c8a
testb $0x1, -0x21(%rbp)
je 0x62c66
movq -0x20(%rbp), %rdi
callq 0x64940
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x64980
movq -0x78(%rbp), %rdi
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x48(%rbp)
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x64810
movq %rax, %rdi
callq 0x64940
movq -0x78(%rbp), %rdi
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x64810
movq %rax, %rdi
callq 0x64980
movq -0x78(%rbp), %rdi
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x68(%rbp)
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x64810
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x649c0
cmpl $0x0, %eax
je 0x62c0c
movb $0x1, -0x1(%rbp)
jmp 0x62c8a
movq -0x78(%rbp), %rdi
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x64810
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0x649c0
cmpl $0x0, %eax
je 0x62c34
movb $0x1, -0x1(%rbp)
jmp 0x62c8a
movq -0x20(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x649c0
cmpl $0x0, %eax
je 0x62c4c
movb $0x1, -0x1(%rbp)
jmp 0x62c8a
movq -0x20(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x649c0
cmpl $0x0, %eax
je 0x62c64
movb $0x1, -0x1(%rbp)
jmp 0x62c8a
jmp 0x62c66
jmp 0x62c68
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x62b26
jmp 0x62c78
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x62a86
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)