feat():initial version

This commit is contained in:
2026-06-09 20:16:47 +08:00
commit 85fbb3188c
14809 changed files with 3044607 additions and 0 deletions

View File

@@ -0,0 +1,335 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// 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.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, 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_ARITHMETIC_HPP
#define BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP
#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>
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
\details
\tparam Point \tparam_point
\param p point
\param value value to add
*/
template <typename Point>
inline void add_value(Point& p, typename detail::param<Point>::type value)
{
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
for_each_coordinate(p,
detail::value_operation
<
typename coordinate_type<Point>::type,
std::plus
>(value));
}
/*!
\brief Adds a point to another
\ingroup arithmetic
\details The coordinates of the second point will be added to those of the first point.
The second point is not modified.
\tparam Point1 \tparam_point
\tparam Point2 \tparam_point
\param p1 first point
\param p2 second point
*/
template <typename Point1, typename Point2>
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));
}
/*!
\brief Subtracts the same value to each coordinate of a point
\ingroup arithmetic
\details
\tparam Point \tparam_point
\param p point
\param value value to subtract
*/
template <typename Point>
inline void subtract_value(Point& p, typename detail::param<Point>::type value)
{
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
for_each_coordinate(p,
detail::value_operation
<
typename coordinate_type<Point>::type,
std::minus
>(value));
}
/*!
\brief Subtracts a point to another
\ingroup arithmetic
\details The coordinates of the second point will be subtracted to those of the first point.
The second point is not modified.
\tparam Point1 \tparam_point
\tparam Point2 \tparam_point
\param p1 first point
\param p2 second point
*/
template <typename Point1, typename Point2>
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));
}
/*!
\brief Multiplies each coordinate of a point by the same value
\ingroup arithmetic
\details
\tparam Point \tparam_point
\param p point
\param value value to multiply by
*/
template <typename Point>
inline void multiply_value(Point& p, typename detail::param<Point>::type value)
{
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
for_each_coordinate(p,
detail::value_operation
<
typename coordinate_type<Point>::type,
std::multiplies
>(value));
}
/*!
\brief Multiplies a point by another
\ingroup arithmetic
\details The coordinates of the first point will be multiplied by those of the second point.
The second point is not modified.
\tparam Point1 \tparam_point
\tparam Point2 \tparam_point
\param p1 first point
\param p2 second point
\note This is *not* a dot, cross or wedge product. It is a mere field-by-field multiplication.
*/
template <typename Point1, typename Point2>
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));
}
/*!
\brief Divides each coordinate of the same point by a value
\ingroup arithmetic
\details
\tparam Point \tparam_point
\param p point
\param value value to divide by
*/
template <typename Point>
inline void divide_value(Point& p, typename detail::param<Point>::type value)
{
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
for_each_coordinate(p,
detail::value_operation
<
typename coordinate_type<Point>::type,
std::divides
>(value));
}
/*!
\brief Divides a point by another
\ingroup arithmetic
\details The coordinates of the first point will be divided by those of the second point.
The second point is not modified.
\tparam Point1 \tparam_point
\tparam Point2 \tparam_point
\param p1 first point
\param p2 second point
*/
template <typename Point1, typename Point2>
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));
}
/*!
\brief Assign each coordinate of a point the same value
\ingroup arithmetic
\details
\tparam Point \tparam_point
\param p point
\param value value to assign
*/
template <typename Point>
inline void assign_value(Point& p, typename detail::param<Point>::type value)
{
BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
for_each_coordinate(p,
detail::value_assignment
<
typename coordinate_type<Point>::type
>(value));
}
/*!
\brief Assign a point with another
\ingroup arithmetic
\details The coordinates of the first point will be assigned those of the second point.
The second point is not modified.
\tparam Point1 \tparam_point
\tparam Point2 \tparam_point
\param p1 first point
\param p2 second point
*/
template <typename Point1, typename Point2>
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));
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP

View File

@@ -0,0 +1,210 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// 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-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,
// 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_CROSS_PRODUCT_HPP
#define BOOST_GEOMETRY_ARITHMETIC_CROSS_PRODUCT_HPP
#include <cstddef>
#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>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
template <std::size_t Dimension>
struct cross_product
{
// We define cross product only for 2d (see Wolfram) and 3d.
// 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_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 void apply(P1 const& p1, P2 const& p2, ResultP& result)
{
assert_dimension<P1, 2>();
assert_dimension<P2, 2>();
assert_dimension<ResultP, 2>();
// For 2-dimensions, analog of the cross product U(x,y) and V(x,y) is
// Ux * Vy - Uy * Vx
// which is returned as 0-component (or X) of 2d vector, 1-component is undefined.
set<0>(result, get<0>(p1) * get<1>(p2) - get<1>(p1) * get<0>(p2));
}
};
template <>
struct cross_product<3>
{
template <typename P1, typename P2, typename ResultP>
static void apply(P1 const& p1, P2 const& p2, ResultP& result)
{
assert_dimension<P1, 3>();
assert_dimension<P2, 3>();
assert_dimension<ResultP, 3>();
set<0>(result, get<1>(p1) * get<2>(p2) - get<2>(p1) * get<1>(p2));
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
#endif // DOXYGEN_NO_DETAIL
/*!
\brief Computes the cross product of two vectors.
\details All vectors should have the same dimension, 3 or 2.
\ingroup arithmetic
\param p1 first vector
\param p2 second vector
\return the cross product vector
*/
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>) );
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<P1>) );
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<P2>) );
ResultP result;
detail::cross_product<dimension<ResultP>::value>::apply(p1, p2, result);
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.
\ingroup arithmetic
\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,
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>));
BOOST_CONCEPT_ASSERT((concepts::ConstPoint<P>));
P result;
detail::cross_product<dimension<P>::value>::apply(p1, p2, result);
return result;
}
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

View File

@@ -0,0 +1,78 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// 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_DETERMINANT_HPP
#define BOOST_GEOMETRY_ARITHMETIC_DETERMINANT_HPP
#include <cstddef>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/geometries/concepts/point_concept.hpp>
#include <boost/geometry/util/select_coordinate_type.hpp>
#include <boost/numeric/conversion/cast.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
template <typename ReturnType, typename U, typename V>
class calculate_determinant
{
template <typename T>
static inline ReturnType rt(T const& v)
{
return boost::numeric_cast<ReturnType>(v);
}
public :
static inline ReturnType apply(U const& ux, U const& uy
, V const& vx, V const& vy)
{
return rt(ux) * rt(vy) - rt(uy) * rt(vx);
}
};
template <typename ReturnType, typename U, typename V>
inline ReturnType determinant(U const& ux, U const& uy
, V const& vx, V const& vy)
{
return calculate_determinant
<
ReturnType, U, V
>::apply(ux, uy, vx, vy);
}
template <typename ReturnType, typename U, typename V>
inline ReturnType determinant(U const& u, V const& v)
{
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<U>) );
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<V>) );
return calculate_determinant
<
ReturnType,
typename geometry::coordinate_type<U>::type,
typename geometry::coordinate_type<V>::type
>::apply(get<0>(u), get<1>(u), get<0>(v), get<1>(v));
}
} // namespace detail
#endif // DOXYGEN_NO_DETAIL
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ARITHMETIC_DETERMINANT_HPP

View File

@@ -0,0 +1,96 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// 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.
// 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.
// 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_DOT_PRODUCT_HPP
#define BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP
#include <cstddef>
#include <boost/concept/requires.hpp>
#include <boost/geometry/geometries/concepts/point_concept.hpp>
#include <boost/geometry/util/select_coordinate_type.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
template <typename P1, typename P2, std::size_t Dimension, std::size_t DimensionCount>
struct dot_product_maker
{
typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
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);
}
};
template <typename P1, typename P2, std::size_t DimensionCount>
struct dot_product_maker<P1, P2, DimensionCount, DimensionCount>
{
typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
static constexpr coordinate_type apply(P1 const& p1, P2 const& p2)
{
return get<DimensionCount>(p1) * get<DimensionCount>(p2);
}
};
} // namespace detail
#endif // DOXYGEN_NO_DETAIL
/*!
\brief Computes the dot product (or scalar product) of 2 vectors (points).
\ingroup arithmetic
\tparam Point1 \tparam_point
\tparam Point2 \tparam_point
\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)
{
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point1>) );
BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
return detail::dot_product_maker
<
Point1, Point2,
0, dimension<Point1>::type::value - 1
>::apply(p1, p2);
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP

View File

@@ -0,0 +1,93 @@
// 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/core/access.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
{
// 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 Point, typename Type>
inline bool intersection_point(model::infinite_line<Type> const& p,
model::infinite_line<Type> const& q, Point& ip)
{
Type const denominator = p.b * q.a - p.a * q.b;
static Type const zero = 0;
if (math::equals(denominator, zero))
{
// Lines are parallel
return false;
}
// Calculate the intersection coordinates
geometry::set<0>(ip, (p.c * q.b - p.b * q.c) / denominator);
geometry::set<1>(ip, (p.a * q.c - p.c * q.a) / 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

View File

@@ -0,0 +1,71 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2016, 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,
// 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_NORMALIZE_HPP
#define BOOST_GEOMETRY_ARITHMETIC_NORMALIZE_HPP
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/arithmetic/arithmetic.hpp>
#include <boost/geometry/arithmetic/dot_product.hpp>
#include <boost/geometry/util/math.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
template <typename Point>
inline typename coordinate_type<Point>::type vec_length_sqr(Point const& pt)
{
return dot_product(pt, pt);
}
template <typename Point>
inline typename coordinate_type<Point>::type vec_length(Point const& pt)
{
// NOTE: hypot() could be used instead of sqrt()
return math::sqrt(dot_product(pt, pt));
}
template <typename Point>
inline bool vec_normalize(Point & pt, typename coordinate_type<Point>::type & len)
{
typedef typename coordinate_type<Point>::type coord_t;
coord_t const c0 = 0;
len = vec_length(pt);
if (math::equals(len, c0))
{
return false;
}
divide_value(pt, len);
return true;
}
template <typename Point>
inline bool vec_normalize(Point & pt)
{
typedef typename coordinate_type<Point>::type coord_t;
coord_t len;
return vec_normalize(pt, len);
}
} // namespace detail
#endif // DOXYGEN_NO_DETAIL
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ARITHMETIC_NORMALIZE_HPP