PageRenderTime 18ms CodeModel.GetById 7ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/geometries/box.cpp

http://hadesmem.googlecode.com/
C++ | 105 lines | 75 code | 20 blank | 10 comment | 0 complexity | 19b26eed9a0d28b6ca52c09d5c84474f MD5 | raw file
  1// Boost.Geometry (aka GGL, Generic Geometry Library)
  2// Unit Test
  3
  4// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  5// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  6// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  7
  8// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
 10
 11// Use, modification and distribution is subject to the Boost Software License,
 12// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 13// http://www.boost.org/LICENSE_1_0.txt)
 14
 15
 16#include <geometry_test_common.hpp>
 17
 18#include <boost/geometry/algorithms/make.hpp>
 19
 20
 21#include <boost/geometry/geometries/point.hpp>
 22#include <boost/geometry/geometries/box.hpp>
 23#include <boost/geometry/geometries/adapted/c_array.hpp>
 24#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
 25#include <test_common/test_point.hpp>
 26
 27BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
 28BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
 29
 30
 31template <typename P>
 32bg::model::box<P> create_box()
 33{
 34    P p1;
 35    P p2;
 36    bg::assign_values(p1, 1, 2, 5);
 37    bg::assign_values(p2, 3, 4, 6);
 38    return bg::model::box<P>(p1, p2);
 39}
 40
 41template <typename B, typename T>
 42void check_box(B& to_check,
 43               T min_x, T min_y, T min_z,
 44               T max_x, T max_y, T max_z)
 45{
 46    BOOST_CHECK_EQUAL(bg::get<0>(to_check.min_corner()), min_x);
 47    BOOST_CHECK_EQUAL(bg::get<1>(to_check.min_corner()), min_y);
 48    BOOST_CHECK_EQUAL(bg::get<2>(to_check.min_corner()), min_z);
 49    BOOST_CHECK_EQUAL(bg::get<0>(to_check.max_corner()), max_x);
 50    BOOST_CHECK_EQUAL(bg::get<1>(to_check.max_corner()), max_y);
 51    BOOST_CHECK_EQUAL(bg::get<2>(to_check.max_corner()), max_z);
 52}
 53
 54template <typename P>
 55void test_construction()
 56{
 57    typedef typename bg::coordinate_type<P>::type T;
 58
 59    bg::model::box<P> b1 = bg::make_zero<bg::model::box<P> >();
 60    check_box(b1, T(),T(),T(),T(),T(),T());
 61
 62    bg::model::box<P> b2(create_box<P>());
 63    check_box(b2, 1,2,5,3,4,6);
 64
 65    bg::model::box<P> b3 = bg::make_inverse<bg::model::box<P> >();
 66    check_box(b3, boost::numeric::bounds<T>::highest(),
 67                  boost::numeric::bounds<T>::highest(),
 68                  boost::numeric::bounds<T>::highest(),
 69                  boost::numeric::bounds<T>::lowest(),
 70                  boost::numeric::bounds<T>::lowest(),
 71                  boost::numeric::bounds<T>::lowest());
 72}
 73
 74template <typename P>
 75void test_assignment()
 76{
 77    bg::model::box<P> b(create_box<P>());
 78    bg::set<0>(b.min_corner(), 10);
 79    bg::set<1>(b.min_corner(), 20);
 80    bg::set<2>(b.min_corner(), 30);
 81    bg::set<0>(b.max_corner(), 40);
 82    bg::set<1>(b.max_corner(), 50);
 83    bg::set<2>(b.max_corner(), 60);
 84    check_box(b, 10,20,30,40,50,60);
 85}
 86
 87template <typename P>
 88void test_all()
 89{
 90    test_construction<P>();
 91    test_assignment<P>();
 92}
 93
 94int test_main(int, char* [])
 95{
 96    test_all<int[3]>();
 97    test_all<float[3]>();
 98    test_all<double[3]>();
 99    test_all<test::test_point>();
100    test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
101    test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
102    test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
103
104    return 0;
105}