geometry icon indicating copy to clipboard operation
geometry copied to clipboard

centroid overflow for multipoint with integer coords

Open woodroof opened this issue 7 years ago • 3 comments

centroid just sums all points and divide result on point count, but it should use "extended" type. Example: {{x = 989466522, y = 789595328}, {x = 989472652, y = 789598701}, {x = 989481089, y = 789595346}, {x = 989484158, y = 789593666}, {x = 989484932, y = 789586937}, {x = 989482640, y = 789580203}, {x = 989478814, y = 789574309}, {x = 989471911, y = 789576825}, {x = 989466522, y = 789595328}} Result: {x = 315354648, y = -1483637949} Expected result: {x = 989476582, y = 789588516}

woodroof avatar Oct 02 '18 04:10 woodroof

Or at least library should provide a way to set ExtendedType in BOOST_GEOMETRY_REGISTER_POINT_2D and other macro.

woodroof avatar Oct 14 '18 16:10 woodroof

Hi, actually it is possible to specify the CalculationType used in centroid() algorithm. You can do this by passing a strategy explicitly however only the strategy for areal geometries like polygons supports this. There is another way however. I think if you defined another point type for the output point using bigger coordinate type or simply used simply bg::model::point<> with greater coordinate type than your "typical" geometry as temporary then this type would be used internally in centroid().

awulkiew avatar Dec 03 '18 19:12 awulkiew

I can do as you suggest but it means additional convertion to another geometry type. It's actually worse than writing my own function for centroid calculation. I think this should be handled in library as user (as I am) may be surprised by unexpected behaviour.

woodroof avatar Dec 05 '18 07:12 woodroof