diff --git a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp index 5064b8d15..3861968e5 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp @@ -65,6 +65,23 @@ private: public: + struct disjoint_info + { + enum type + { + intersect, + disjoint_no_vertex, + disjoint_vertex + }; + disjoint_info(type t) : t_(t){} + operator type () const {return t_;} + type t_; + private : + //prevent automatic conversion for any other built-in types + template + operator T () const; + }; + template static inline bool apply(Segment const& segment, Box const& box, @@ -72,17 +89,14 @@ public: { typedef typename point_type::type segment_point; segment_point vertex; - return (apply(segment, box, azimuth_strategy, vertex) > 0); + return (apply(segment, box, azimuth_strategy, vertex) != disjoint_info::intersect); } - // returns 0 if intersect, - // 1 if disjoint (vertex not computed), - // 2 if disjoint (vertex computed) template - static inline std::size_t apply(Segment const& segment, - Box const& box, - Strategy const& azimuth_strategy, - P& vertex) + static inline disjoint_info apply(Segment const& segment, + Box const& box, + Strategy const& azimuth_strategy, + P& vertex) { assert_dimension_equal(); @@ -93,14 +107,15 @@ public: geometry::detail::assign_point_from_index<0>(segment, p0); geometry::detail::assign_point_from_index<1>(segment, p1); - std::size_t disjoint_return_value = 1; //vertex not computed here + //vertex not computed here + disjoint_info disjoint_return_value = disjoint_info::disjoint_no_vertex; // Simplest cases first // Case 1: if box contains one of segment's endpoints then they are not disjoint if (! disjoint_point_box(p0, box) || ! disjoint_point_box(p1, box)) { - return 0; + return disjoint_info::intersect; } // Case 2: disjoint if bounding boxes are disjoint @@ -163,7 +178,7 @@ public: if (!(b0 && b1 && b2 && b3) && (b0 || b1 || b2 || b3)) { - return 0; + return disjoint_info::intersect; } // Case 4: The only intersection case not covered above is when all four @@ -198,7 +213,7 @@ public: geometry::set_from_radian<0>(vertex, vertex_lon); geometry::set_from_radian<1>(vertex, vertex_lat); - disjoint_return_value = 2; //vertex_computed + disjoint_return_value = disjoint_info::disjoint_vertex; //vertex_computed // Check if the vertex point is within the band defined by the // minimum and maximum longitude of the box; if yes, then return @@ -207,7 +222,7 @@ public: if (vertex_lon >= b_lon_min && vertex_lon <= b_lon_max && std::abs(vertex_lat) > std::abs(b_lat_below)) { - return 0; + return disjoint_info::intersect; } } diff --git a/include/boost/geometry/strategies/spherical/segment_below_of_box.hpp b/include/boost/geometry/strategies/spherical/segment_below_of_box.hpp index 2f144030e..031cbc402 100644 --- a/include/boost/geometry/strategies/spherical/segment_below_of_box.hpp +++ b/include/boost/geometry/strategies/spherical/segment_below_of_box.hpp @@ -52,16 +52,19 @@ struct spherical_or_geographic typedef typename cs_tag::type segment_cs_type; SegmentPoint p_max; - std::size_t disjoint_result = - geometry::detail::disjoint:: - disjoint_segment_box_sphere_or_spheroid:: + typedef geometry::detail::disjoint:: + disjoint_segment_box_sphere_or_spheroid disjoint_sb; + typedef typename disjoint_sb::disjoint_info disjoint_info_type; + + disjoint_info_type disjoint_result = disjoint_sb:: apply(seg, input_box, ps_strategy.get_azimuth_strategy(), p_max); - if (disjoint_result == 0) //intersect + if (disjoint_result == disjoint_info_type::intersect) //intersect { return 0; } - if (disjoint_result == 1) // disjoint but vertex not computed + // disjoint but vertex not computed + if (disjoint_result == disjoint_info_type::disjoint_no_vertex) { typedef typename coordinate_type::type CT; geometry::model::box mbr; @@ -92,13 +95,13 @@ struct spherical_or_geographic geometry::set_from_radian<0>(p_max, vertex_lon); geometry::set_from_radian<1>(p_max, vertex_lat); } - //otherwise disjoint_result == 2 - //i.e. disjoint and vertex computed inside disjoint + //otherwise disjoint and vertex computed inside disjoint if (less_equal(geometry::get_as_radian<0>(bottom_left), geometry::get_as_radian<0>(p_max))) { - result = boost::numeric_cast(ps_strategy.apply(bottom_left, p0, p1)); + result = boost::numeric_cast(ps_strategy.apply(bottom_left, + p0, p1)); } else {