segment.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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& strategy)
  35. {
  36. boost::ignore_unused(visitor);
  37. typename point_type<Segment>::type p[2];
  38. detail::assign_point_from_index<0>(segment, p[0]);
  39. detail::assign_point_from_index<1>(segment, p[1]);
  40. if (detail::is_valid::has_invalid_coordinate
  41. <
  42. Segment
  43. >::apply(segment, visitor))
  44. {
  45. return false;
  46. }
  47. else if (! detail::equals::equals_point_point(p[0], p[1], strategy))
  48. {
  49. return visitor.template apply<no_failure>();
  50. }
  51. else
  52. {
  53. return
  54. visitor.template apply<failure_wrong_topological_dimension>();
  55. }
  56. }
  57. };
  58. } // namespace dispatch
  59. #endif // DOXYGEN_NO_DISPATCH
  60. }} // namespace boost::geometry
  61. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_SEGMENT_HPP