Menu

#198 Clipping polygons create wrong intersection point

*
open
nobody
1
2020-01-10
2020-01-10
Anonymous
No

Hi!
While using the clipper library I came across the following error.
Polygon1 (subject):

List<Point64> subject = new List<Point64>(){
new Point64(904675703125944,266633074088286),
new Point64(907075816879187,236703904344869),
new Point64(5338151409674252,236703904344868),
new Point64(5340549400729718,266633374812947),
new Point64(904675703125944,266633074088286),
}

Polygon2 (clip):

List<Point64> clip = new List<Point64>(){
new Point64(5331548017402586,234065076438205),
new Point64(913614980252469,234065076438206),
new Point64(913614980252469,236703904344869),
new Point64(5331564749816380,236703904344868),
new Point64(5331548017402586,234065076438205),
}

The polygons are clipped using the following code:

clipper.AddPaths(subject, PolyType.ptSubject); //Add subject
clipper.AddPaths(clip, PolyType.ptClip); //Add clipper
 bool exec = clipper.Execute(ClipType.ctDifference, result,
                PolyFillType.pftNonZero, PolyFillType.pftNonZero); 

This results in the following 5 points:

{IntPoint}
    X: 5338151409674252
    Y: 236703904344868
{IntPoint}
    X: 5340549400729718
    Y: 266633374812947
{IntPoint}
    X: 904675703125944
    Y: 266633074088286
{IntPoint}
    X: 907075816879187
    Y: 236703904344869
{IntPoint} // This last point have an X value that is completely wrong..
    X: -562949953421312
    Y: 236703904344869

In the IntersectPoint() function, it seems a check is performed, for the calculated Y value, to see if it goes outside the scope of the edges, however no checks are performed on the calculated X value?
In this particular example, the approximate form that is used to descripe Y is the same for the line, whether X is 0 or 907.075.816.879.187, which means checking only Y does not guarentee that the result is correct.

I have not spent much time looking through the clipper library, so I am reluctant to just implement some quickfix myself, as I don't feel confident enough that I can guarentee it won't break some other clipping scenario - so i am turning to you guys for help!

Best regards!

Discussion

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB