Opened 8 years ago

Closed 8 years ago

#11121 closed Bugs (fixed)

Invalid result of difference() for integral coordinates.

Reported by: awulkiew Owned by: Barend Gehrels
Milestone: Boost 1.58.0 Component: geometry
Version: Boost Development Trunk Severity: Problem
Keywords: difference, integral, setops, get_turns Cc: mkaravel

Description

For polygons:

green = "POLYGON((-8042 -1485,-8042 250,-8042 250,15943 254,15943 -1485,-8042 -1485))",
blue = "POLYGON((-7901 -1485,-7901 529,-7901 529, 15802 544, 15802 -1485, -7901 -1485))"

The result of difference(green, blue) and/or difference(blue, green) is invalid if the polygons use int coordinate type.

I think it may be related to get_turns/cart_intersect and ratios/fractions but it needs further investigation. I noticed that turns has wrong coordinates, always endpoints of segments are picked as if internally ratios were always truncated to 0.

Change History (1)

comment:1 by mkaravel, 8 years ago

Cc: mkaravel added
Milestone: To Be DeterminedBoost 1.58.0
Resolution: fixed
Status: newclosed

The problem was in the computation of the intersection points. In particular, integer overflow was taking place, yielding the wrong results.

The problem has been fixed by locally promoting the coordinates to a number type with increased precision, thus avoiding the overflow.

See also tickets #10835 and #10658.

Note: See TracTickets for help on using tickets.