pointlike.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
  3. // Copyright (c) 2014-2020, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Licensed under the Boost Software License version 1.0.
  7. // http://www.boost.org/users/license.html
  8. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP
  9. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP
  10. #include <boost/core/ignore_unused.hpp>
  11. #include <boost/range/empty.hpp>
  12. #include <boost/geometry/core/tags.hpp>
  13. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  14. #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
  15. #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
  16. #include <boost/geometry/util/constexpr.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DISPATCH
  20. namespace dispatch
  21. {
  22. // A point is always simple
  23. template <typename Point>
  24. struct is_valid<Point, point_tag>
  25. {
  26. template <typename VisitPolicy, typename Strategy>
  27. static inline bool apply(Point const& point, VisitPolicy& visitor, Strategy const&)
  28. {
  29. boost::ignore_unused(visitor);
  30. return ! detail::is_valid::has_invalid_coordinate
  31. <
  32. Point
  33. >::apply(point, visitor);
  34. }
  35. };
  36. // A MultiPoint is simple if no two Points in the MultiPoint are equal
  37. // (have identical coordinate values in X and Y)
  38. //
  39. // Reference: OGC 06-103r4 (6.1.5)
  40. template <typename MultiPoint, bool AllowEmptyMultiGeometries>
  41. struct is_valid<MultiPoint, multi_point_tag, AllowEmptyMultiGeometries>
  42. {
  43. template <typename VisitPolicy, typename Strategy>
  44. static inline bool apply(MultiPoint const& multipoint,
  45. VisitPolicy& visitor,
  46. Strategy const&)
  47. {
  48. boost::ignore_unused(multipoint, visitor);
  49. if BOOST_GEOMETRY_CONSTEXPR (! AllowEmptyMultiGeometries)
  50. {
  51. if (boost::empty(multipoint))
  52. {
  53. // we do not allow an empty multipoint
  54. return visitor.template apply<failure_few_points>();
  55. }
  56. }
  57. // if we allow empty multi-geometries, an empty multipoint
  58. // is considered valid
  59. return ! detail::is_valid::has_invalid_coordinate
  60. <
  61. MultiPoint
  62. >::apply(multipoint, visitor);
  63. }
  64. };
  65. } // namespace dispatch
  66. #endif // DOXYGEN_NO_DISPATCH
  67. }} // namespace boost::geometry
  68. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP