convex_hull.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2015.
  7. // Modifications copyright (c) 2015 Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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. #include <cstddef>
  15. #include <string>
  16. #include <algorithms/test_convex_hull.hpp>
  17. #include <boost/geometry/geometries/geometries.hpp>
  18. #include <boost/geometry/geometries/point_xy.hpp>
  19. template <typename P>
  20. void test_all()
  21. {
  22. // from sample linestring
  23. test_geometry<bg::model::linestring<P> >(
  24. "linestring(1.1 1.1, 2.5 2.1, 3.1 3.1, 4.9 1.1, 3.1 1.9)", 5, 4, 3.8);
  25. // rectangular, with concavity
  26. test_geometry<bg::model::polygon<P> >(
  27. "polygon((1 1, 1 4, 3 4, 3 3, 4 3, 4 4, 5 4, 5 1, 1 1))",
  28. 9, 5, 12.0);
  29. // from sample polygon, with concavity
  30. test_geometry<bg::model::polygon<P> >(
  31. "polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6,3.4 2.0, 4.1 3.0"
  32. ", 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7,2.0 1.3))",
  33. 12, 8, 5.245);
  34. test_geometry<bg::model::ring<P> >(
  35. "polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6,3.4 2.0, 4.1 3.0"
  36. ", 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7,2.0 1.3))",
  37. 12, 8, 5.245);
  38. test_geometry<bg::model::box<P> >("box(0 0,2 2)", 4, 5, 4);
  39. // https://svn.boost.org/trac/boost/ticket/6443
  40. {
  41. test_geometry<bg::model::ring<P> >(
  42. "polygon((0 0, 2 0))", // note that this polygon is very invalid
  43. 2, 4, 0, 4);
  44. }
  45. // degenerated hulls
  46. test_geometry<bg::model::multi_point<P> >(
  47. "multipoint(0 0)",
  48. 1, 4, 0, 0);
  49. test_geometry<bg::model::multi_point<P> >(
  50. "multipoint(0 0, 2 0)",
  51. 2, 4, 0, 4);
  52. test_geometry<bg::model::linestring<P> >(
  53. "linestring(0 0, 2 0)",
  54. 2, 4, 0, 4);
  55. test_empty_input<bg::model::linestring<P> >();
  56. test_empty_input<bg::model::ring<P> >();
  57. test_empty_input<bg::model::polygon<P> >();
  58. }
  59. int test_main(int, char* [])
  60. {
  61. //test_all<bg::model::d2::point_xy<int> >();
  62. test_all<bg::model::d2::point_xy<float> >();
  63. test_all<bg::model::d2::point_xy<double> >();
  64. #if defined(HAVE_TTMATH)
  65. test_all<bg::model::d2::point_xy<ttmath_big> >();
  66. #endif
  67. return 0;
  68. }