/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. // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <iterator>
  12. #include <algorithms/test_simplify.hpp>
  13. #include <boost/geometry/geometries/geometries.hpp>
  14. #include <boost/geometry/geometries/point_xy.hpp>
  15. #include <test_geometries/wrapped_boost_array.hpp>
  16. #include <test_common/test_point.hpp>
  17. template <typename P>
  18. void test_all()
  19. {
  20. test_geometry<bg::model::linestring<P> >(
  21. "LINESTRING(0 0,5 5,10 10)",
  22. "LINESTRING(0 0,10 10)", 1.0);
  23. test_geometry<bg::model::linestring<P> >(
  24. "LINESTRING(0 0, 5 5, 6 5, 10 10)",
  25. "LINESTRING(0 0,10 10)", 1.0);
  26. test_geometry<bg::model::linestring<P> >(
  27. "LINESTRING(0 0,5 5,7 5,10 10)",
  28. "LINESTRING(0 0,5 5,7 5,10 10)", 1.0);
  29. /* TODO fix this
  30. test_geometry<test::wrapped_boost_array<P, 10> >(
  31. "LINESTRING(0 0,5 5,7 5,10 10)",
  32. "LINESTRING(0 0,5 5,7 5,10 10)", 1.0);
  33. */
  34. test_geometry<bg::model::ring<P> >(
  35. "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
  36. "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
  37. test_geometry<bg::model::polygon<P> >(
  38. "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
  39. "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
  40. test_geometry<bg::model::polygon<P> >(
  41. "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))",
  42. "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);
  43. /*
  44. Above can be checked in PostGIS by:
  45. select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 10 10)'),1.0)) as simplified
  46. union all select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 6 5, 10 10)'),1.0))
  47. union all select astext(ST_Simplify(geomfromtext('LINESTRING(0 0, 5 5, 7 5, 10 10)'),1.0))
  48. 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))
  49. 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))
  50. */
  51. // Just check compilation
  52. test_geometry<P>(
  53. "POINT(0 0)",
  54. "POINT(0 0)", 1.0);
  55. test_geometry<bg::model::ring<P> >(
  56. "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,2 1,4 0))",
  57. "POLYGON((4 0,8 2,8 7,4 9,0 7,0 2,4 0))", 1.0);
  58. }
  59. template <typename P>
  60. void test_spherical()
  61. {
  62. test_geometry<bg::model::linestring<P> >(
  63. "LINESTRING(4.1 52.1,4.2 52.2,4.3 52.3)",
  64. "LINESTRING(4.1 52.1,4.3 52.3)", 0.01);
  65. }
  66. int test_main(int, char* [])
  67. {
  68. // Integer compiles, but simplify-process fails (due to distances)
  69. //test_all<bg::model::d2::point_xy<int> >();
  70. test_all<bg::model::d2::point_xy<float> >();
  71. test_all<bg::model::d2::point_xy<double> >();
  72. test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  73. #if defined(HAVE_TTMATH)
  74. test_all<bg::model::d2::point_xy<ttmath_big> >();
  75. test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  76. #endif
  77. return 0;
  78. }