123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_JOIN_MITER_HPP
- #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_JOIN_MITER_HPP
- #include <boost/geometry/core/assert.hpp>
- #include <boost/geometry/core/cs.hpp>
- #include <boost/geometry/policies/compare.hpp>
- #include <boost/geometry/util/math.hpp>
- #include <boost/geometry/util/select_most_precise.hpp>
- #include <boost/geometry/strategies/buffer.hpp>
- namespace boost { namespace geometry
- {
- namespace strategy { namespace buffer
- {
- class join_miter
- {
- public:
-
-
- explicit inline join_miter(double miter_limit = 5.0)
- : m_miter_limit(valid_limit(miter_limit))
- {}
- #ifndef DOXYGEN_SHOULD_SKIP_THIS
-
- template <typename Point, typename DistanceType, typename RangeOut>
- inline bool apply(Point const& ip, Point const& vertex,
- Point const& perp1, Point const& perp2,
- DistanceType const& buffer_distance,
- RangeOut& range_out) const
- {
- geometry::equal_to<Point> equals;
- if (equals(ip, vertex))
- {
- return false;
- }
- if (equals(perp1, perp2))
- {
- return false;
- }
- typedef typename coordinate_type<Point>::type coordinate_type;
- typedef typename geometry::select_most_precise
- <
- coordinate_type,
- double
- >::type promoted_type;
- Point p = ip;
-
-
-
- promoted_type const dx = get<0>(p) - get<0>(vertex);
- promoted_type const dy = get<1>(p) - get<1>(vertex);
- promoted_type const distance = geometry::math::sqrt(dx * dx + dy * dy);
- promoted_type const max_distance
- = m_miter_limit * geometry::math::abs(buffer_distance);
- if (distance > max_distance)
- {
- BOOST_GEOMETRY_ASSERT(distance != 0.0);
- promoted_type const proportion = max_distance / distance;
- set<0>(p, get<0>(vertex) + dx * proportion);
- set<1>(p, get<1>(vertex) + dy * proportion);
- }
- range_out.push_back(perp1);
- range_out.push_back(p);
- range_out.push_back(perp2);
- return true;
- }
- template <typename NumericType>
- inline NumericType max_distance(NumericType const& distance) const
- {
- return distance * m_miter_limit;
- }
- #endif
- private :
- double valid_limit(double miter_limit) const
- {
- if (miter_limit < 1.0)
- {
-
- miter_limit = 1.0;
- }
- return miter_limit;
- }
- double m_miter_limit;
- };
- }}
- }}
- #endif
|