segment.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2019, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_SEGMENT_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_SEGMENT_HPP
  9. #include <boost/core/ignore_unused.hpp>
  10. #include <boost/geometry/core/point_type.hpp>
  11. #include <boost/geometry/core/tags.hpp>
  12. #include <boost/geometry/algorithms/assign.hpp>
  13. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  14. #include <boost/geometry/algorithms/detail/equals/point_point.hpp>
  15. #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
  16. #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DISPATCH
  20. namespace dispatch
  21. {
  22. // A segment is a curve.
  23. // A curve is simple if it does not pass through the same point twice,
  24. // with the possible exception of its two endpoints
  25. // A curve is 1-dimensional, hence we have to check is the two
  26. // endpoints of the segment coincide, since in this case it is
  27. // 0-dimensional.
  28. //
  29. // Reference: OGC 06-103r4 (6.1.6.1)
  30. template <typename Segment>
  31. struct is_valid<Segment, segment_tag>
  32. {
  33. template <typename VisitPolicy, typename Strategy>
  34. static inline bool apply(Segment const& segment, VisitPolicy& visitor, Strategy const&)
  35. {
  36. typedef typename Strategy::equals_point_point_strategy_type eq_pp_strategy_type;
  37. boost::ignore_unused(visitor);
  38. typename point_type<Segment>::type p[2];
  39. detail::assign_point_from_index<0>(segment, p[0]);
  40. detail::assign_point_from_index<1>(segment, p[1]);
  41. if (detail::is_valid::has_invalid_coordinate
  42. <
  43. Segment
  44. >::apply(segment, visitor))
  45. {
  46. return false;
  47. }
  48. else if (! geometry::detail::equals::equals_point_point(
  49. p[0], p[1], eq_pp_strategy_type()))
  50. {
  51. return visitor.template apply<no_failure>();
  52. }
  53. else
  54. {
  55. return
  56. visitor.template apply<failure_wrong_topological_dimension>();
  57. }
  58. }
  59. };
  60. } // namespace dispatch
  61. #endif // DOXYGEN_NO_DISPATCH
  62. }} // namespace boost::geometry
  63. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_SEGMENT_HPP