]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/strategies/cartesian/buffer_side_straight.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / strategies / cartesian / buffer_side_straight.hpp
CommitLineData
7c673cae
FG
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
7#ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_SIDE_STRAIGHT_HPP
8#define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_SIDE_STRAIGHT_HPP
9
10#include <cstddef>
11
12#include <boost/math/special_functions/fpclassify.hpp>
13
14#include <boost/geometry/core/coordinate_type.hpp>
15#include <boost/geometry/core/access.hpp>
16#include <boost/geometry/util/math.hpp>
17#include <boost/geometry/util/select_most_precise.hpp>
18
19#include <boost/geometry/strategies/buffer.hpp>
20#include <boost/geometry/strategies/side.hpp>
21
22
23
24namespace boost { namespace geometry
25{
26
27namespace strategy { namespace buffer
28{
29
30
31
32/*!
33\brief Let the buffer use straight sides along segments (the default)
34\ingroup strategies
35\details This strategy can be used as SideStrategy for the buffer algorithm.
36 It is currently the only provided strategy for this purpose
37
38\qbk{
39[heading Example]
40See the examples for other buffer strategies\, for example
41[link geometry.reference.strategies.strategy_buffer_join_round join_round]
42[heading See also]
43\* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
44}
45 */
46class side_straight
47{
48public :
49#ifndef DOXYGEN_SHOULD_SKIP_THIS
1e59de90
TL
50
51 // Returns true if the buffer distance is always the same
52 static inline bool equidistant()
53 {
54 return true;
55 }
56
7c673cae
FG
57 template
58 <
59 typename Point,
60 typename OutputRange,
61 typename DistanceStrategy
62 >
63 static inline result_code apply(
64 Point const& input_p1, Point const& input_p2,
65 buffer_side_selector side,
66 DistanceStrategy const& distance,
67 OutputRange& output_range)
68 {
69 typedef typename coordinate_type<Point>::type coordinate_type;
70 typedef typename geometry::select_most_precise
71 <
72 coordinate_type,
73 double
74 >::type promoted_type;
75
76 // Generate a block along (left or right of) the segment
77
78 // Simulate a vector d (dx,dy)
79 coordinate_type const dx = get<0>(input_p2) - get<0>(input_p1);
80 coordinate_type const dy = get<1>(input_p2) - get<1>(input_p1);
81
82 // For normalization [0,1] (=dot product d.d, sqrt)
83 promoted_type const length = geometry::math::sqrt(dx * dx + dy * dy);
84
85 if (! boost::math::isfinite(length))
86 {
87 // In case of coordinates differences of e.g. 1e300, length
88 // will overflow and we should not generate output
89#ifdef BOOST_GEOMETRY_DEBUG_BUFFER_WARN
90 std::cout << "Error in length calculation for points "
91 << geometry::wkt(input_p1) << " " << geometry::wkt(input_p2)
92 << " length: " << length << std::endl;
93#endif
94 return result_error_numerical;
95 }
96
97 if (geometry::math::equals(length, 0))
98 {
99 // Coordinates are simplified and therefore most often not equal.
100 // But if simplify is skipped, or for lines with two
101 // equal points, length is 0 and we cannot generate output.
102 return result_no_output;
103 }
104
105 promoted_type const d = distance.apply(input_p1, input_p2, side);
106
107 // Generate the normalized perpendicular p, to the left (ccw)
108 promoted_type const px = -dy / length;
109 promoted_type const py = dx / length;
110
111 if (geometry::math::equals(px, 0)
112 && geometry::math::equals(py, 0))
113 {
114 // This basically should not occur - because of the checks above.
115 // There are no unit tests triggering this condition
116#ifdef BOOST_GEOMETRY_DEBUG_BUFFER_WARN
117 std::cout << "Error in perpendicular calculation for points "
118 << geometry::wkt(input_p1) << " " << geometry::wkt(input_p2)
119 << " length: " << length
120 << " distance: " << d
121 << std::endl;
122#endif
123 return result_no_output;
124 }
125
126 output_range.resize(2);
127
128 set<0>(output_range.front(), get<0>(input_p1) + px * d);
129 set<1>(output_range.front(), get<1>(input_p1) + py * d);
130 set<0>(output_range.back(), get<0>(input_p2) + px * d);
131 set<1>(output_range.back(), get<1>(input_p2) + py * d);
132
133 return result_normal;
134 }
135#endif // DOXYGEN_SHOULD_SKIP_THIS
136};
137
138
139}} // namespace strategy::buffer
140
141}} // namespace boost::geometry
142
143#endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_SIDE_STRAIGHT_HPP