1 // Boost.Geometry
2 // Unit Test
3 
4 // Copyright (c) 2019 Barend Gehrels, Amsterdam, the Netherlands.
5 
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
9 
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)
13 
14 #include <geometry_test_common.hpp>
15 
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>
20 
21 namespace
22 {
23     // Boost.Test does not support BOOST_CHECK_CLOSE for integral types
24     template <typename T>
is_small(T const & value)25     bool is_small(T const& value)
26     {
27         static long double const epsilon = 1.0e-5;
28         return bg::math::abs(value) < epsilon;
29     }
30 }
31 
32 template <typename T, typename C>
verify_point_on_line(bg::model::infinite_line<T> const & line,C const & x,C const & y)33 void verify_point_on_line(bg::model::infinite_line<T> const& line,
34                           C const& x, C const& y)
35 {
36     BOOST_CHECK_MESSAGE(is_small(line.a * x + line.b * y + line.c),
37                         "Point is not located on the line");
38 }
39 
40 template <typename T>
test_make()41 void test_make()
42 {
43     typedef bg::model::infinite_line<T> line_type;
44 
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);
49 
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);
54 
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);
59 
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);
64 
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);
69 
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);
74 }
75 
76 
77 template <typename T>
test_all()78 void test_all()
79 {
80     test_make<T>();
81 }
82 
test_main(int,char * [])83 int test_main(int, char* [])
84 {
85     test_all<double>();
86     test_all<long double>();
87     test_all<float>();
88     test_all<int>();
89     return 0;
90 }
91