geometry/test/algorithms/simplify.cpp
Barend Gehrels db53e722db Removed traits::append_point.
The library now used std::back_insert_iterator everywhere

[SVN r64113]
2010-07-17 20:26:29 +00:00

97 lines
3.0 KiB
C++

// Boost.Geometry (aka GGL, Generic Geometry Library) test file
//
// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands
// Copyright Bruno Lalande 2008, 2009
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <iterator>
#include <algorithms/test_simplify.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <test_geometries/wrapped_boost_array.hpp>
#include <test_common/test_point.hpp>
template <typename P>
void test_all()
{
test_geometry<boost::geometry::linestring<P> >(
"LINESTRING(0 0,5 5,10 10)",
"LINESTRING(0 0,10 10)", 1.0);
test_geometry<boost::geometry::linestring<P> >(
"LINESTRING(0 0, 5 5, 6 5, 10 10)",
"LINESTRING(0 0,10 10)", 1.0);
test_geometry<boost::geometry::linestring<P> >(
"LINESTRING(0 0,5 5,7 5,10 10)",
"LINESTRING(0 0,5 5,7 5,10 10)", 1.0);
test_geometry<test::wrapped_boost_array<P, 10> >(
"LINESTRING(0 0,5 5,7 5,10 10)",
"LINESTRING(0 0,5 5,7 5,10 10)", 1.0);
test_geometry<boost::geometry::linear_ring<P> >(
"POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
"POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
test_geometry<boost::geometry::polygon<P> >(
"POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
"POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
test_geometry<boost::geometry::polygon<P> >(
"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))",
"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);
/*
Above can be checked in PostGIS by:
select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 10 10)'),1.0)) as simplified
union all select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 6 5, 10 10)'),1.0))
union all select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 7 5, 10 10)'),1.0))
union 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))
union 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))
*/
// Just check compilation
test_geometry<P>(
"POINT(0 0)",
"POINT(0 0)", 1.0);
test_geometry<boost::geometry::linear_ring<P> >(
"POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
"POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
}
template <typename P>
void test_spherical()
{
test_geometry<boost::geometry::linestring<P> >(
"LINESTRING(4.1 52.1,4.2 52.2,4.3 52.3)",
"LINESTRING(4.1 52.1,4.3 52.3)", 0.01);
}
int test_main(int, char* [])
{
// Integer compiles, but simplify-process fails (due to distances)
//test_all<boost::geometry::point_xy<int> >();
test_all<boost::geometry::point_xy<float> >();
test_all<boost::geometry::point_xy<double> >();
test_spherical<boost::geometry::point<double, 2, boost::geometry::cs::spherical<boost::geometry::degree> > >();
return 0;
}