4 // Copyright (c) 2019 Barend Gehrels, Amsterdam, the Netherlands.
6 // This file was modified by Oracle on 2019.
7 // Modifications copyright (c) 2019, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #include <geometry_test_common.hpp>
16 #include <boost/geometry/algorithms/detail/make/make.hpp>
17 #include <boost/geometry/geometries/infinite_line.hpp>
18 #include <boost/geometry/geometries/point.hpp>
19 #include <boost/geometry/util/math.hpp>
23 // Boost.Test does not support BOOST_CHECK_CLOSE for integral types
25 bool is_small(T const& value)
27 static long double const epsilon = 1.0e-5;
28 return bg::math::abs(value) < epsilon;
32 template <typename T, typename C>
33 void verify_point_on_line(bg::model::infinite_line<T> const& line,
34 C const& x, C const& y)
36 BOOST_CHECK_MESSAGE(is_small(line.a * x + line.b * y + line.c),
37 "Point is not located on the line");
43 typedef bg::model::infinite_line<T> line_type;
45 // Horizontal through origin
46 line_type line = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0);
47 verify_point_on_line(line, 0, 0);
48 verify_point_on_line(line, 10, 0);
50 // Horizontal line above origin
51 line = bg::detail::make::make_infinite_line<T>(0, 5, 10, 5);
52 verify_point_on_line(line, 0, 5);
53 verify_point_on_line(line, 10, 5);
55 // Vertical through origin
56 line = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10);
57 verify_point_on_line(line, 0, 0);
58 verify_point_on_line(line, 0, 10);
60 // Vertical line left from origin
61 line = bg::detail::make::make_infinite_line<T>(5, 0, 5, 10);
62 verify_point_on_line(line, 5, 0);
63 verify_point_on_line(line, 5, 10);
65 // Diagonal through origin
66 line = bg::detail::make::make_infinite_line<T>(0, 0, 8, 10);
67 verify_point_on_line(line, 0, 0);
68 verify_point_on_line(line, 8, 10);
70 // Diagonal not through origin
71 line = bg::detail::make::make_infinite_line<T>(5, 2, -8, 10);
72 verify_point_on_line(line, 5, 2);
73 verify_point_on_line(line, -8, 10);
83 int test_main(int, char* [])
86 test_all<long double>();