buffer_point_square.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP
  8. #include <cstddef>
  9. #include <boost/range.hpp>
  10. #include <boost/geometry/util/math.hpp>
  11. #include <boost/geometry/strategies/buffer.hpp>
  12. namespace boost { namespace geometry
  13. {
  14. namespace strategy { namespace buffer
  15. {
  16. /*!
  17. \brief Create a squared form buffer around a point
  18. \ingroup strategies
  19. \details This strategy can be used as PointStrategy for the buffer algorithm.
  20. It creates a square from each point, where the point lies in the center.
  21. It can be applied for points and multi_points, but also for a linestring (if it is degenerate,
  22. so consisting of only one point) and for polygons (if it is degenerate).
  23. This strategy is only applicable for Cartesian coordinate systems.
  24. \qbk{
  25. [heading Example]
  26. [buffer_point_square]
  27. [heading Output]
  28. [$img/strategies/buffer_point_square.png]
  29. [heading See also]
  30. \* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
  31. \* [link geometry.reference.strategies.strategy_buffer_point_circle point_circle]
  32. }
  33. */
  34. class point_square
  35. {
  36. template
  37. <
  38. typename Point,
  39. typename DistanceType,
  40. typename OutputRange
  41. >
  42. inline void add_point(Point const& point,
  43. DistanceType const& distance,
  44. DistanceType const& x,
  45. DistanceType const& y,
  46. OutputRange& output_range) const
  47. {
  48. typename boost::range_value<OutputRange>::type p;
  49. set<0>(p, get<0>(point) + x * distance);
  50. set<1>(p, get<1>(point) + y * distance);
  51. output_range.push_back(p);
  52. }
  53. template
  54. <
  55. typename Point,
  56. typename DistanceType,
  57. typename OutputRange
  58. >
  59. inline void add_points(Point const& point,
  60. DistanceType const& distance,
  61. OutputRange& output_range) const
  62. {
  63. add_point(point, distance, -1.0, -1.0, output_range);
  64. add_point(point, distance, -1.0, +1.0, output_range);
  65. add_point(point, distance, +1.0, +1.0, output_range);
  66. add_point(point, distance, +1.0, -1.0, output_range);
  67. // Close it:
  68. output_range.push_back(output_range.front());
  69. }
  70. public :
  71. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  72. //! Fills output_range with a square around point using distance_strategy
  73. template
  74. <
  75. typename Point,
  76. typename DistanceStrategy,
  77. typename OutputRange
  78. >
  79. inline void apply(Point const& point,
  80. DistanceStrategy const& distance_strategy,
  81. OutputRange& output_range) const
  82. {
  83. add_points(point, distance_strategy.apply(point, point,
  84. strategy::buffer::buffer_side_left), output_range);
  85. }
  86. #endif // DOXYGEN_SHOULD_SKIP_THIS
  87. };
  88. }} // namespace strategy::buffer
  89. }} // namespace boost::geometry
  90. #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_POINT_SQUARE_HPP