PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 107 lines | 52 code | 27 blank | 28 comment | 0 complexity | e59ab6c4c9cef434e73b42bd5d3e10d2 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 <iterator>
 16
 17
 18#include <algorithms/test_simplify.hpp>
 19#include <boost/geometry/geometries/geometries.hpp>
 20#include <boost/geometry/geometries/point_xy.hpp>
 21
 22#include <test_geometries/wrapped_boost_array.hpp>
 23#include <test_common/test_point.hpp>
 24
 25
 26template <typename P>
 27void test_all()
 28{
 29    test_geometry<bg::model::linestring<P> >(
 30        "LINESTRING(0 0,5 5,10 10)",
 31        "LINESTRING(0 0,10 10)", 1.0);
 32
 33    test_geometry<bg::model::linestring<P> >(
 34        "LINESTRING(0 0, 5 5, 6 5, 10 10)",
 35        "LINESTRING(0 0,10 10)", 1.0);
 36
 37    test_geometry<bg::model::linestring<P> >(
 38        "LINESTRING(0 0,5 5,7 5,10 10)",
 39        "LINESTRING(0 0,5 5,7 5,10 10)", 1.0);
 40
 41    /* TODO fix this
 42    test_geometry<test::wrapped_boost_array<P, 10> >(
 43        "LINESTRING(0 0,5 5,7 5,10 10)",
 44        "LINESTRING(0 0,5 5,7 5,10 10)", 1.0);
 45    */
 46
 47    test_geometry<bg::model::ring<P> >(
 48        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
 49        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
 50
 51    test_geometry<bg::model::polygon<P> >(
 52        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
 53        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
 54
 55    test_geometry<bg::model::polygon<P> >(
 56        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0),(7 3,7 6,1 6,1 3,4 3,7 3))",
 57        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0),(7 3,7 6,1 6,1 3,7 3))", 1.0);
 58
 59/*
 60
 61Above can be checked in PostGIS by:
 62
 63select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 10 10)'),1.0)) as simplified
 64union all select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 6 5, 10 10)'),1.0))
 65union all select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 7 5, 10 10)'),1.0))
 66union all select astext(ST_Simplify(geomfromtext('POLYGON((4 0, 8 2, 8 7, 4 9, 0 7, 0 2, 2 1, 4 0))'),1.0))
 67union all select astext(ST_Simplify(geomfromtext('POLYGON((4 0, 8 2, 8 7, 4 9, 0 7, 0 2, 2 1, 4 0),(7 3, 7 6, 1 6, 1 3, 4 3, 7 3))'),1.0))
 68*/
 69
 70    // Just check compilation
 71    test_geometry<P>(
 72        "POINT(0 0)",
 73        "POINT(0 0)", 1.0);
 74
 75
 76    test_geometry<bg::model::ring<P> >(
 77        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
 78        "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
 79}
 80
 81
 82template <typename P>
 83void test_spherical()
 84{
 85    test_geometry<bg::model::linestring<P> >(
 86        "LINESTRING(4.1 52.1,4.2 52.2,4.3 52.3)",
 87        "LINESTRING(4.1 52.1,4.3 52.3)", 0.01);
 88}
 89
 90
 91int test_main(int, char* [])
 92{
 93    // Integer compiles, but simplify-process fails (due to distances)
 94    //test_all<bg::model::d2::point_xy<int> >();
 95
 96    test_all<bg::model::d2::point_xy<float> >();
 97    test_all<bg::model::d2::point_xy<double> >();
 98
 99    test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
100
101#if defined(HAVE_TTMATH)
102    test_all<bg::model::d2::point_xy<ttmath_big> >();
103    test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
104#endif
105
106    return 0;
107}