1 // Boost.Geometry Index
4 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 #include <geometry_index_test_common.hpp>
12 #include <boost/geometry/index/detail/algorithms/segment_intersection.hpp>
14 //#include <boost/geometry/io/wkt/read.hpp>
16 template <typename Box
, typename Point
, typename RelativeDistance
>
17 void test_segment_intersection(Box
const& box
, Point
const& p0
, Point
const& p1
,
19 RelativeDistance expected_rel_dist
)
21 RelativeDistance rel_dist
;
22 bool value
= bgi::detail::segment_intersection(box
, p0
, p1
, rel_dist
);
23 BOOST_CHECK(value
== expected_result
);
24 if ( value
&& expected_result
)
25 BOOST_CHECK_CLOSE(rel_dist
, expected_rel_dist
, 0.0001);
28 template <typename Box
, typename Point
, typename RelativeDistance
>
29 void test_geometry(std::string
const& wkt_g
, std::string
const& wkt_p0
, std::string
const& wkt_p1
,
31 RelativeDistance expected_rel_dist
)
34 bg::read_wkt(wkt_g
, box
);
36 bg::read_wkt(wkt_p0
, p0
);
37 bg::read_wkt(wkt_p1
, p1
);
38 test_segment_intersection(box
, p0
, p1
, expected_result
, expected_rel_dist
);
41 #include <boost/geometry/geometries/point_xy.hpp>
42 #include <boost/geometry/geometries/point.hpp>
43 #include <boost/geometry/geometries/box.hpp>
45 void test_large_integers()
47 typedef bg::model::point
<int, 2, bg::cs::cartesian
> int_point_type
;
48 typedef bg::model::point
<double, 2, bg::cs::cartesian
> double_point_type
;
50 bg::model::box
<int_point_type
> int_box
;
51 bg::model::box
<double_point_type
> double_box
;
52 int_point_type int_p0
, int_p1
;
53 double_point_type double_p0
, double_p1
;
55 std::string
const str_box
= "POLYGON((1536119 192000, 1872000 528000))";
56 std::string
const str_p0
= "POINT(1535000 191000)";
57 std::string
const str_p1
= "POINT(1873000 529000)";
58 bg::read_wkt(str_box
, int_box
);
59 bg::read_wkt(str_box
, double_box
);
60 bg::read_wkt(str_p0
, int_p0
);
61 bg::read_wkt(str_p1
, int_p1
);
62 bg::read_wkt(str_p0
, double_p0
);
63 bg::read_wkt(str_p1
, double_p1
);
66 bool int_result
= bgi::detail::segment_intersection(int_box
, int_p0
, int_p1
, int_value
);
68 bool double_result
= bgi::detail::segment_intersection(double_box
, double_p0
, double_p1
, double_value
);
69 BOOST_CHECK(int_result
== double_result
);
70 if ( int_result
&& double_result
)
71 BOOST_CHECK_CLOSE(int_value
, double_value
, 0.0001);
74 int test_main(int, char* [])
76 typedef bg::model::point
<int, 2, bg::cs::cartesian
> P2ic
;
77 typedef bg::model::point
<float, 2, bg::cs::cartesian
> P2fc
;
78 typedef bg::model::point
<double, 2, bg::cs::cartesian
> P2dc
;
80 typedef bg::model::point
<int, 3, bg::cs::cartesian
> P3ic
;
81 typedef bg::model::point
<float, 3, bg::cs::cartesian
> P3fc
;
82 typedef bg::model::point
<double, 3, bg::cs::cartesian
> P3dc
;
84 test_geometry
<bg::model::box
<P2ic
>, P2ic
>("POLYGON((0 1,2 4))", "POINT(0 0)", "POINT(2 5)", true, 1.0f
/5);
85 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(0 0)", "POINT(2 5)", true, 1.0f
/5);
86 test_geometry
<bg::model::box
<P2dc
>, P2dc
>("POLYGON((0 1,2 4))", "POINT(0 0)", "POINT(2 5)", true, 1.0/5);
87 test_geometry
<bg::model::box
<P3ic
>, P3ic
>("POLYGON((0 1 2,2 4 6))", "POINT(0 0 0)", "POINT(2 5 7)", true, 2.0f
/7);
88 test_geometry
<bg::model::box
<P3fc
>, P3fc
>("POLYGON((0 1 2,2 4 6))", "POINT(0 0 0)", "POINT(2 5 7)", true, 2.0f
/7);
89 test_geometry
<bg::model::box
<P3dc
>, P3dc
>("POLYGON((0 1 2,2 4 6))", "POINT(0 0 0)", "POINT(2 5 7)", true, 2.0/7);
91 test_geometry
<bg::model::box
<P2ic
>, P2ic
>("POLYGON((0 1,2 4))", "POINT(3 4)", "POINT(0 0)", true, 1.0f
/3);
92 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(3 4)", "POINT(0 2)", true, 1.0f
/3);
93 test_geometry
<bg::model::box
<P2dc
>, P2dc
>("POLYGON((0 1,2 4))", "POINT(3 4)", "POINT(0 2)", true, 1.0/3);
94 test_geometry
<bg::model::box
<P3ic
>, P3ic
>("POLYGON((0 1 2,2 4 6))", "POINT(3 5 6)", "POINT(0 3 3)", true, 1.0f
/2);
95 test_geometry
<bg::model::box
<P3fc
>, P3fc
>("POLYGON((0 1 2,2 4 6))", "POINT(3 5 6)", "POINT(0 3 3)", true, 1.0f
/2);
96 test_geometry
<bg::model::box
<P3dc
>, P3dc
>("POLYGON((0 1 2,2 4 6))", "POINT(3 5 6)", "POINT(0 3 3)", true, 1.0/2);
98 test_geometry
<bg::model::box
<P2ic
>, P2ic
>("POLYGON((0 1,2 4))", "POINT(1 0)", "POINT(1 5)", true, 1.0f
/5);
99 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(1 5)", "POINT(1 0)", true, 1.0f
/5);
100 test_geometry
<bg::model::box
<P2dc
>, P2dc
>("POLYGON((0 1,2 4))", "POINT(1 0)", "POINT(1 5)", true, 1.0/5);
101 test_geometry
<bg::model::box
<P3ic
>, P3ic
>("POLYGON((0 1 2,2 4 6))", "POINT(1 3 0)", "POINT(1 3 7)", true, 2.0f
/7);
102 test_geometry
<bg::model::box
<P3fc
>, P3fc
>("POLYGON((0 1 2,2 4 6))", "POINT(1 3 7)", "POINT(1 3 0)", true, 1.0f
/7);
103 test_geometry
<bg::model::box
<P3dc
>, P3dc
>("POLYGON((0 1 2,2 4 6))", "POINT(1 3 0)", "POINT(1 3 7)", true, 2.0/7);
105 test_geometry
<bg::model::box
<P2ic
>, P2ic
>("POLYGON((0 1,2 4))", "POINT(0 0)", "POINT(0 5)", true, 0.2f
);
106 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(0 5)", "POINT(0 0)", true, 0.2f
);
107 test_geometry
<bg::model::box
<P2dc
>, P2dc
>("POLYGON((0 1,2 4))", "POINT(0 0)", "POINT(0 5)", true, 0.2);
109 test_geometry
<bg::model::box
<P2ic
>, P2ic
>("POLYGON((0 1,2 4))", "POINT(3 0)", "POINT(3 5)", false, 0.0f
);
110 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(3 5)", "POINT(3 0)", false, 0.0f
);
111 test_geometry
<bg::model::box
<P2dc
>, P2dc
>("POLYGON((0 1,2 4))", "POINT(3 0)", "POINT(3 5)", false, 0.0);
113 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(1 0)", "POINT(1 1)", true, 1.0f
);
114 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(1 4)", "POINT(1 5)", true, 0.0f
);
116 test_geometry
<bg::model::box
<P2fc
>, P2fc
>("POLYGON((0 1,2 4))", "POINT(0.5 2)", "POINT(1.5 3)", true, 0.0f
);
119 typedef bg::model::point
<ttmath_big
, 2, bg::cs::cartesian
> P2ttmc
;
120 typedef bg::model::point
<ttmath_big
, 3, bg::cs::cartesian
> P3ttmc
;
122 test_geometry
<bg::model::box
<P2ttmc
>, P2ttmc
>("POLYGON((0 1,2 4))", "POINT(0 0)", "POINT(2 5)", true, 1.0f
/5);
123 test_geometry
<bg::model::box
<P3ttmc
>, P3ttmc
>("POLYGON((0 1 2,2 4 6))", "POINT(0 0 0)", "POINT(2 5 7)", true, 2.0f
/7);
126 test_large_integers();