PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/algorithms/convert.cpp

http://hadesmem.googlecode.com/
C++ | 108 lines | 70 code | 26 blank | 12 comment | 0 complexity | 20190166e65b6555f09cf5a508512818 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#include <geometry_test_common.hpp>
 16
 17
 18#include <boost/geometry/algorithms/assign.hpp>
 19#include <boost/geometry/algorithms/convert.hpp>
 20#include <boost/geometry/algorithms/make.hpp>
 21#include <boost/geometry/algorithms/num_points.hpp>
 22
 23#include <boost/geometry/geometries/geometries.hpp>
 24#include <boost/geometry/geometries/adapted/c_array.hpp>
 25#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
 26#include <test_common/test_point.hpp>
 27
 28BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
 29BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
 30
 31
 32template <typename P>
 33void test_all()
 34{
 35    typedef bg::model::box<P> box_type;
 36
 37    P p;
 38    bg::assign_values(p, 1, 2);
 39
 40    box_type b;
 41    bg::convert(p, b);
 42
 43    BOOST_CHECK_CLOSE((bg::get<0, 0>(b)), 1.0, 0.001);
 44    BOOST_CHECK_CLOSE((bg::get<0, 1>(b)), 2.0, 0.001);
 45    BOOST_CHECK_CLOSE((bg::get<1, 0>(b)), 1.0, 0.001);
 46    BOOST_CHECK_CLOSE((bg::get<1, 1>(b)), 2.0, 0.001);
 47}
 48
 49template <typename P>
 50void test_std()
 51{
 52    test_all<P>();
 53
 54    typedef bg::model::box<P> box_type;
 55    typedef bg::model::ring<P> ring_type;
 56    typedef bg::model::polygon<P> polygon_type;
 57
 58    box_type b;
 59    bg::set<bg::min_corner, 0>(b, 1);
 60    bg::set<bg::min_corner, 1>(b, 2);
 61    bg::set<bg::max_corner, 0>(b, 3);
 62    bg::set<bg::max_corner, 1>(b, 4);
 63
 64    ring_type ring;
 65    bg::convert(b, ring);
 66
 67    //std::cout << bg::wkt(b) << std::endl;
 68    //std::cout << bg::wkt(ring) << std::endl;
 69
 70    typename boost::range_const_iterator<ring_type>::type it = ring.begin();
 71    BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
 72    BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
 73    it++;
 74    BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
 75    BOOST_CHECK_CLOSE(bg::get<1>(*it), 4.0, 0.001);
 76    it++;
 77    BOOST_CHECK_CLOSE(bg::get<0>(*it), 3.0, 0.001);
 78    BOOST_CHECK_CLOSE(bg::get<1>(*it), 4.0, 0.001);
 79    it++;
 80    BOOST_CHECK_CLOSE(bg::get<0>(*it), 3.0, 0.001);
 81    BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
 82    it++;
 83    BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
 84    BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
 85
 86    BOOST_CHECK_EQUAL(ring.size(), 5u);
 87
 88
 89    polygon_type polygon;
 90
 91    bg::convert(ring, polygon);
 92    BOOST_CHECK_EQUAL(bg::num_points(polygon), 5u);
 93
 94    bg::convert(polygon, ring);
 95    BOOST_CHECK_EQUAL(bg::num_points(ring), 5u);
 96}
 97
 98int test_main(int, char* [])
 99{
100    test_std<bg::model::point<int, 2, bg::cs::cartesian> >();
101    test_std<bg::model::point<float, 2, bg::cs::cartesian> >();
102    test_std<bg::model::point<double, 2, bg::cs::cartesian> >();
103
104#ifdef HAVE_TTMATH
105    test_std<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
106#endif
107    return 0;
108}