Opened 6 years ago

Last modified 6 years ago

#12663 new Support Requests

geometry::equals fails when points differ by small value

Reported by: anonymous Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.61.0 Severity: Problem
Keywords: equals Cc:

Description

It seems the geometry::equals function is very strict when dealing w/ floating point precision. I have 2 polygons that are the same except for one point (15.0, 10.0) vs (14.9999999999, 10.0), but geometry::equals returns false. I don't know if this is a bug or the expected behavior. What is the tolerance and is there a way to specify it?

bg_polygon polygon1; boost::geometry::read_wkt("POLYGON((10.0 10.0, 10.0 20.0, 15.0 20.0, 14.9999999999 10.0, 10.0 10.0))", polygon1);

bg_polygon polygon2; boost::geometry::read_wkt("POLYGON((10.0 10.0, 10.0 20.0, 15.0 20.0, 15.0 10.0, 10.0 10.0))", polygon2);

boost::geometry::equals(polygon1, polygon2); --> returns false

Change History (1)

comment:1 by awulkiew, 6 years ago

Type: BugsSupport Requests

Yes, this is expected. Points are compared WRT machine epsilon scaled by the greater coordinate absolute value. Currently it's not possible to pass user-defined epsilon value into algorithms which could be used in Point comparisons. It'd be possible to implement custom coordinate type with comparison operator using greater epsilon but this way this comparison method would be used in every case, not only when Points were compared.

Note: See TracTickets for help on using tickets.