update boost
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// This file was modified by Oracle on 2021.
|
||||
// Modifications copyright (c) 2021 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@@ -16,118 +21,17 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <boost/call_traits.hpp>
|
||||
#include <boost/concept/requires.hpp>
|
||||
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/geometries/concepts/point_concept.hpp>
|
||||
#include <boost/geometry/util/for_each_coordinate.hpp>
|
||||
#include <boost/geometry/util/select_most_precise.hpp>
|
||||
#include <boost/geometry/util/algorithm.hpp>
|
||||
#include <boost/geometry/util/select_coordinate_type.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
template <typename Point>
|
||||
struct param
|
||||
{
|
||||
typedef typename boost::call_traits
|
||||
<
|
||||
typename coordinate_type<Point>::type
|
||||
>::param_type type;
|
||||
};
|
||||
|
||||
|
||||
template <typename Value, template <typename> class Function>
|
||||
struct value_operation
|
||||
{
|
||||
Value m_value;
|
||||
|
||||
inline value_operation(Value const &value)
|
||||
: m_value(value)
|
||||
{}
|
||||
|
||||
template <typename PointDst, std::size_t Index>
|
||||
inline void apply(PointDst& point_dst) const
|
||||
{
|
||||
set<Index>(point_dst,
|
||||
Function
|
||||
<
|
||||
typename geometry::select_most_precise
|
||||
<
|
||||
Value,
|
||||
typename geometry::coordinate_type<PointDst>::type
|
||||
>::type
|
||||
>()(get<Index>(point_dst), m_value));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PointSrc, template <typename> class Function>
|
||||
struct point_operation
|
||||
{
|
||||
PointSrc const& m_point_src;
|
||||
|
||||
inline point_operation(PointSrc const& point)
|
||||
: m_point_src(point)
|
||||
{}
|
||||
|
||||
template <typename PointDst, std::size_t Index>
|
||||
inline void apply(PointDst& point_dst) const
|
||||
{
|
||||
set<Index>(point_dst,
|
||||
Function
|
||||
<
|
||||
typename geometry::select_most_precise
|
||||
<
|
||||
typename geometry::coordinate_type<PointSrc>::type,
|
||||
typename geometry::coordinate_type<PointDst>::type
|
||||
>::type
|
||||
>()(get<Index>(point_dst), get<Index>(m_point_src)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Value>
|
||||
struct value_assignment
|
||||
{
|
||||
Value m_value;
|
||||
|
||||
inline value_assignment(Value const &value)
|
||||
: m_value(value)
|
||||
{}
|
||||
|
||||
template <typename PointDst, std::size_t Index>
|
||||
inline void apply(PointDst& point_dst) const
|
||||
{
|
||||
set<Index>(point_dst, m_value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PointSrc>
|
||||
struct point_assignment
|
||||
{
|
||||
PointSrc const& m_point_src;
|
||||
|
||||
inline point_assignment(PointSrc const& point)
|
||||
: m_point_src(point)
|
||||
{}
|
||||
|
||||
template <typename PointDst, std::size_t Index>
|
||||
inline void apply(PointDst& point_dst) const
|
||||
{
|
||||
set<Index>(point_dst, get<Index>(m_point_src));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
/*!
|
||||
\brief Adds the same value to each coordinate of a point
|
||||
\ingroup arithmetic
|
||||
@@ -137,16 +41,14 @@ struct point_assignment
|
||||
\param value value to add
|
||||
*/
|
||||
template <typename Point>
|
||||
inline void add_value(Point& p, typename detail::param<Point>::type value)
|
||||
inline void add_value(Point& p, typename coordinate_type<Point>::type const& value)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
|
||||
|
||||
for_each_coordinate(p,
|
||||
detail::value_operation
|
||||
<
|
||||
typename coordinate_type<Point>::type,
|
||||
std::plus
|
||||
>(value));
|
||||
detail::for_each_dimension<Point>([&](auto index)
|
||||
{
|
||||
set<index>(p, get<index>(p) + value);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -165,7 +67,11 @@ inline void add_point(Point1& p1, Point2 const& p2)
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
|
||||
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
|
||||
|
||||
for_each_coordinate(p1, detail::point_operation<Point2, std::plus>(p2));
|
||||
detail::for_each_dimension<Point1>([&](auto index)
|
||||
{
|
||||
using calc_t = typename select_coordinate_type<Point1, Point2>::type;
|
||||
set<index>(p1, calc_t(get<index>(p1)) + calc_t(get<index>(p2)));
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -177,16 +83,14 @@ inline void add_point(Point1& p1, Point2 const& p2)
|
||||
\param value value to subtract
|
||||
*/
|
||||
template <typename Point>
|
||||
inline void subtract_value(Point& p, typename detail::param<Point>::type value)
|
||||
inline void subtract_value(Point& p, typename coordinate_type<Point>::type const& value)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
|
||||
|
||||
for_each_coordinate(p,
|
||||
detail::value_operation
|
||||
<
|
||||
typename coordinate_type<Point>::type,
|
||||
std::minus
|
||||
>(value));
|
||||
detail::for_each_dimension<Point>([&](auto index)
|
||||
{
|
||||
set<index>(p, get<index>(p) - value);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -205,7 +109,11 @@ inline void subtract_point(Point1& p1, Point2 const& p2)
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
|
||||
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
|
||||
|
||||
for_each_coordinate(p1, detail::point_operation<Point2, std::minus>(p2));
|
||||
detail::for_each_dimension<Point1>([&](auto index)
|
||||
{
|
||||
using calc_t = typename select_coordinate_type<Point1, Point2>::type;
|
||||
set<index>(p1, calc_t(get<index>(p1)) - calc_t(get<index>(p2)));
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -217,16 +125,14 @@ inline void subtract_point(Point1& p1, Point2 const& p2)
|
||||
\param value value to multiply by
|
||||
*/
|
||||
template <typename Point>
|
||||
inline void multiply_value(Point& p, typename detail::param<Point>::type value)
|
||||
inline void multiply_value(Point& p, typename coordinate_type<Point>::type const& value)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
|
||||
|
||||
for_each_coordinate(p,
|
||||
detail::value_operation
|
||||
<
|
||||
typename coordinate_type<Point>::type,
|
||||
std::multiplies
|
||||
>(value));
|
||||
detail::for_each_dimension<Point>([&](auto index)
|
||||
{
|
||||
set<index>(p, get<index>(p) * value);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -246,7 +152,11 @@ inline void multiply_point(Point1& p1, Point2 const& p2)
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
|
||||
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
|
||||
|
||||
for_each_coordinate(p1, detail::point_operation<Point2, std::multiplies>(p2));
|
||||
detail::for_each_dimension<Point1>([&](auto index)
|
||||
{
|
||||
using calc_t = typename select_coordinate_type<Point1, Point2>::type;
|
||||
set<index>(p1, calc_t(get<index>(p1)) * calc_t(get<index>(p2)));
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -258,16 +168,14 @@ inline void multiply_point(Point1& p1, Point2 const& p2)
|
||||
\param value value to divide by
|
||||
*/
|
||||
template <typename Point>
|
||||
inline void divide_value(Point& p, typename detail::param<Point>::type value)
|
||||
inline void divide_value(Point& p, typename coordinate_type<Point>::type const& value)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
|
||||
|
||||
for_each_coordinate(p,
|
||||
detail::value_operation
|
||||
<
|
||||
typename coordinate_type<Point>::type,
|
||||
std::divides
|
||||
>(value));
|
||||
detail::for_each_dimension<Point>([&](auto index)
|
||||
{
|
||||
set<index>(p, get<index>(p) / value);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -286,7 +194,11 @@ inline void divide_point(Point1& p1, Point2 const& p2)
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
|
||||
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
|
||||
|
||||
for_each_coordinate(p1, detail::point_operation<Point2, std::divides>(p2));
|
||||
detail::for_each_dimension<Point1>([&](auto index)
|
||||
{
|
||||
using calc_t = typename select_coordinate_type<Point1, Point2>::type;
|
||||
set<index>(p1, calc_t(get<index>(p1)) / calc_t(get<index>(p2)));
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -298,15 +210,14 @@ inline void divide_point(Point1& p1, Point2 const& p2)
|
||||
\param value value to assign
|
||||
*/
|
||||
template <typename Point>
|
||||
inline void assign_value(Point& p, typename detail::param<Point>::type value)
|
||||
inline void assign_value(Point& p, typename coordinate_type<Point>::type const& value)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
|
||||
|
||||
for_each_coordinate(p,
|
||||
detail::value_assignment
|
||||
<
|
||||
typename coordinate_type<Point>::type
|
||||
>(value));
|
||||
detail::for_each_dimension<Point>([&](auto index)
|
||||
{
|
||||
set<index>(p, value);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -325,7 +236,10 @@ inline void assign_point(Point1& p1, Point2 const& p2)
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
|
||||
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
|
||||
|
||||
for_each_coordinate(p1, detail::point_assignment<Point2>(p2));
|
||||
detail::for_each_dimension<Point1>([&](auto index)
|
||||
{
|
||||
set<index>(p1, get<index>(p2));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
||||
|
||||
// This file was modified by Oracle on 2016.
|
||||
// Modifications copyright (c) 2016, Oracle and/or its affiliates.
|
||||
// This file was modified by Oracle on 2016-2020.
|
||||
// Modifications copyright (c) 2016-2020, Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/size_t.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/make.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/static_assert.hpp>
|
||||
|
||||
#include <boost/geometry/geometries/concepts/point_concept.hpp>
|
||||
|
||||
@@ -41,16 +41,16 @@ struct cross_product
|
||||
// In Math, it is also well-defined for 7-dimension.
|
||||
// Generalisation of cross product to n-dimension is defined as
|
||||
// wedge product but it is not direct analogue to binary cross product.
|
||||
BOOST_MPL_ASSERT_MSG((false),
|
||||
NOT_IMPLEMENTED_FOR_THIS_DIMENSION,
|
||||
(mpl::size_t<Dimension>));
|
||||
BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
|
||||
"Not implemented for this Dimension.",
|
||||
std::integral_constant<std::size_t, Dimension>);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct cross_product<2>
|
||||
{
|
||||
template <typename P1, typename P2, typename ResultP>
|
||||
static inline void apply(P1 const& p1, P2 const& p2, ResultP& result)
|
||||
static void apply(P1 const& p1, P2 const& p2, ResultP& result)
|
||||
{
|
||||
assert_dimension<P1, 2>();
|
||||
assert_dimension<P2, 2>();
|
||||
@@ -67,7 +67,7 @@ template <>
|
||||
struct cross_product<3>
|
||||
{
|
||||
template <typename P1, typename P2, typename ResultP>
|
||||
static inline void apply(P1 const& p1, P2 const& p2, ResultP& result)
|
||||
static void apply(P1 const& p1, P2 const& p2, ResultP& result)
|
||||
{
|
||||
assert_dimension<P1, 3>();
|
||||
assert_dimension<P2, 3>();
|
||||
@@ -77,6 +77,19 @@ struct cross_product<3>
|
||||
set<1>(result, get<2>(p1) * get<0>(p2) - get<0>(p1) * get<2>(p2));
|
||||
set<2>(result, get<0>(p1) * get<1>(p2) - get<1>(p1) * get<0>(p2));
|
||||
}
|
||||
|
||||
template <typename ResultP, typename P1, typename P2>
|
||||
static constexpr ResultP apply(P1 const& p1, P2 const& p2)
|
||||
{
|
||||
assert_dimension<P1, 3>();
|
||||
assert_dimension<P2, 3>();
|
||||
assert_dimension<ResultP, 3>();
|
||||
|
||||
return traits::make<ResultP>::apply(
|
||||
get<1>(p1) * get<2>(p2) - get<2>(p1) * get<1>(p2),
|
||||
get<2>(p1) * get<0>(p2) - get<0>(p1) * get<2>(p2),
|
||||
get<0>(p1) * get<1>(p2) - get<1>(p1) * get<0>(p2));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
@@ -90,8 +103,19 @@ struct cross_product<3>
|
||||
\param p1 first vector
|
||||
\param p2 second vector
|
||||
\return the cross product vector
|
||||
*/
|
||||
template <typename ResultP, typename P1, typename P2>
|
||||
|
||||
*/
|
||||
|
||||
template
|
||||
<
|
||||
typename ResultP, typename P1, typename P2,
|
||||
std::enable_if_t
|
||||
<
|
||||
dimension<ResultP>::value != 3
|
||||
|| ! traits::make<ResultP>::is_specialized,
|
||||
int
|
||||
> = 0
|
||||
>
|
||||
inline ResultP cross_product(P1 const& p1, P2 const& p2)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concepts::Point<ResultP>) );
|
||||
@@ -103,6 +127,29 @@ inline ResultP cross_product(P1 const& p1, P2 const& p2)
|
||||
return result;
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename ResultP, typename P1, typename P2,
|
||||
std::enable_if_t
|
||||
<
|
||||
dimension<ResultP>::value == 3
|
||||
&& traits::make<ResultP>::is_specialized,
|
||||
int
|
||||
> = 0
|
||||
>
|
||||
// workaround for VS2015
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1910)
|
||||
constexpr
|
||||
#endif
|
||||
inline ResultP cross_product(P1 const& p1, P2 const& p2)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((concepts::Point<ResultP>));
|
||||
BOOST_CONCEPT_ASSERT((concepts::ConstPoint<P1>));
|
||||
BOOST_CONCEPT_ASSERT((concepts::ConstPoint<P2>));
|
||||
|
||||
return detail::cross_product<3>::apply<ResultP>(p1, p2);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Computes the cross product of two vectors.
|
||||
\details All vectors should have the same dimension, 3 or 2.
|
||||
@@ -110,8 +157,20 @@ inline ResultP cross_product(P1 const& p1, P2 const& p2)
|
||||
\param p1 first vector
|
||||
\param p2 second vector
|
||||
\return the cross product vector
|
||||
|
||||
\qbk{[heading Examples]}
|
||||
\qbk{[cross_product] [cross_product_output]}
|
||||
*/
|
||||
template <typename P>
|
||||
template
|
||||
<
|
||||
typename P,
|
||||
std::enable_if_t
|
||||
<
|
||||
dimension<P>::value != 3
|
||||
|| ! traits::make<P>::is_specialized,
|
||||
int
|
||||
> = 0
|
||||
>
|
||||
inline P cross_product(P const& p1, P const& p2)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((concepts::Point<P>));
|
||||
@@ -123,6 +182,29 @@ inline P cross_product(P const& p1, P const& p2)
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename P,
|
||||
std::enable_if_t
|
||||
<
|
||||
dimension<P>::value == 3
|
||||
&& traits::make<P>::is_specialized,
|
||||
int
|
||||
> = 0
|
||||
>
|
||||
// workaround for VS2015
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1910)
|
||||
constexpr
|
||||
#endif
|
||||
inline P cross_product(P const& p1, P const& p2)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((concepts::Point<P>));
|
||||
BOOST_CONCEPT_ASSERT((concepts::ConstPoint<P>));
|
||||
|
||||
return detail::cross_product<3>::apply<P>(p1, p2);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_ARITHMETIC_CROSS_PRODUCT_HPP
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
||||
|
||||
// This file was modified by Oracle on 2020.
|
||||
// Modifications copyright (c) 2020, Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
|
||||
@@ -34,7 +38,7 @@ struct dot_product_maker
|
||||
{
|
||||
typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
|
||||
|
||||
static inline coordinate_type apply(P1 const& p1, P2 const& p2)
|
||||
static constexpr coordinate_type apply(P1 const& p1, P2 const& p2)
|
||||
{
|
||||
return get<Dimension>(p1) * get<Dimension>(p2)
|
||||
+ dot_product_maker<P1, P2, Dimension+1, DimensionCount>::apply(p1, p2);
|
||||
@@ -46,7 +50,7 @@ struct dot_product_maker<P1, P2, DimensionCount, DimensionCount>
|
||||
{
|
||||
typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
|
||||
|
||||
static inline coordinate_type apply(P1 const& p1, P2 const& p2)
|
||||
static constexpr coordinate_type apply(P1 const& p1, P2 const& p2)
|
||||
{
|
||||
return get<DimensionCount>(p1) * get<DimensionCount>(p2);
|
||||
}
|
||||
@@ -64,8 +68,16 @@ struct dot_product_maker<P1, P2, DimensionCount, DimensionCount>
|
||||
\param p1 first point
|
||||
\param p2 second point
|
||||
\return the dot product
|
||||
|
||||
\qbk{[heading Examples]}
|
||||
\qbk{[dot_product] [dot_product_output]}
|
||||
|
||||
*/
|
||||
template <typename Point1, typename Point2>
|
||||
// workaround for VS2015
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1910)
|
||||
constexpr
|
||||
#endif
|
||||
inline typename select_coordinate_type<Point1, Point2>::type dot_product(
|
||||
Point1 const& p1, Point2 const& p2)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// Boost.Geometry
|
||||
|
||||
// Copyright (c) 2018-2019 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#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));
|
||||
|
||||
// x = | pb pc | / d and y = | pc pa | / d
|
||||
// | qb qc | | qc qa |
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Calculates intersection point of two infinite lines.
|
||||
// Returns true if the lines intersect.
|
||||
// Returns false if lines are parallel (or collinear, possibly opposite)
|
||||
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))
|
||||
{
|
||||
// Lines are parallel
|
||||
return false;
|
||||
}
|
||||
|
||||
ip = assign_intersection_point<Point>(p, q, denominator);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Return a distance-side-measure for a point to a line
|
||||
//! Point is located left of the line if value is positive,
|
||||
//! right of the line is value is negative, and on the line if the value
|
||||
//! is exactly zero
|
||||
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)
|
||||
{
|
||||
// https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Line_defined_by_an_equation
|
||||
// Distance from point to line in general form is given as:
|
||||
// (a * x + b * y + c) / sqrt(a * a + b * b);
|
||||
// In most use cases comparisons are enough, saving the sqrt
|
||||
// and often even the division.
|
||||
// Also, this gives positive values for points left to the line,
|
||||
// and negative values for points right to the line.
|
||||
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(const model::infinite_line<Type>& line)
|
||||
{
|
||||
static Type const zero = 0;
|
||||
return math::equals(line.a, zero) && math::equals(line.b, zero);
|
||||
}
|
||||
|
||||
|
||||
} // namespace arithmetic
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_ARITHMETIC_LINE_FUNCTIONS_HPP
|
||||
@@ -45,7 +45,7 @@ inline bool vec_normalize(Point & pt, typename coordinate_type<Point>::type & le
|
||||
|
||||
coord_t const c0 = 0;
|
||||
len = vec_length(pt);
|
||||
|
||||
|
||||
if (math::equals(len, c0))
|
||||
{
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user