diff options
Diffstat (limited to 'src/boost/libs/geometry/test/geometries')
14 files changed, 1477 insertions, 0 deletions
diff --git a/src/boost/libs/geometry/test/geometries/Jamfile.v2 b/src/boost/libs/geometry/test/geometries/Jamfile.v2 new file mode 100644 index 00000000..15f8c60c --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/Jamfile.v2 @@ -0,0 +1,31 @@ +# Boost.Geometry +# +# Copyright (c) 2007-2019 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2019 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2019 Mateusz Loskot, London, UK. +# Copyright (c) 2014-2019 Adam Wulkiewicz, Lodz, Poland. + +# 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) + +test-suite boost-geometry-geometries + : + [ run adapted.cpp : : : : geometries_adapted ] + [ run boost_array_as_point.cpp : : : : geometries_boost_array_as_point ] + [ run boost_fusion.cpp : : : : geometries_boost_fusion ] + [ run boost_polygon.cpp : : : : geometries_boost_polygon ] + [ run boost_range.cpp : : : : geometries_boost_range ] + [ run boost_tuple.cpp : : : : geometries_boost_tuple ] + [ run box.cpp : : : : geometries_box ] + #[ compile-fail custom_linestring.cpp + # : # requirements + # <define>TEST_FAIL_CLEAR + # : # target name + # geometries_custom_linestring_test_fail_clear + #] + [ run custom_linestring.cpp : : : : geometries_custom_linestring ] + [ run initialization.cpp : : : : geometries_initialization ] + [ run segment.cpp : : : : geometries_segment ] + [ run infinite_line.cpp : : : : geometries_infinite_line ] + ; diff --git a/src/boost/libs/geometry/test/geometries/adapted.cpp b/src/boost/libs/geometry/test/geometries/adapted.cpp new file mode 100644 index 00000000..17331439 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/adapted.cpp @@ -0,0 +1,112 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// 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 <deque> +#include <vector> + +#include <geometry_test_common.hpp> +#include <boost/core/ignore_unused.hpp> + +#include <boost/geometry/geometries/geometries.hpp> + +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +#include <test_common/test_point.hpp> + +#define BOOST_GEOMETRY_TEST_RING + + + +#if defined(BOOST_GEOMETRY_TEST_RING) + + #include <boost/geometry/geometries/register/ring.hpp> + #include <boost/geometry/geometries/concepts/ring_concept.hpp> + + BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(std::vector) + BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(std::deque) + +#elif defined(BOOST_GEOMETRY_TEST_MULTI_POINT) + + #include <boost/geometry/geometries/register/multi_point.hpp> + #include <boost/geometry/geometries/concepts/multi_point_concept.hpp> + + BOOST_GEOMETRY_REGISTER_MULTI_POINT_TEMPLATED(std::vector) + BOOST_GEOMETRY_REGISTER_MULTI_POINT_TEMPLATED(std::deque) + +#else + + #include <boost/geometry/geometries/register/linestring.hpp> + #include <boost/geometry/geometries/concepts/linestring_concept.hpp> + + BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector) + BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque) + +#endif + + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +// ---------------------------------------------------------------------------- + +template <typename G> +void test_geometry(G const& geometry, std::size_t expected_size = 0) +{ +#if defined(BOOST_GEOMETRY_TEST_RING) + BOOST_CONCEPT_ASSERT( (bg::concepts::ConstRing<G>) ); +#elif defined(BOOST_GEOMETRY_TEST_MULTI_POINT) + BOOST_CONCEPT_ASSERT( (bg::concepts::ConstMultiPoint<G>) ); +#else + BOOST_CONCEPT_ASSERT( (bg::concepts::ConstLinestring<G>) ); +#endif + + typedef typename bg::point_type<G>::type P; + typedef typename bg::coordinate_type<P>::type C; + boost::ignore_unused<P, C>(); + + // Check range-like behaviour + BOOST_CHECK_EQUAL(boost::size(geometry), expected_size); +} + +template <typename P> +void test_all() +{ + test_geometry(std::vector<P>()); + test_geometry(std::deque<P>()); + //test_geometry(std::list<P>()); + + /*** + double vertices[][3] = { + {-1, -1, 1}, {1, -1, 1}, {1, 1, 1}, {-1, 1, 1}, + {-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1} + }; + + test_geometry(vertices, 8); + ***/ +} + +int test_main(int, char* []) +{ + test_all<test::test_point>(); + test_all<boost::tuple<float, float> >(); + test_all<bg::model::point<int, 2, bg::cs::cartesian> >(); + test_all<bg::model::point<float, 2, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 2, bg::cs::cartesian> >(); + test_all<bg::model::point<long double, 2, bg::cs::cartesian> >(); + + test_all<boost::tuple<float, float, float> >(); + test_all<bg::model::point<double, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<long double, 3, bg::cs::cartesian> >(); + + test_all<boost::tuple<float, float, float, float, float> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/geometries/boost_array_as_point.cpp b/src/boost/libs/geometry/test/geometries/boost_array_as_point.cpp new file mode 100644 index 00000000..1cd49bf6 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/boost_array_as_point.cpp @@ -0,0 +1,50 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010 Alfredo Correa +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// 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 <boost/config.hpp> +#include <geometry_test_common.hpp> + +#include<boost/geometry/geometry.hpp> +#include<boost/geometry/geometries/adapted/boost_array.hpp> +#include<boost/geometry/geometries/adapted/c_array.hpp> +#include<boost/geometry/geometries/adapted/boost_tuple.hpp> +#include<iostream> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#include<boost/geometry/geometries/adapted/std_array.hpp> +BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(cs::cartesian) +#endif //BOOST_NO_CXX11_HDR_ARRAY + +int test_main(int, char* []) +{ + bg::model::point<double, 3, bg::cs::cartesian> p1(1,2,3); + double p2[3] = {4,5,6}; + boost::tuple<double, double, double> p3(7,8,9); + boost::array<double, 3> p4 = {{10,11,12}}; + std::clog << bg::distance(p1, p2) << std::endl; + std::clog << bg::distance(p2, p3) << std::endl; + std::clog << bg::distance(p3, p4) << std::endl; + +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + std::array<double, 3> p5 = {13,14,15}; +#else + std::array<double, 3> p5; p5[0] = 13; p5[1] = 14; p5[2] = 15; +#endif // BOOST_NO_CXX11_HDR_INITIALIZER_LIST + std::clog << bg::distance(p4, p5) << std::endl; +#endif //BOOST_NO_CXX11_HDR_ARRAY + + return 0; +} + diff --git a/src/boost/libs/geometry/test/geometries/boost_fusion.cpp b/src/boost/libs/geometry/test/geometries/boost_fusion.cpp new file mode 100644 index 00000000..38a4a05f --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/boost_fusion.cpp @@ -0,0 +1,71 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright Akira Takahashi 2011 + +// 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 <geometry_test_common.hpp> + +#include <boost/fusion/include/adapt_struct_named.hpp> + +#include <boost/geometry/geometry.hpp> +#include <boost/geometry/geometries/adapted/boost_fusion.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <iostream> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +struct for_fusion_2d +{ + float x,y; +}; +struct for_fusion_3d +{ + double x,y,z; +}; + +BOOST_FUSION_ADAPT_STRUCT(for_fusion_2d, (float, x) (float, y)) +BOOST_FUSION_ADAPT_STRUCT(for_fusion_3d, (double, x) (double, y) (double, z)) + + +void test_2d() +{ + bg::model::point<double, 2, bg::cs::cartesian> p1(1, 2); + double p2[2] = {3, 4}; + boost::tuple<double, double> p3(5,6); + + for_fusion_2d pf = {7, 8}; + + BOOST_CHECK_CLOSE(bg::distance(p1, pf), 8.4852813742385695, 0.01); + BOOST_CHECK_CLOSE(bg::distance(p2, pf), 5.6568542494923806, 0.01); + BOOST_CHECK_CLOSE(bg::distance(p3, pf), 2.82843, 0.01); +} + +void test_3d() +{ + bg::model::point<double, 3, bg::cs::cartesian> p1(1, 2, 3); + double p2[3] = {4, 5, 6}; + boost::tuple<double, double, double> p3(7, 8, 9); + + for_fusion_3d pf = {10, 11, 12}; + + BOOST_CHECK_CLOSE(bg::distance(p1, pf), 15.58845726811, 0.01); + BOOST_CHECK_CLOSE(bg::distance(p2, pf), 10.392304845413, 0.01); + BOOST_CHECK_CLOSE(bg::distance(p3, pf), 5.196152, 0.01); +} + +int test_main(int, char* []) +{ + test_2d(); + test_3d(); + return 0; +} + diff --git a/src/boost/libs/geometry/test/geometries/boost_polygon.cpp b/src/boost/libs/geometry/test/geometries/boost_polygon.cpp new file mode 100644 index 00000000..c535b22d --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/boost_polygon.cpp @@ -0,0 +1,174 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// 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) + +// geometry::num_points does not accept the ring_proxy for adaptation, like +// centroid and probably many more algorithms. TODO: fix that. Until then we +// define it such that num_points is not called. +#define BOOST_GEOMETRY_EMPTY_INPUT_NO_THROW + +#include <geometry_test_common.hpp> + + +#include <boost/geometry/geometry.hpp> + +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/ring.hpp> + +#include <boost/geometry/geometries/adapted/boost_polygon/point.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/box.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/ring.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/polygon.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <iostream> + +template <typename T> +void fill_polygon_with_two_holes(boost::polygon::polygon_with_holes_data<T>& boost_polygon_polygon) +{ + std::vector<boost::polygon::point_data<T> > point_vector; + point_vector.push_back(boost::polygon::point_data<T>(0, 0)); + point_vector.push_back(boost::polygon::point_data<T>(0, 10)); + point_vector.push_back(boost::polygon::point_data<T>(10, 10)); + point_vector.push_back(boost::polygon::point_data<T>(10, 0)); + point_vector.push_back(boost::polygon::point_data<T>(0, 0)); + boost_polygon_polygon.set(point_vector.begin(), point_vector.end()); + + + std::vector<boost::polygon::polygon_data<T> > holes; + holes.resize(2); + + { + std::vector<boost::polygon::point_data<T> > point_vector; + point_vector.push_back(boost::polygon::point_data<T>(1, 1)); + point_vector.push_back(boost::polygon::point_data<T>(2, 1)); + point_vector.push_back(boost::polygon::point_data<T>(2, 2)); + point_vector.push_back(boost::polygon::point_data<T>(1, 2)); + point_vector.push_back(boost::polygon::point_data<T>(1, 1)); + holes[0].set(point_vector.begin(), point_vector.end()); + } + + { + std::vector<boost::polygon::point_data<T> > point_vector; + point_vector.push_back(boost::polygon::point_data<T>(3, 3)); + point_vector.push_back(boost::polygon::point_data<T>(4, 3)); + point_vector.push_back(boost::polygon::point_data<T>(4, 4)); + point_vector.push_back(boost::polygon::point_data<T>(3, 4)); + point_vector.push_back(boost::polygon::point_data<T>(3, 3)); + holes[1].set(point_vector.begin(), point_vector.end()); + } + boost_polygon_polygon.set_holes(holes.begin(), holes.end()); +} + + +template <typename T> +void test_coordinate_type() +{ + // 1a: Check if Boost.Polygon's point fulfills Boost.Geometry's point concept + bg::concepts::check<boost::polygon::point_data<T> >(); + + // 1b: use a Boost.Polygon point in Boost.Geometry, calc. distance with two point types + boost::polygon::point_data<T> boost_polygon_point(1, 2); + + typedef bg::model::point<T, 2, bg::cs::cartesian> bg_point_type; + bg_point_type boost_geometry_point(3, 4); + BOOST_CHECK_EQUAL(bg::distance(boost_polygon_point, boost_geometry_point), + 2 * std::sqrt(2.0)); + + // 2a: Check if Boost.Polygon's box fulfills Boost.Geometry's box concept + bg::concepts::check<boost::polygon::rectangle_data<T> >(); + + // 2b: use a Boost.Polygon rectangle in Boost.Geometry, compare with boxes + boost::polygon::rectangle_data<T> boost_polygon_box; + bg::model::box<bg_point_type> boost_geometry_box; + + bg::assign_values(boost_polygon_box, 0, 1, 5, 6); + bg::assign_values(boost_geometry_box, 0, 1, 5, 6); + T boost_polygon_area = bg::area(boost_polygon_box); + T boost_geometry_area = bg::area(boost_geometry_box); + T boost_polygon_area_by_boost_polygon = boost::polygon::area(boost_polygon_box); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_geometry_area); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_polygon_area_by_boost_polygon); + + // 3a: Check if Boost.Polygon's polygon fulfills Boost.Geometry's ring concept + bg::concepts::check<boost::polygon::polygon_data<T> >(); + + // 3b: use a Boost.Polygon polygon (ring) + boost::polygon::polygon_data<T> boost_polygon_ring; + { + // Filling it is a two-step process using Boost.Polygon + std::vector<boost::polygon::point_data<T> > point_vector; + point_vector.push_back(boost::polygon::point_data<T>(0, 0)); + point_vector.push_back(boost::polygon::point_data<T>(0, 3)); + point_vector.push_back(boost::polygon::point_data<T>(4, 0)); + point_vector.push_back(boost::polygon::point_data<T>(0, 0)); + boost_polygon_ring.set(point_vector.begin(), point_vector.end()); + } + + // Boost-geometry ring + bg::model::ring<bg_point_type> boost_geometry_ring; + { + boost_geometry_ring.push_back(bg_point_type(0, 0)); + boost_geometry_ring.push_back(bg_point_type(0, 3)); + boost_geometry_ring.push_back(bg_point_type(4, 0)); + boost_geometry_ring.push_back(bg_point_type(0, 0)); + } + boost_polygon_area = bg::area(boost_polygon_ring); + boost_geometry_area = bg::area(boost_geometry_ring); + boost_polygon_area_by_boost_polygon = boost::polygon::area(boost_polygon_ring); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_geometry_area); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_polygon_area_by_boost_polygon); + + // Check mutable ring + std::string wkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))"; + bg::read_wkt(wkt, boost_polygon_ring); + bg::read_wkt(wkt, boost_geometry_ring); + boost_polygon_area = bg::area(boost_polygon_ring); + boost_geometry_area = bg::area(boost_geometry_ring); + boost_polygon_area_by_boost_polygon = boost::polygon::area(boost_polygon_ring); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_geometry_area); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_polygon_area_by_boost_polygon); + + // 4a: Boost.Polygon's polygon with holes + boost::polygon::polygon_with_holes_data<T> boost_polygon_polygon; + fill_polygon_with_two_holes(boost_polygon_polygon); + + // Using Boost.Polygon + boost_polygon_area = bg::area(boost_polygon_polygon); + boost_polygon_area_by_boost_polygon = boost::polygon::area(boost_polygon_polygon); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_polygon_area_by_boost_polygon); + + wkt = "POLYGON((0 0,0 10,10 10,10 0,0 0),(1 1,2 1,2 2,1 2,1 1),(3 3,4 3,4 4,3 4,3 3))"; + + bg::model::polygon<bg_point_type> boost_geometry_polygon; + bg::read_wkt(wkt, boost_geometry_polygon); + + boost_geometry_area = bg::area(boost_geometry_polygon); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_geometry_area); + + bg::clear(boost_polygon_polygon); + bg::read_wkt(wkt, boost_polygon_polygon); + boost_geometry_area = bg::area(boost_polygon_polygon); + BOOST_CHECK_EQUAL(boost_polygon_area, boost_geometry_area); + + std::ostringstream out; + out << bg::wkt(boost_polygon_polygon); + BOOST_CHECK_EQUAL(wkt, out.str()); + +} + +int test_main(int, char* []) +{ + test_coordinate_type<int>(); + //test_coordinate_type<float>(); // compiles, but "BOOST_CHECK_EQUAL" fails + test_coordinate_type<double>(); + return 0; +} diff --git a/src/boost/libs/geometry/test/geometries/boost_polygon_overlay.cpp b/src/boost/libs/geometry/test/geometries/boost_polygon_overlay.cpp new file mode 100644 index 00000000..f7db7735 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/boost_polygon_overlay.cpp @@ -0,0 +1,122 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// 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 <geometry_test_common.hpp> + + +#include <boost/geometry/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/point.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/box.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/ring.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +#include<iostream> + +template <typename T> +void test_overlay_using_boost_polygon(std::string const& case_id, std::string const& wkt_p, std::string const& wkt_q) +{ + typedef boost::polygon::polygon_set_data<T> polygon_set; + + polygon_set p, q; + polygon_set out_i, out_u; + + { + // Read polygons, conveniently using Boost.Geometry + typedef boost::geometry::model::multi_polygon + < + boost::polygon::polygon_with_holes_data<T> + > mp_type; + mp_type mp, mq; + + bg::read_wkt(wkt_p, mp); + bg::read_wkt(wkt_q, mq); + + p.insert(mp.begin(), mp.end()); + q.insert(mq.begin(), mq.end()); + } + + { + using namespace boost::polygon::operators; + out_i = p & q; + out_u = p | q; + } + + double area_p = boost::polygon::area(p); + double area_q = boost::polygon::area(q); + double area_i = boost::polygon::area(out_i); + double area_u = boost::polygon::area(out_u); + + double sum = area_p + area_q - area_u - area_i; + BOOST_CHECK_MESSAGE(abs(sum) < 0.001, + "Overlay error\n" + << "Boost.Polygon " << case_id + << " area p: " << area_p + << " area q: " << area_q + << " area i: " << area_i + << " area u: " << area_u + << " sum: " << sum + ); +} + + +template <typename T> +void test_overlay_using_boost_geometry(std::string const& case_id, std::string const& wkt_p, std::string const& wkt_q) +{ + typedef boost::geometry::model::multi_polygon + < + boost::geometry::model::polygon + < + boost::geometry::model::d2::point_xy<T> + > + > mp_type; + + // Read it using Boost.Geometry + mp_type p, q, out_i, out_u; + + boost::geometry::read_wkt(wkt_p, p); + boost::geometry::read_wkt(wkt_q, q); + + boost::geometry::intersection(p, q, out_i); + boost::geometry::union_(p, q, out_u); + + double area_p = boost::geometry::area(p); + double area_q = boost::geometry::area(q); + double area_i = boost::geometry::area(out_i); + double area_u = boost::geometry::area(out_u); + + double sum = area_p + area_q - area_u - area_i; + BOOST_CHECK_MESSAGE(abs(sum) < 0.001, + "Overlay error\n" + << "Boost.Geometry " << case_id + << " area p: " << area_p + << " area q: " << area_q + << " area i: " << area_i + << " area u: " << area_u + << " sum: " << sum + ); +} + +template <typename T> +void test_overlay(std::string const& case_id, std::string const& wkt_p, std::string const& wkt_q) +{ + test_overlay_using_boost_polygon<T>(case_id, wkt_p, wkt_q); + test_overlay_using_boost_geometry<T>(case_id, wkt_p, wkt_q); +} + + +int test_main(int, char* []) +{ + test_overlay<int>("case 1", "MULTIPOLYGON(((100 900,0 800,100 800,100 900)),((200 700,100 800,100 700,200 700)),((500 400,400 400,400 300,500 400)),((600 300,500 200,600 200,600 300)),((600 700,500 800,500 700,600 700)),((700 500,600 500,600 400,700 500)),((900 300,800 400,800 300,900 300)))", + "MULTIPOLYGON(((200 900,100 1000,100 800,200 800,200 900)),((400 500,300 600,300 500,400 500)),((500 900,400 800,500 800,500 900)),((600 800,500 700,600 700,600 800)),((700 500,600 400,700 400,700 500)),((1000 1000,900 900,1000 900,1000 1000)))"); + test_overlay<int>("case 2", "MULTIPOLYGON(((200 400,100 400,100 300,200 400)),((300 100,200 100,200 0,300 0,300 100)),((600 700,500 700,500 600,600 700)),((700 300,600 300,600 200,700 300)),((800 500,700 600,700 500,800 500)),((900 800,800 700,900 700,900 800)),((1000 200,900 100,1000 100,1000 200)),((1000 800,900 900,900 800,1000 800)))", + "MULTIPOLYGON(((200 800,100 800,100 700,200 700,200 800)),((400 200,300 100,400 100,400 200)),((400 800,300 700,400 700,400 800)),((700 100,600 0,700 0,700 100)),((700 200,600 200,600 100,700 200)),((900 200,800 200,800 0,900 0,900 200)),((1000 300,900 200,1000 200,1000 300)))"); + return 0; +} diff --git a/src/boost/libs/geometry/test/geometries/boost_range.cpp b/src/boost/libs/geometry/test/geometries/boost_range.cpp new file mode 100644 index 00000000..d2a2ff5d --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/boost_range.cpp @@ -0,0 +1,123 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// 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 <geometry_test_common.hpp> + + +#include <boost/geometry/geometry.hpp> +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/adapted/boost_range/adjacent_filtered.hpp> +#include <boost/geometry/geometries/adapted/boost_range/filtered.hpp> +#include <boost/geometry/geometries/adapted/boost_range/reversed.hpp> +#include <boost/geometry/geometries/adapted/boost_range/strided.hpp> +#include <boost/geometry/geometries/adapted/boost_range/sliced.hpp> +#include <boost/geometry/geometries/adapted/boost_range/uniqued.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <sstream> + +#ifdef BOOST_GEOMETRY_TEST_QUARANTINED +struct not_two +{ + template <typename P> + bool operator()(P const& p) const + { + return boost::geometry::get<0>(p) != 2.0; + } +}; + +struct sum_not_five +{ + template <typename P> + bool operator()(P const& p1, P const& p2) const + { + return boost::geometry::get<0>(p1) + boost::geometry::get<0>(p2) != 5.0; + } +}; +#endif + + +template <typename P> +void test_range_adaptor() +{ + bg::model::linestring<P> ls; + bg::read_wkt("LINESTRING(1 1,2 2,3 3,4 4)", ls); + + { + std::ostringstream out; + out << bg::wkt(ls); + BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)"); + } + + { + std::ostringstream out; + out << bg::wkt(ls | boost::adaptors::reversed); + BOOST_CHECK_EQUAL(out.str(), "LINESTRING(4 4,3 3,2 2,1 1)"); + } + + { + std::ostringstream out; + out << bg::wkt(ls | boost::adaptors::strided(2)); + BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3)"); + } + + { + std::ostringstream out; + out << bg::wkt(ls | boost::adaptors::sliced(1,3)); + BOOST_CHECK_EQUAL(out.str(), "LINESTRING(2 2,3 3)"); + } + +#ifdef BOOST_GEOMETRY_TEST_QUARANTINED +// range filter adaptor does not support boost::size() +// This makes it in practice not applicable, boost::geometry calls boost::size +// in most if not all algorithms + { + std::ostringstream out; + out << bg::wkt(ls | boost::adaptors::filtered(not_two())); + BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)"); + } + + { + std::ostringstream out; + out << bg::wkt(ls | boost::adaptors::adjacent_filtered(sum_not_five())); + BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,3 3,4 4)"); + } + + { + bg::model::linestring<P> ls2; + bg::read_wkt("LINESTRING(1 1,1 1,2 2,3 3,3 3,4 4)", ls2); + std::ostringstream out; + + + // uniqued needs == operator, equals + //out << bg::wkt(ls | boost::adaptors::uniqued); + //BOOST_CHECK_EQUAL(out.str(), "LINESTRING(1 1,2 2,3 3,4 4)"); + } +#endif +} + +template <typename P> +void test_all() +{ + test_range_adaptor<P>(); +} + + + +int test_main(int, char* []) +{ + test_all<bg::model::d2::point_xy<double> >(); + test_all<bg::model::point<int, 2, bg::cs::cartesian> >(); + + return 0; + } + diff --git a/src/boost/libs/geometry/test/geometries/boost_tuple.cpp b/src/boost/libs/geometry/test/geometries/boost_tuple.cpp new file mode 100644 index 00000000..b6db1f02 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/boost_tuple.cpp @@ -0,0 +1,39 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. + +// 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 <geometry_test_common.hpp> +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <boost/geometry/algorithms/distance.hpp> +#include <boost/geometry/strategies/strategies.hpp> + +#include <iostream> + + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +template <typename P> +void test_all() +{ + P p1, p2; + bg::distance(p1, p2); +} + +int test_main(int, char* []) +{ + test_all<boost::tuple<float> >(); + test_all<boost::tuple<int, int> >(); + test_all<boost::tuple<double, double, double> >(); + test_all<boost::tuple<float, float, float, float> >(); + test_all<boost::tuple<float, float, float, float, float> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/geometries/box.cpp b/src/boost/libs/geometry/test/geometries/box.cpp new file mode 100644 index 00000000..5e1fdaae --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/box.cpp @@ -0,0 +1,105 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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 <geometry_test_common.hpp> + +#include <boost/geometry/algorithms/make.hpp> + + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <test_common/test_point.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +template <typename P> +bg::model::box<P> create_box() +{ + P p1; + P p2; + bg::assign_values(p1, 1, 2, 5); + bg::assign_values(p2, 3, 4, 6); + return bg::model::box<P>(p1, p2); +} + +template <typename B, typename T> +void check_box(B& to_check, + T min_x, T min_y, T min_z, + T max_x, T max_y, T max_z) +{ + BOOST_CHECK_EQUAL(bg::get<0>(to_check.min_corner()), min_x); + BOOST_CHECK_EQUAL(bg::get<1>(to_check.min_corner()), min_y); + BOOST_CHECK_EQUAL(bg::get<2>(to_check.min_corner()), min_z); + BOOST_CHECK_EQUAL(bg::get<0>(to_check.max_corner()), max_x); + BOOST_CHECK_EQUAL(bg::get<1>(to_check.max_corner()), max_y); + BOOST_CHECK_EQUAL(bg::get<2>(to_check.max_corner()), max_z); +} + +template <typename P> +void test_construction() +{ + typedef typename bg::coordinate_type<P>::type T; + + bg::model::box<P> b1 = bg::make_zero<bg::model::box<P> >(); + check_box(b1, T(),T(),T(),T(),T(),T()); + + bg::model::box<P> b2(create_box<P>()); + check_box(b2, 1,2,5,3,4,6); + + bg::model::box<P> b3 = bg::make_inverse<bg::model::box<P> >(); + check_box(b3, boost::numeric::bounds<T>::highest(), + boost::numeric::bounds<T>::highest(), + boost::numeric::bounds<T>::highest(), + boost::numeric::bounds<T>::lowest(), + boost::numeric::bounds<T>::lowest(), + boost::numeric::bounds<T>::lowest()); +} + +template <typename P> +void test_assignment() +{ + bg::model::box<P> b(create_box<P>()); + bg::set<0>(b.min_corner(), 10); + bg::set<1>(b.min_corner(), 20); + bg::set<2>(b.min_corner(), 30); + bg::set<0>(b.max_corner(), 40); + bg::set<1>(b.max_corner(), 50); + bg::set<2>(b.max_corner(), 60); + check_box(b, 10,20,30,40,50,60); +} + +template <typename P> +void test_all() +{ + test_construction<P>(); + test_assignment<P>(); +} + +int test_main(int, char* []) +{ + test_all<int[3]>(); + test_all<float[3]>(); + test_all<double[3]>(); + test_all<test::test_point>(); + test_all<bg::model::point<int, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<float, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 3, bg::cs::cartesian> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/geometries/concepts/check.cpp b/src/boost/libs/geometry/test/geometries/concepts/check.cpp new file mode 100644 index 00000000..07b34429 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/concepts/check.cpp @@ -0,0 +1,76 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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 <boost/geometry/core/cs.hpp> +#include <boost/geometry/geometries/concepts/check.hpp> + +struct ro_point +{ + float x, y; +}; + + +struct rw_point +{ + float x, y; +}; + + +namespace boost { namespace geometry { namespace traits { + +template <> struct tag<ro_point> { typedef point_tag type; }; +template <> struct coordinate_type<ro_point> { typedef float type; }; +template <> struct coordinate_system<ro_point> { typedef bg::cs::cartesian type; }; +template <> struct dimension<ro_point> { enum { value = 2 }; }; + +template <> struct access<ro_point, 0> +{ + static float get(ro_point const& p) { return p.x; } +}; + +template <> struct access<ro_point, 1> +{ + static float get(ro_point const& p) { return p.y; } +}; + + + + +template <> struct tag<rw_point> { typedef point_tag type; }; +template <> struct coordinate_type<rw_point> { typedef float type; }; +template <> struct coordinate_system<rw_point> { typedef bg::cs::cartesian type; }; +template <> struct dimension<rw_point> { enum { value = 2 }; }; + +template <> struct access<rw_point, 0> +{ + static float get(rw_point const& p) { return p.x; } + static void set(rw_point& p, float value) { p.x = value; } +}; + +template <> struct access<rw_point, 1> +{ + static float get(rw_point const& p) { return p.y; } + static void set(rw_point& p, float value) { p.y = value; } +}; + + +}}} // namespace bg::traits + + +int main() +{ + bg::concepts::check<const ro_point>(); + bg::concepts::check<rw_point>(); +} diff --git a/src/boost/libs/geometry/test/geometries/custom_linestring.cpp b/src/boost/libs/geometry/test/geometries/custom_linestring.cpp new file mode 100644 index 00000000..66feef66 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/custom_linestring.cpp @@ -0,0 +1,128 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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 <deque> +#include <vector> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/algorithms/append.hpp> +#include <boost/geometry/algorithms/clear.hpp> +#include <boost/geometry/algorithms/make.hpp> +#include <boost/geometry/core/access.hpp> +#include <boost/geometry/geometries/concepts/linestring_concept.hpp> + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/register/linestring.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <test_common/test_point.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector) +BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque) + +//#define TEST_FAIL_CLEAR +//#define TEST_FAIL_APPEND + + + +// ---------------------------------------------------------------------------- +// First custom linestring, requires ONLY one traits: to register itself as a linestring +template <typename P> +struct custom_linestring1 : std::vector<P> {}; + +namespace boost { namespace geometry { namespace traits { + template <typename P> + struct tag< custom_linestring1<P> > { typedef linestring_tag type; }; +}}} // namespace bg::traits + +// ---------------------------------------------------------------------------- +// Second custom linestring, decides to implement all edit operations itself +// by specializing the "use_std" traits to false. +// It should therefore implement the traits:: clear / append_point +template <typename P> +struct custom_linestring2 : std::deque<P> // std::pair<typename std::vector<P>::const_iterator, typename std::vector<P>::const_iterator> +{ +}; + +namespace boost { namespace geometry { namespace traits { + template <typename P> + struct tag< custom_linestring2<P> > { typedef linestring_tag type; }; + +#if ! defined(TEST_FAIL_CLEAR) + template <typename P> + struct clear< custom_linestring2<P> > + { + // does not use std::vector<P>.clear() but something else. + static inline void apply(custom_linestring2<P>& ls) { ls.resize(0); } + }; +#endif + +}}} // namespace bg::traits + +// ---------------------------------------------------------------------------- + +template <typename G> +void test_linestring() +{ + BOOST_CONCEPT_ASSERT( (bg::concepts::Linestring<G>) ); + BOOST_CONCEPT_ASSERT( (bg::concepts::ConstLinestring<G>) ); + + G geometry; + typedef typename bg::point_type<G>::type P; + + bg::clear(geometry); + BOOST_CHECK_EQUAL(boost::size(geometry), 0u); + + bg::append(geometry, bg::make_zero<P>()); + BOOST_CHECK_EQUAL(boost::size(geometry), 1u); + + //std::cout << geometry << std::endl; + + bg::clear(geometry); + BOOST_CHECK_EQUAL(boost::size(geometry), 0u); + + + //P p = boost::range::front(geometry); +} + +template <typename P> +void test_all() +{ + test_linestring<bg::model::linestring<P> >(); + test_linestring<bg::model::linestring<P, std::vector> >(); + test_linestring<bg::model::linestring<P, std::deque> >(); + + test_linestring<custom_linestring1<P> >(); + test_linestring<custom_linestring2<P> >(); + + test_linestring<std::vector<P> >(); + test_linestring<std::deque<P> >(); + //test_linestring<std::list<P> >(); +} + +int test_main(int, char* []) +{ + test_all<test::test_point>(); + test_all<boost::tuple<float, float> >(); + test_all<bg::model::point<int, 2, bg::cs::cartesian> >(); + test_all<bg::model::point<float, 2, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 2, bg::cs::cartesian> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/geometries/infinite_line.cpp b/src/boost/libs/geometry/test/geometries/infinite_line.cpp new file mode 100755 index 00000000..a69b4313 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/infinite_line.cpp @@ -0,0 +1,90 @@ +// Boost.Geometry +// Unit Test + +// Copyright (c) 2019 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2019. +// Modifications copyright (c) 2019, Oracle and/or its affiliates. +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// 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 <geometry_test_common.hpp> + +#include <boost/geometry/algorithms/detail/make/make.hpp> +#include <boost/geometry/geometries/infinite_line.hpp> +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/util/math.hpp> + +namespace +{ + // Boost.Test does not support BOOST_CHECK_CLOSE for integral types + template <typename T> + bool is_small(T const& value) + { + static long double const epsilon = 1.0e-5; + return bg::math::abs(value) < epsilon; + } +} + +template <typename T, typename C> +void verify_point_on_line(bg::model::infinite_line<T> const& line, + C const& x, C const& y) +{ + BOOST_CHECK_MESSAGE(is_small(line.a * x + line.b * y + line.c), + "Point is not located on the line"); +} + +template <typename T> +void test_make() +{ + typedef bg::model::infinite_line<T> line_type; + + // Horizontal through origin + line_type line = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0); + verify_point_on_line(line, 0, 0); + verify_point_on_line(line, 10, 0); + + // Horizontal line above origin + line = bg::detail::make::make_infinite_line<T>(0, 5, 10, 5); + verify_point_on_line(line, 0, 5); + verify_point_on_line(line, 10, 5); + + // Vertical through origin + line = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10); + verify_point_on_line(line, 0, 0); + verify_point_on_line(line, 0, 10); + + // Vertical line left from origin + line = bg::detail::make::make_infinite_line<T>(5, 0, 5, 10); + verify_point_on_line(line, 5, 0); + verify_point_on_line(line, 5, 10); + + // Diagonal through origin + line = bg::detail::make::make_infinite_line<T>(0, 0, 8, 10); + verify_point_on_line(line, 0, 0); + verify_point_on_line(line, 8, 10); + + // Diagonal not through origin + line = bg::detail::make::make_infinite_line<T>(5, 2, -8, 10); + verify_point_on_line(line, 5, 2); + verify_point_on_line(line, -8, 10); +} + + +template <typename T> +void test_all() +{ + test_make<T>(); +} + +int test_main(int, char* []) +{ + test_all<double>(); + test_all<long double>(); + test_all<float>(); + test_all<int>(); + return 0; +} diff --git a/src/boost/libs/geometry/test/geometries/initialization.cpp b/src/boost/libs/geometry/test/geometries/initialization.cpp new file mode 100644 index 00000000..23dd11f5 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/initialization.cpp @@ -0,0 +1,252 @@ +// Boost.Geometry +// Unit Test + +// Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland. + +// 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 <geometry_test_common.hpp> + +#include <boost/assign.hpp> +#include <boost/range.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <boost/geometry/geometries/register/point.hpp> + +#include <boost/geometry/algorithms/num_points.hpp> +#include <boost/geometry/algorithms/num_geometries.hpp> + +typedef std::pair<float, float> pt_pair_t; +BOOST_GEOMETRY_REGISTER_POINT_2D(pt_pair_t, float, bg::cs::cartesian, first, second) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +template <typename P> +void test_default() +{ + typedef bg::model::multi_point<P> mpt; + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::ring<P> ring; + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + // multi_point() + mpt mptd; + BOOST_CHECK(bg::num_points(mptd) == 0); + // linestring() + ls lsd; + BOOST_CHECK(bg::num_points(lsd) == 0); + // multi_linestring() + mls mlsd; + BOOST_CHECK(bg::num_points(mlsd) == 0); + // ring() + ring rd; + BOOST_CHECK(bg::num_points(rd) == 0); + // polygon() + poly pd; + BOOST_CHECK(bg::num_points(pd) == 0); + // multi_polygon() + mpoly mpd; + BOOST_CHECK(bg::num_points(mpd) == 0); +} + +template <typename P> +void test_boost_assign_2d() +{ + typedef bg::model::multi_point<P> mpt; + typedef bg::model::linestring<P> ls; + typedef bg::model::ring<P> ring; + + // using Boost.Assign + mpt mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); + BOOST_CHECK(bg::num_points(mpt2) == 2); + mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); + BOOST_CHECK(bg::num_points(mpt2) == 2); + + // using Boost.Assign + ls ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1)); + BOOST_CHECK(bg::num_points(ls2) == 3); + ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1)); + BOOST_CHECK(bg::num_points(ls2) == 3); + + // using Boost.Assign + ring r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0)); + BOOST_CHECK(bg::num_points(r2) == 5); + r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0)); + BOOST_CHECK(bg::num_points(r2) == 5); +} + +void test_boost_assign_pair_2d() +{ + typedef std::pair<float, float> pt; + + test_boost_assign_2d<pt>(); + + typedef bg::model::multi_point<pt> mpt; + + // using Boost.Assign + mpt mpt2 = boost::assign::pair_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); + mpt2 = boost::assign::pair_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); +} + +void test_boost_assign_tuple_2d() +{ + typedef boost::tuple<float, float> pt; + + test_boost_assign_2d<pt>(); + + typedef bg::model::multi_point<pt> mpt; + + // using Boost.Assign + mpt mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); + mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); +} + +template <typename P> +void test_initializer_list_2d() +{ +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + + typedef bg::model::multi_point<P> mpt; + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::ring<P> ring; + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + // multi_point(initializer_list<Point>) + mpt mpt1 = {{0, 0}, {1, 0}, {2, 0}}; + BOOST_CHECK(bg::num_geometries(mpt1) == 3); + BOOST_CHECK(bg::num_points(mpt1) == 3); + // multi_point::operator=(initializer_list<Point>) + mpt1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; + BOOST_CHECK(bg::num_points(mpt1) == 4); + + // linestring(initializer_list<Point>) + ls ls1 = {{0, 0}, {1, 0}, {2, 0}}; + BOOST_CHECK(bg::num_geometries(ls1) == 1); + BOOST_CHECK(bg::num_points(ls1) == 3); + // linestring::operator=(initializer_list<Point>) + ls1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; + BOOST_CHECK(bg::num_points(ls1) == 4); + + // multi_linestring(initializer_list<Linestring>) + mls mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}}}; + BOOST_CHECK(bg::num_geometries(mls1) == 2); + BOOST_CHECK(bg::num_points(mls1) == 5); + // multi_linestring::operator=(initializer_list<Linestring>) + mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}, {5, 0}}}; + BOOST_CHECK(bg::num_points(mls1) == 6); + + // ring(initializer_list<Point>) + ring r1 = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; + BOOST_CHECK(bg::num_geometries(r1) == 1); + BOOST_CHECK(bg::num_points(r1) == 5); + // ring::operator=(initializer_list<Point>) + r1 = {{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}; + BOOST_CHECK(bg::num_points(r1) == 6); + + // polygon(initializer_list<ring_type>) + poly p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; + BOOST_CHECK(bg::num_geometries(p1) == 1); + BOOST_CHECK(bg::num_points(p1) == 10); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1); + // polygon::operator=(initializer_list<ring_type>) + p1 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; + BOOST_CHECK(bg::num_points(p1) == 11); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1); + p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; + BOOST_CHECK(bg::num_points(p1) == 5); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0); + // polygon(initializer_list<ring_type>) + poly p2 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; + BOOST_CHECK(bg::num_geometries(p2) == 1); + BOOST_CHECK(bg::num_points(p2) == 5); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0); + // polygon::operator=(initializer_list<ring_type>) + p2 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}}; + BOOST_CHECK(bg::num_points(p2) == 6); + + // multi_polygon(initializer_list<Polygon>) + mpoly mp1 = {{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; + BOOST_CHECK(bg::num_geometries(mp1) == 2); + BOOST_CHECK(bg::num_points(mp1) == 10); + // multi_polygon::operator=(initializer_list<Polygon>) + mp1 = {{{{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; + BOOST_CHECK(bg::num_points(mp1) == 11); + +#endif +} + +template <typename P> +void test_all_2d() +{ + test_default<P>(); + test_boost_assign_2d<P>(); + test_initializer_list_2d<P>(); +} + +template <typename T> +struct test_point +{ + test_point(T = T(), T = T()) {} +}; + +template <typename T> +struct test_range +{ + test_range() {} + template <typename It> + test_range(It, It) {} +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + test_range(std::initializer_list<T>) {} + //test_range & operator=(std::initializer_list<T>) { return *this; } +#endif +}; + +void test_sanity_check() +{ + typedef test_point<float> P; + typedef test_range<P> R; + typedef std::vector<P> V; + +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + R r = {{1, 1},{2, 2},{3, 3}}; + r = {{1, 1},{2, 2},{3, 3}}; + + V v = {{1, 1},{2, 2},{3, 3}}; + v = {{1, 1},{2, 2},{3, 3}}; + } +#endif + { + R r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + + V v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + //v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + v.empty(); + } +} + +int test_main(int, char* []) +{ + test_all_2d< bg::model::point<float, 2, bg::cs::cartesian> >(); + test_all_2d< bg::model::d2::point_xy<float> >(); + + test_boost_assign_pair_2d(); + test_boost_assign_tuple_2d(); + + test_sanity_check(); + + return 0; +} + diff --git a/src/boost/libs/geometry/test/geometries/segment.cpp b/src/boost/libs/geometry/test/geometries/segment.cpp new file mode 100644 index 00000000..dcbb2ed1 --- /dev/null +++ b/src/boost/libs/geometry/test/geometries/segment.cpp @@ -0,0 +1,104 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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 <iostream> + +#include <geometry_test_common.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/geometry/geometries/concepts/segment_concept.hpp> + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/segment.hpp> + + +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +#include <boost/geometry/io/dsv/write.hpp> + + +#include <test_common/test_point.hpp> +#include <test_geometries/custom_segment.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +template <typename P> +void test_all() +{ + typedef bg::model::referring_segment<P> S; + + P p1; + P p2; + S s(p1, p2); + BOOST_CHECK_EQUAL(&s.first, &p1); + BOOST_CHECK_EQUAL(&s.second, &p2); + + // Compilation tests, all things should compile. + BOOST_CONCEPT_ASSERT( (bg::concepts::ConstSegment<S>) ); + BOOST_CONCEPT_ASSERT( (bg::concepts::Segment<S>) ); + + typedef typename bg::coordinate_type<S>::type T; + typedef typename bg::point_type<S>::type SP; + boost::ignore_unused<T, SP>(); + + //std::cout << sizeof(typename coordinate_type<S>::type) << std::endl; + + typedef bg::model::referring_segment<P const> refseg_t; + //BOOST_CONCEPT_ASSERT( (concepts::ConstSegment<refseg_t>) ); + + refseg_t seg(p1, p2); + + typedef typename bg::coordinate_type<refseg_t>::type CT; + typedef typename bg::point_type<refseg_t>::type CSP; + boost::ignore_unused<CT, CSP>(); +} + + + +template <typename S> +void test_custom() +{ + S seg; + bg::set<0,0>(seg, 1); + bg::set<0,1>(seg, 2); + bg::set<1,0>(seg, 3); + bg::set<1,1>(seg, 4); + std::ostringstream out; + out << bg::dsv(seg); + BOOST_CHECK_EQUAL(out.str(), "((1, 2), (3, 4))"); +} + + +int test_main(int, char* []) +{ + test_all<int[3]>(); + test_all<float[3]>(); + test_all<double[3]>(); + //test_all<test_point>(); + test_all<bg::model::point<int, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<float, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 3, bg::cs::cartesian> >(); + + test_custom<test::custom_segment>(); + test_custom<test::custom_segment_of<bg::model::point<double, 2, bg::cs::cartesian> > >(); + test_custom<test::custom_segment_of<test::custom_point_for_segment> >(); + test_custom<test::custom_segment_4>(); + + return 0; +} + |