]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/algorithms/detail/make/make.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / make / make.hpp
CommitLineData
92f5a8d4
TL
1// Boost.Geometry
2
3// Copyright (c) 2019 Barend Gehrels, Amsterdam, the Netherlands.
4
5// Use, modification and distribution is subject to the Boost Software License,
6// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_MAKE_MAKE_HPP
10#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_MAKE_MAKE_HPP
11
12#include <boost/geometry/geometries/infinite_line.hpp>
13#include <boost/geometry/core/access.hpp>
14
15namespace boost { namespace geometry
16{
17
18#ifndef DOXYGEN_NO_DETAIL
19namespace detail { namespace make
20{
21
22template <typename Type, typename Coordinate>
23inline
24model::infinite_line<Type> make_infinite_line(Coordinate const& x1,
25 Coordinate const& y1, Coordinate const& x2, Coordinate const& y2)
26{
27 model::infinite_line<Type> result;
28 result.a = y1 - y2;
29 result.b = x2 - x1;
30 result.c = -result.a * x1 - result.b * y1;
31 return result;
32}
33
34template <typename Type, typename Point>
35inline
36model::infinite_line<Type> make_infinite_line(Point const& a, Point const& b)
37{
38 return make_infinite_line<Type>(geometry::get<0>(a), geometry::get<1>(a),
39 geometry::get<0>(b), geometry::get<1>(b));
40}
41
42template <typename Type, typename Segment>
43inline
44model::infinite_line<Type> make_infinite_line(Segment const& segment)
45{
46 return make_infinite_line<Type>(geometry::get<0, 0>(segment),
47 geometry::get<0, 1>(segment),
48 geometry::get<1, 0>(segment),
49 geometry::get<1, 1>(segment));
50}
51
20effc67
TL
52template <typename Type, typename Point>
53inline
54model::infinite_line<Type> make_perpendicular_line(Point const& a, Point const& b, Point const& c)
55{
56 // https://www.math-only-math.com/equation-of-a-line-perpendicular-to-a-line.html
57 model::infinite_line<Type> const line = make_infinite_line<Type>(a, b);
58 model::infinite_line<Type> result;
59 result.a = line.b;
60 result.b = -line.a;
61 // Lines with any result.c are perpendicular to a->b
62 // Calculate this result such that it goes through point c
63 result.c = -result.a * geometry::get<0>(c) - result.b * geometry::get<1>(c);
64 return result;
65}
92f5a8d4
TL
66
67}} // namespace detail::make
68#endif // DOXYGEN_NO_DETAIL
69
70
71}} // namespace boost::geometry
72
73#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_MAKE_MAKE_HPP