buffer_end_flat.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_END_FLAT_HPP
  10. #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_END_FLAT_HPP
  11. #include <boost/geometry/core/coordinate_type.hpp>
  12. #include <boost/geometry/strategies/buffer.hpp>
  13. #include <boost/geometry/strategies/tags.hpp>
  14. #include <boost/geometry/strategies/side.hpp>
  15. #include <boost/geometry/util/math.hpp>
  16. #include <boost/geometry/util/select_most_precise.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace strategy { namespace buffer
  20. {
  21. /*!
  22. \brief Let the buffer create flat ends
  23. \ingroup strategies
  24. \details This strategy can be used as EndStrategy for the buffer algorithm.
  25. It creates a flat end for each linestring-end. It can be applied
  26. for (multi)linestrings. Also it is applicable for spikes in (multi)polygons.
  27. This strategy is only applicable for Cartesian coordinate systems.
  28. \qbk{
  29. [heading Example]
  30. [buffer_end_flat]
  31. [heading Output]
  32. [$img/strategies/buffer_end_flat.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_end_round end_round]
  36. }
  37. */
  38. class end_flat
  39. {
  40. public :
  41. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  42. //! Fills output_range with a flat end
  43. template <typename Point, typename RangeOut, typename DistanceStrategy>
  44. inline void apply(Point const& penultimate_point,
  45. Point const& perp_left_point,
  46. Point const& ultimate_point,
  47. Point const& perp_right_point,
  48. buffer_side_selector side,
  49. DistanceStrategy const& distance,
  50. RangeOut& range_out) const
  51. {
  52. typedef typename coordinate_type<Point>::type coordinate_type;
  53. typedef typename geometry::select_most_precise
  54. <
  55. coordinate_type,
  56. double
  57. >::type promoted_type;
  58. promoted_type const dist_left = distance.apply(penultimate_point, ultimate_point, buffer_side_left);
  59. promoted_type const dist_right = distance.apply(penultimate_point, ultimate_point, buffer_side_right);
  60. bool reversed = (side == buffer_side_left && dist_right < 0 && -dist_right > dist_left)
  61. || (side == buffer_side_right && dist_left < 0 && -dist_left > dist_right)
  62. ;
  63. if (reversed)
  64. {
  65. range_out.push_back(perp_right_point);
  66. range_out.push_back(perp_left_point);
  67. }
  68. else
  69. {
  70. range_out.push_back(perp_left_point);
  71. range_out.push_back(perp_right_point);
  72. }
  73. // Don't add the ultimate_point (endpoint of the linestring).
  74. // The buffer might be generated completely at one side.
  75. // In other cases it does no harm but is further useless
  76. }
  77. template <typename NumericType>
  78. static inline NumericType max_distance(NumericType const& distance)
  79. {
  80. return distance;
  81. }
  82. //! Returns the piece_type (flat end)
  83. static inline piece_type get_piece_type()
  84. {
  85. return buffered_flat_end;
  86. }
  87. #endif // DOXYGEN_SHOULD_SKIP_THIS
  88. };
  89. }} // namespace strategy::buffer
  90. }} // namespace boost::geometry
  91. #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_END_FLAT_HPP