buffer_point_square.hpp 3.6 KB

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