]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/polygon/test/polygon_point_test.cpp
1 // Boost.Polygon library polygon_point_test.cpp file
3 // Copyright Andrii Sydorchuk 2012.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org for updates, documentation, and revision history.
10 #define BOOST_TEST_MODULE POLYGON_POINT_TEST
11 #include <boost/mpl/list.hpp>
12 #include <boost/test/test_case_template.hpp>
14 #include "boost/polygon/point_concept.hpp"
15 #include "boost/polygon/point_data.hpp"
16 #include "boost/polygon/point_traits.hpp"
17 using namespace boost::polygon
;
19 typedef boost::mpl::list
<int> test_types
;
21 BOOST_AUTO_TEST_CASE_TEMPLATE(point_data_test
, T
, test_types
) {
22 typedef point_data
<T
> point_type
;
24 point_type
point1(1, 2);
27 BOOST_CHECK_EQUAL(point1
.x(), 1);
28 BOOST_CHECK_EQUAL(point1
.y(), 2);
29 BOOST_CHECK_EQUAL(point2
.x(), 1);
30 BOOST_CHECK_EQUAL(point2
.y(), 2);
31 BOOST_CHECK(point1
== point2
);
32 BOOST_CHECK(!(point1
!= point2
));
33 BOOST_CHECK(!(point1
< point2
));
34 BOOST_CHECK(!(point1
> point2
));
35 BOOST_CHECK(point1
<= point2
);
36 BOOST_CHECK(point1
>= point2
);
40 BOOST_CHECK_EQUAL(point2
.x(), 2);
41 BOOST_CHECK_EQUAL(point2
.y(), 1);
42 BOOST_CHECK(!(point1
== point2
));
43 BOOST_CHECK(point1
!= point2
);
44 BOOST_CHECK(point1
< point2
);
45 BOOST_CHECK(!(point1
> point2
));
46 BOOST_CHECK(point1
<= point2
);
47 BOOST_CHECK(!(point1
>= point2
));
49 point2
.set(HORIZONTAL
, 1);
50 point2
.set(VERTICAL
, 2);
51 BOOST_CHECK(point1
== point2
);
54 BOOST_AUTO_TEST_CASE_TEMPLATE(point_traits_test
, T
, test_types
) {
55 typedef point_data
<T
> point_type
;
57 point_type point
= point_mutable_traits
<point_type
>::construct(1, 2);
58 BOOST_CHECK_EQUAL(point_traits
<point_type
>::get(point
, HORIZONTAL
), 1);
59 BOOST_CHECK_EQUAL(point_traits
<point_type
>::get(point
, VERTICAL
), 2);
61 point_mutable_traits
<point_type
>::set(point
, HORIZONTAL
, 3);
62 point_mutable_traits
<point_type
>::set(point
, VERTICAL
, 4);
63 BOOST_CHECK_EQUAL(point_traits
<point_type
>::get(point
, HORIZONTAL
), 3);
64 BOOST_CHECK_EQUAL(point_traits
<point_type
>::get(point
, VERTICAL
), 4);
76 struct geometry_concept
< Point
<T
> > {
77 typedef point_concept type
;
81 struct point_traits
< Point
<T
> > {
82 typedef T coordinate_type
;
84 static coordinate_type
get(const Point
<T
>& point
, orientation_2d orient
) {
85 return (orient
== HORIZONTAL
) ? point
.x
: point
.y
;
90 struct point_mutable_traits
< Point
<T
> > {
91 typedef T coordinate_type
;
93 static void set(Point
<T
>& point
, orientation_2d orient
, T value
) {
94 (orient
== HORIZONTAL
) ? point
.x
= value
: point
.y
= value
;
97 static Point
<T
> construct(coordinate_type x
, coordinate_type y
) {
107 BOOST_AUTO_TEST_CASE_TEMPLATE(point_concept_test1
, T
, test_types
) {
108 typedef Point
<T
> point_type
;
110 point_type point1
= construct
<point_type
>(1, 2);
111 BOOST_CHECK_EQUAL(point1
.x
, 1);
112 BOOST_CHECK_EQUAL(point1
.y
, 2);
114 set(point1
, HORIZONTAL
, 3);
115 set(point1
, VERTICAL
, 4);
116 BOOST_CHECK_EQUAL(get(point1
, HORIZONTAL
), 3);
117 BOOST_CHECK_EQUAL(get(point1
, VERTICAL
), 4);
120 assign(point2
, point1
);
121 BOOST_CHECK(equivalence(point1
, point2
));
125 BOOST_CHECK_EQUAL(x(point2
), 1);
126 BOOST_CHECK_EQUAL(y(point2
), 2);
129 BOOST_AUTO_TEST_CASE_TEMPLATE(point_concept_test2
, T
, test_types
) {
130 typedef Point
<T
> point_type
;
132 point_type point1
= construct
<point_type
>(1, 2);
133 point_type point2
= construct
<point_type
>(5, 5);
134 BOOST_CHECK_EQUAL(euclidean_distance(point1
, point2
, HORIZONTAL
), 4);
135 BOOST_CHECK_EQUAL(euclidean_distance(point1
, point2
, VERTICAL
), 3);
136 BOOST_CHECK_EQUAL(manhattan_distance(point1
, point2
), 7);
137 BOOST_CHECK_EQUAL(euclidean_distance(point1
, point2
), 5.0);
140 BOOST_AUTO_TEST_CASE_TEMPLATE(point_concept_test3
, T
, test_types
) {
141 typedef Point
<T
> point_type
;
143 point_type point
= construct
<point_type
>(1, 2);
144 point_type shift
= construct
<point_type
>(4, 3);
145 convolve(point
, shift
);
146 BOOST_CHECK_EQUAL(x(point
), 5);
147 BOOST_CHECK_EQUAL(y(point
), 5);
149 deconvolve(point
, shift
);
150 BOOST_CHECK_EQUAL(x(point
), 1);
151 BOOST_CHECK_EQUAL(y(point
), 2);
154 BOOST_CHECK_EQUAL(x(point
), 5);
155 BOOST_CHECK_EQUAL(y(point
), 10);
157 scale_down(point
, 5);
158 BOOST_CHECK_EQUAL(x(point
), 1);
159 BOOST_CHECK_EQUAL(y(point
), 2);
161 move(point
, HORIZONTAL
, 2);
162 move(point
, VERTICAL
, 3);
163 BOOST_CHECK_EQUAL(x(point
), 3);
164 BOOST_CHECK_EQUAL(y(point
), 5);
169 void scale(T
& x
, T
& y
) const {
174 void transform(T
& x
, T
& y
) const {
181 BOOST_AUTO_TEST_CASE_TEMPLATE(point_concept_test4
, T
, test_types
) {
182 typedef Point
<T
> point_type
;
184 point_type point
= construct
<point_type
>(1, 2);
185 scale(point
, Transformer
<T
>());
186 BOOST_CHECK_EQUAL(x(point
), 2);
187 BOOST_CHECK_EQUAL(y(point
), 4);
189 transform(point
, Transformer
<T
>());
190 BOOST_CHECK_EQUAL(x(point
), 4);
191 BOOST_CHECK_EQUAL(y(point
), 2);