From eb7613e703f4bbb4cca37f00610695600f25e8df Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 6 Oct 2015 13:58:18 -0700 Subject: [PATCH] [algorithms][intersection] Fixes liang_barsky for integer coordinate types - Fixes an integer division bug which caused incorrect clipping results when a geometry is clipped by a box and the coordinate type is integral - Refs https://github.com/mapbox/mapnik-vector-tile/pull/102 --- .../algorithms/detail/overlay/clip_linestring.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp b/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp index b1a25c9f5..8d2a398ad 100644 --- a/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp @@ -51,14 +51,14 @@ class liang_barsky private: typedef model::referring_segment segment_type; - template - inline bool check_edge(T const& p, T const& q, T& t1, T& t2) const + template + inline bool check_edge(PointType const& p, PointType const& q, CalcType& t1, CalcType& t2) const { bool visible = true; if(p < 0) { - T const r = q / p; + CalcType const r = static_cast(q) / p; if (r > t2) visible = false; else if (r > t1) @@ -66,7 +66,7 @@ private: } else if(p > 0) { - T const r = q / p; + CalcType const r = static_cast(q) / p; if (r < t1) visible = false; else if (r < t2) @@ -86,9 +86,10 @@ public: inline bool clip_segment(Box const& b, segment_type& s, bool& sp1_clipped, bool& sp2_clipped) const { typedef typename select_coordinate_type::type coordinate_type; + typedef double calc_type; - coordinate_type t1 = 0; - coordinate_type t2 = 1; + calc_type t1 = 0; + calc_type t2 = 1; coordinate_type const dx = get<1, 0>(s) - get<0, 0>(s); coordinate_type const dy = get<1, 1>(s) - get<0, 1>(s);