]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/geometries/box.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / geometries / box.cpp
CommitLineData
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
20effc67
TL
8// This file was modified by Oracle on 2020.
9// Modifications copyright (c) 2020, Oracle and/or its affiliates.
10// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
7c673cae
FG
12// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15// Use, modification and distribution is subject to the Boost Software License,
16// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17// http://www.boost.org/LICENSE_1_0.txt)
18
19
20#include <geometry_test_common.hpp>
21
22#include <boost/geometry/algorithms/make.hpp>
23
24
25#include <boost/geometry/geometries/point.hpp>
26#include <boost/geometry/geometries/box.hpp>
27#include <boost/geometry/geometries/adapted/c_array.hpp>
28#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
29#include <test_common/test_point.hpp>
30
31BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
32BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
33
34
35template <typename P>
36bg::model::box<P> create_box()
37{
38 P p1;
39 P p2;
40 bg::assign_values(p1, 1, 2, 5);
41 bg::assign_values(p2, 3, 4, 6);
42 return bg::model::box<P>(p1, p2);
43}
44
45template <typename B, typename T>
46void check_box(B& to_check,
47 T min_x, T min_y, T min_z,
48 T max_x, T max_y, T max_z)
49{
50 BOOST_CHECK_EQUAL(bg::get<0>(to_check.min_corner()), min_x);
51 BOOST_CHECK_EQUAL(bg::get<1>(to_check.min_corner()), min_y);
52 BOOST_CHECK_EQUAL(bg::get<2>(to_check.min_corner()), min_z);
53 BOOST_CHECK_EQUAL(bg::get<0>(to_check.max_corner()), max_x);
54 BOOST_CHECK_EQUAL(bg::get<1>(to_check.max_corner()), max_y);
55 BOOST_CHECK_EQUAL(bg::get<2>(to_check.max_corner()), max_z);
56}
57
58template <typename P>
59void test_construction()
60{
61 typedef typename bg::coordinate_type<P>::type T;
62
63 bg::model::box<P> b1 = bg::make_zero<bg::model::box<P> >();
64 check_box(b1, T(),T(),T(),T(),T(),T());
65
66 bg::model::box<P> b2(create_box<P>());
67 check_box(b2, 1,2,5,3,4,6);
68
69 bg::model::box<P> b3 = bg::make_inverse<bg::model::box<P> >();
70 check_box(b3, boost::numeric::bounds<T>::highest(),
71 boost::numeric::bounds<T>::highest(),
72 boost::numeric::bounds<T>::highest(),
73 boost::numeric::bounds<T>::lowest(),
74 boost::numeric::bounds<T>::lowest(),
75 boost::numeric::bounds<T>::lowest());
76}
77
78template <typename P>
79void test_assignment()
80{
81 bg::model::box<P> b(create_box<P>());
82 bg::set<0>(b.min_corner(), 10);
83 bg::set<1>(b.min_corner(), 20);
84 bg::set<2>(b.min_corner(), 30);
85 bg::set<0>(b.max_corner(), 40);
86 bg::set<1>(b.max_corner(), 50);
87 bg::set<2>(b.max_corner(), 60);
88 check_box(b, 10,20,30,40,50,60);
89}
90
20effc67
TL
91template <typename P>
92void test_constexpr()
93{
94 typedef bg::model::box<P> B;
95 constexpr B b = B{ {1, 2, 3}, {4, 5} };
96 constexpr auto c1 = bg::get<0, 0>(b);
97 constexpr auto c2 = bg::get<1, 2>(b);
98 BOOST_CHECK_EQUAL(c1, 1);
99 BOOST_CHECK_EQUAL(c2, 0);
100 check_box(b, 1, 2, 3, 4, 5, 0);
101}
102
7c673cae
FG
103template <typename P>
104void test_all()
105{
106 test_construction<P>();
107 test_assignment<P>();
108}
109
110int test_main(int, char* [])
111{
112 test_all<int[3]>();
113 test_all<float[3]>();
114 test_all<double[3]>();
115 test_all<test::test_point>();
116 test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
117 test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
118 test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
119
20effc67
TL
120 test_constexpr<bg::model::point<double, 3, bg::cs::cartesian> >();
121
7c673cae
FG
122 return 0;
123}