pointlike.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2017, 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_POINTLIKE_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP
  9. #include <boost/core/ignore_unused.hpp>
  10. #include <boost/range.hpp>
  11. #include <boost/geometry/core/tags.hpp>
  12. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  13. #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
  14. #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
  15. #include <boost/geometry/util/condition.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. #ifndef DOXYGEN_NO_DISPATCH
  19. namespace dispatch
  20. {
  21. // A point is always simple
  22. template <typename Point>
  23. struct is_valid<Point, point_tag>
  24. {
  25. template <typename VisitPolicy, typename Strategy>
  26. static inline bool apply(Point const& point, VisitPolicy& visitor, Strategy const&)
  27. {
  28. boost::ignore_unused(visitor);
  29. return ! detail::is_valid::has_invalid_coordinate
  30. <
  31. Point
  32. >::apply(point, visitor);
  33. }
  34. };
  35. // A MultiPoint is simple if no two Points in the MultiPoint are equal
  36. // (have identical coordinate values in X and Y)
  37. //
  38. // Reference: OGC 06-103r4 (6.1.5)
  39. template <typename MultiPoint, bool AllowEmptyMultiGeometries>
  40. struct is_valid<MultiPoint, multi_point_tag, AllowEmptyMultiGeometries>
  41. {
  42. template <typename VisitPolicy, typename Strategy>
  43. static inline bool apply(MultiPoint const& multipoint,
  44. VisitPolicy& visitor,
  45. Strategy const&)
  46. {
  47. boost::ignore_unused(multipoint, visitor);
  48. if (BOOST_GEOMETRY_CONDITION(
  49. AllowEmptyMultiGeometries || !boost::empty(multipoint)))
  50. {
  51. // we allow empty multi-geometries, so an empty multipoint
  52. // is considered valid
  53. return ! detail::is_valid::has_invalid_coordinate
  54. <
  55. MultiPoint
  56. >::apply(multipoint, visitor);
  57. }
  58. else
  59. {
  60. // we do not allow an empty multipoint
  61. return visitor.template apply<failure_few_points>();
  62. }
  63. }
  64. };
  65. } // namespace dispatch
  66. #endif // DOXYGEN_NO_DISPATCH
  67. }} // namespace boost::geometry
  68. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP