123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #ifndef BOOST_GEOMETRY_ARITHMETIC_LINE_FUNCTIONS_HPP
- #define BOOST_GEOMETRY_ARITHMETIC_LINE_FUNCTIONS_HPP
- #include <boost/geometry/arithmetic/determinant.hpp>
- #include <boost/geometry/core/access.hpp>
- #include <boost/geometry/core/assert.hpp>
- #include <boost/geometry/core/config.hpp>
- #include <boost/geometry/geometries/infinite_line.hpp>
- #include <boost/geometry/util/math.hpp>
- #include <boost/geometry/util/select_most_precise.hpp>
- namespace boost { namespace geometry
- {
- namespace arithmetic
- {
- template <typename Line, typename Line::type Line::* member1, typename Line::type Line::* member2>
- inline auto determinant(Line const& p, Line const& q)
- {
- return geometry::detail::determinant<typename Line::type>(p.*member1, p.*member2,
- q.*member1, q.*member2);
- }
- template <typename Point, typename Line, typename Type>
- inline Point assign_intersection_point(Line const& p, Line const& q, Type const& denominator)
- {
- BOOST_ASSERT(denominator != Type(0));
-
-
- Point result;
- geometry::set<0>(result, determinant<Line, &Line::b, &Line::c>(p, q) / denominator);
- geometry::set<1>(result, determinant<Line, &Line::c, &Line::a>(p, q) / denominator);
- return result;
- }
- template <typename Line, typename Point>
- inline bool intersection_point(Line const& p, Line const& q, Point& ip)
- {
- auto const denominator = determinant<Line, &Line::a, &Line::b>(p, q);
- constexpr decltype(denominator) const zero = 0;
- if (math::equals(denominator, zero))
- {
-
- return false;
- }
- ip = assign_intersection_point<Point>(p, q, denominator);
- return true;
- }
- template <typename Type, typename CoordinateType>
- inline
- typename select_most_precise<Type, CoordinateType>::type
- side_value(model::infinite_line<Type> const& line,
- CoordinateType const& x, CoordinateType const& y)
- {
-
-
-
-
-
-
-
- return line.a * x + line.b * y + line.c;
- }
- template <typename Type, typename Point>
- inline
- typename select_most_precise
- <
- Type,
- typename geometry::coordinate_type<Point>::type
- >::type
- side_value(model::infinite_line<Type> const& line, Point const& p)
- {
- return side_value(line, geometry::get<0>(p), geometry::get<1>(p));
- }
- template <typename Type>
- inline bool is_degenerate(model::infinite_line<Type> const& line)
- {
- static Type const zero = 0;
- return math::equals(line.a, zero) && math::equals(line.b, zero);
- }
- }
- }}
- #endif
|