]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. | |
6 | // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. | |
7 | ||
b32b8144 FG |
8 | // This file was modified by Oracle on 2017. |
9 | // Modifications copyright (c) 2017, Oracle and/or its affiliates. | |
10 | ||
11 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
12 | ||
7c673cae FG |
13 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library |
14 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
15 | ||
16 | // Use, modification and distribution is subject to the Boost Software License, | |
17 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
18 | // http://www.boost.org/LICENSE_1_0.txt) | |
19 | ||
20 | #include "test_expand.hpp" | |
21 | ||
22 | ||
23 | #include <boost/geometry/algorithms/make.hpp> | |
24 | ||
25 | #include <boost/geometry/geometries/geometries.hpp> | |
26 | #include <boost/geometry/geometries/adapted/c_array.hpp> | |
27 | #include <boost/geometry/geometries/adapted/boost_tuple.hpp> | |
28 | #include <boost/geometry/geometries/adapted/std_pair_as_segment.hpp> | |
29 | #include <test_common/test_point.hpp> | |
30 | ||
31 | BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) | |
32 | BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) | |
33 | ||
34 | ||
35 | template <typename Point> | |
36 | void test_point_3d() | |
37 | { | |
38 | bg::model::box<Point> b = bg::make_inverse<bg::model::box<Point> >(); | |
39 | ||
40 | test_expand<Point>(b, "POINT(1 2 5)", "(1,2,5),(1,2,5)"); | |
41 | test_expand<Point>(b, "POINT(3 4 6)", "(1,2,5),(3,4,6)"); | |
42 | ||
43 | test_expand<Point>(b, "POINT(4 4 5)", "(1,2,5),(4,4,6)"); | |
44 | test_expand<Point>(b, "POINT(4 5 5)", "(1,2,5),(4,5,6)"); | |
45 | test_expand<Point>(b, "POINT(10 10 4)", "(1,2,4),(10,10,6)"); | |
46 | test_expand<Point>(b, "POINT(9 9 4)", "(1,2,4),(10,10,6)"); | |
47 | ||
48 | test_expand<Point>(b, "POINT(0 2 7)", "(0,2,4),(10,10,7)"); | |
49 | test_expand<Point>(b, "POINT(0 0 7)", "(0,0,4),(10,10,7)"); | |
50 | test_expand<Point>(b, "POINT(-1 -1 5)", "(-1,-1,4),(10,10,7)"); | |
51 | test_expand<Point>(b, "POINT(0 0 5)", "(-1,-1,4),(10,10,7)"); | |
52 | ||
53 | test_expand<Point>(b, "POINT(15 -1 0)", "(-1,-1,0),(15,10,7)"); | |
54 | test_expand<Point>(b, "POINT(-1 15 10)", "(-1,-1,0),(15,15,10)"); | |
55 | } | |
56 | ||
57 | template <typename Point> | |
58 | void test_box_3d() | |
59 | { | |
60 | typedef bg::model::box<Point> box_type; | |
61 | box_type b = bg::make_inverse<box_type>(); | |
62 | ||
63 | test_expand<box_type>(b, "BOX(0 2 5,4 4 6)", "(0,2,5),(4,4,6)"); | |
64 | test_expand<box_type>(b, "BOX(0 1 5,4 6 6)", "(0,1,5),(4,6,6)"); | |
65 | test_expand<box_type>(b, "BOX(-1 -1 6,10 10 5)", "(-1,-1,5),(10,10,6)"); | |
66 | test_expand<box_type>(b, "BOX(3 3 6,3 3 5)", "(-1,-1,5),(10,10,6)"); | |
67 | ||
68 | test_expand<box_type>(b, "BOX(3 15 7,-1 3 4)", "(-1,-1,4),(10,15,7)"); | |
69 | test_expand<box_type>(b, "BOX(-15 3 7,3 20 4)", "(-15,-1,4),(10,20,7)"); | |
70 | test_expand<box_type>(b, "BOX(3 -20 8,3 20 3)", "(-15,-20,3),(10,20,8)"); | |
71 | test_expand<box_type>(b, "BOX(-20 3 8,20 3 3)", "(-20,-20,3),(20,20,8)"); | |
72 | } | |
73 | ||
74 | ||
75 | ||
76 | template <typename P> | |
77 | void test_3d() | |
78 | { | |
79 | test_point_3d<P>(); | |
80 | test_box_3d<P>(); | |
81 | } | |
82 | ||
83 | template <typename Point> | |
84 | void test_2d() | |
85 | { | |
86 | typedef bg::model::box<Point> box_type; | |
87 | typedef std::pair<Point, Point> segment_type; | |
88 | ||
89 | box_type b = bg::make_inverse<box_type>(); | |
90 | ||
91 | test_expand<box_type>(b, "BOX(1 1,2 2)", "(1,1),(2,2)"); | |
92 | ||
93 | // Test an 'incorrect' box -> should also correctly update the bbox | |
94 | test_expand<box_type>(b, "BOX(3 4,0 1)", "(0,1),(3,4)"); | |
95 | ||
96 | // Test a segment | |
97 | test_expand<segment_type>(b, "SEGMENT(5 6,7 8)", "(0,1),(7,8)"); | |
98 | } | |
99 | ||
100 | template <typename Point> | |
101 | void test_spherical_degree() | |
102 | { | |
b32b8144 FG |
103 | // it doesn't work with normalization of input enabled |
104 | //bg::model::box<Point> b = bg::make_inverse<bg::model::box<Point> >(); | |
105 | Point p; | |
106 | bg::read_wkt("POINT(179.73 71.56)", p); | |
107 | bg::model::box<Point> b(p, p); | |
7c673cae FG |
108 | |
109 | test_expand<Point>(b, "POINT(179.73 71.56)", | |
110 | "(179.73,71.56),(179.73,71.56)"); | |
111 | test_expand<Point>(b, "POINT(177.47 71.23)", | |
112 | "(177.47,71.23),(179.73,71.56)"); | |
113 | ||
114 | // It detects that this point is lying RIGHT of the others, | |
115 | // and then it "expands" it. | |
7c673cae | 116 | test_expand<Point>(b, "POINT(-178.78 70.78)", |
b32b8144 | 117 | "(177.47,70.78),(181.22,71.56)"); |
7c673cae FG |
118 | } |
119 | ||
120 | ||
121 | template <typename Point> | |
122 | void test_spherical_radian() | |
123 | { | |
b32b8144 FG |
124 | // it doesn't work with normalization of input enabled |
125 | //bg::model::box<Point> b = bg::make_inverse<bg::model::box<Point> >(); | |
126 | Point p; | |
127 | bg::read_wkt("POINT(3.128 1.249)", p); | |
128 | bg::model::box<Point> b(p, p); | |
7c673cae FG |
129 | |
130 | test_expand<Point>(b, "POINT(3.128 1.249)", | |
131 | "(3.128,1.249),(3.128,1.249)"); | |
132 | test_expand<Point>(b, "POINT(3.097 1.243)", | |
133 | "(3.097,1.243),(3.128,1.249)"); | |
134 | ||
135 | // It detects that this point is lying RIGHT of the others, | |
136 | // and then it "expands" it. | |
7c673cae | 137 | test_expand<Point>(b, "POINT(-3.121 1.235)", |
b32b8144 | 138 | "(3.097,1.235),(3.16219,1.249)"); |
7c673cae FG |
139 | } |
140 | ||
141 | int test_main(int, char* []) | |
142 | { | |
143 | test_2d<bg::model::point<int, 2, bg::cs::cartesian> >(); | |
144 | ||
145 | ||
146 | test_3d<test::test_point>(); | |
147 | test_3d<bg::model::point<int, 3, bg::cs::cartesian> >(); | |
148 | test_3d<bg::model::point<float, 3, bg::cs::cartesian> >(); | |
149 | test_3d<bg::model::point<double, 3, bg::cs::cartesian> >(); | |
150 | ||
151 | test_spherical_degree<bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >(); | |
152 | test_spherical_radian<bg::model::point<double, 2, bg::cs::spherical<bg::radian> > >(); | |
b32b8144 FG |
153 | test_spherical_degree<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); |
154 | test_spherical_radian<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::radian> > >(); | |
7c673cae | 155 | |
7c673cae FG |
156 | return 0; |
157 | } |