diff options
Diffstat (limited to 'libs/polygon/test')
-rw-r--r-- | libs/polygon/test/Jamfile.v2 | 2 | ||||
-rw-r--r-- | libs/polygon/test/gtl_boost_unit_test.cpp | 2 | ||||
-rw-r--r-- | libs/polygon/test/polygon_90_data_test.cpp | 51 | ||||
-rw-r--r-- | libs/polygon/test/polygon_set_data_test.cpp | 111 |
4 files changed, 165 insertions, 1 deletions
diff --git a/libs/polygon/test/Jamfile.v2 b/libs/polygon/test/Jamfile.v2 index 35657ff18..6a6e8caa1 100644 --- a/libs/polygon/test/Jamfile.v2 +++ b/libs/polygon/test/Jamfile.v2 @@ -22,6 +22,8 @@ test-suite polygon-unit [ run polygon_segment_test.cpp ] [ run polygon_interval_test.cpp ] [ run polygon_rectangle_test.cpp ] + [ run polygon_set_data_test.cpp ] + [ run polygon_90_data_test.cpp ] [ run gtl_boost_unit_test.cpp ] ; diff --git a/libs/polygon/test/gtl_boost_unit_test.cpp b/libs/polygon/test/gtl_boost_unit_test.cpp index 1ade24247..c85d5d661 100644 --- a/libs/polygon/test/gtl_boost_unit_test.cpp +++ b/libs/polygon/test/gtl_boost_unit_test.cpp @@ -681,7 +681,7 @@ namespace boost { namespace polygon{ std::cout << (ps2 == ps) << std::endl; ps2 ^= ps; std::cout << ps2.empty() << std::endl; - axis_transformation atr(axis_transformation::WS); + axis_transformation atr(axis_transformation::WEST_SOUTH); ps2 = ps; ps.transform(atr); transformation<int> tr(atr); diff --git a/libs/polygon/test/polygon_90_data_test.cpp b/libs/polygon/test/polygon_90_data_test.cpp new file mode 100644 index 000000000..9171a19f4 --- /dev/null +++ b/libs/polygon/test/polygon_90_data_test.cpp @@ -0,0 +1,51 @@ +// Boost.Polygon library polygon_90_data_test.cpp file + +// Copyright Andrii Sydorchuk 2015. +// Distributed under 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#define BOOST_TEST_MODULE POLYGON_90_DATA_TEST +#include <vector> + +#include <boost/mpl/list.hpp> +#include <boost/test/test_case_template.hpp> + +#include "boost/polygon/polygon.hpp" +using namespace boost::polygon; + +#include <iostream> + +typedef boost::mpl::list<int> test_types; + +BOOST_AUTO_TEST_CASE_TEMPLATE(polygon_90_data_test, T, test_types) { + typedef polygon_90_data<int> polygon_type; + typedef polygon_traits_90<polygon_type>::point_type point_type; + typedef polygon_type::iterator_type iterator_type; + + std::vector<point_type> data; + data.push_back(point_type(0, 0)); // 1 + data.push_back(point_type(10, 0)); // 2 + data.push_back(point_type(10, 10)); // 3 + data.push_back(point_type(0, 10)); // 4 + + polygon_type polygon; + polygon.set(data.begin(), data.end()); + + std::cout << "Interesting: " << std::endl; + for (polygon_type::compact_iterator_type it = polygon.begin_compact(); it != polygon.end_compact(); ++it) { + std::cout << *it << " "; + } + std::cout << std::endl; + + iterator_type it = polygon.begin(); + for (int i = 0; i < 2; i++) { + it++; + } + + iterator_type it_3rd = it; + it++; + BOOST_CHECK(it != it_3rd); +} diff --git a/libs/polygon/test/polygon_set_data_test.cpp b/libs/polygon/test/polygon_set_data_test.cpp new file mode 100644 index 000000000..d85936869 --- /dev/null +++ b/libs/polygon/test/polygon_set_data_test.cpp @@ -0,0 +1,111 @@ +// Boost.Polygon library polygon_set_data_test.cpp file + +// Copyright Andrii Sydorchuk 2015. +// Distributed under 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#define BOOST_TEST_MODULE POLYGON_SET_DATA_TEST +#include <vector> + +#include <boost/mpl/list.hpp> +#include <boost/test/test_case_template.hpp> + +#include "boost/polygon/polygon.hpp" +using namespace boost::polygon; +using namespace boost::polygon::operators; + +typedef boost::mpl::list<int> test_types; + +BOOST_AUTO_TEST_CASE_TEMPLATE(polygon_set_data_test1, T, test_types) { + typedef point_data<T> point_type; + typedef polygon_data<T> polygon_type; + typedef polygon_with_holes_data<T> polygon_with_holes_type; + typedef polygon_set_data<T> polygon_set_type; + + polygon_set_type pset; + std::vector<point_type> outbox; + outbox.push_back(point_type(0, 0)); + outbox.push_back(point_type(100, 0)); + outbox.push_back(point_type(100, 100)); + outbox.push_back(point_type(0, 100)); + pset.insert_vertex_sequence(outbox.begin(), outbox.end(), COUNTERCLOCKWISE, false); + std::vector<point_type> inbox; + inbox.push_back(point_type(20, 20)); + inbox.push_back(point_type(80, 20)); + inbox.push_back(point_type(80, 80)); + inbox.push_back(point_type(20, 80)); + pset.insert_vertex_sequence(inbox.begin(), inbox.end(), COUNTERCLOCKWISE, true); + + BOOST_CHECK(!pset.empty()); + BOOST_CHECK(!pset.sorted()); + BOOST_CHECK(pset.dirty()); + BOOST_CHECK_EQUAL(8, pset.size()); + + std::vector<polygon_with_holes_type> vpoly; + pset.get(vpoly); + BOOST_CHECK_EQUAL(1, vpoly.size()); + + polygon_with_holes_type poly = vpoly[0]; + BOOST_CHECK_EQUAL(5, poly.size()); + BOOST_CHECK_EQUAL(1, poly.size_holes()); +} + +BOOST_AUTO_TEST_CASE_TEMPLATE(polygon_set_data_test2, T, test_types) { + typedef point_data<T> point_type; + typedef polygon_data<T> polygon_type; + typedef polygon_with_holes_data<T> polygon_with_holes_type; + typedef polygon_set_data<T> polygon_set_type; + + std::vector<point_type> data; + data.push_back(point_type(2,0)); + data.push_back(point_type(4,0)); + data.push_back(point_type(4,3)); + data.push_back(point_type(0,3)); + data.push_back(point_type(0,0)); + data.push_back(point_type(2,0)); + data.push_back(point_type(2,1)); + data.push_back(point_type(1,1)); + data.push_back(point_type(1,2)); + data.push_back(point_type(3,2)); + data.push_back(point_type(3,1)); + data.push_back(point_type(2,1)); + data.push_back(point_type(2,0)); + + polygon_type polygon; + set_points(polygon, data.begin(), data.end()); + + polygon_set_type pset; + pset.insert(polygon); + + std::vector<polygon_type> traps; + get_trapezoids(traps, pset, HORIZONTAL); + + BOOST_CHECK_EQUAL(4, traps.size()); +} + +BOOST_AUTO_TEST_CASE_TEMPLATE(polygon_set_data_test3, T, test_types) { + typedef point_data<T> point_type; + typedef polygon_data<T> polygon_type; + typedef polygon_with_holes_data<T> polygon_with_holes_type; + typedef polygon_set_data<T> polygon_set_type; + + std::vector<point_type> data; + data.push_back(point_type(0,0)); + data.push_back(point_type(6,0)); + data.push_back(point_type(6,4)); + data.push_back(point_type(4,6)); + data.push_back(point_type(0,6)); + data.push_back(point_type(0,0)); + data.push_back(point_type(4,4)); + data.push_back(point_type(5,4)); + + polygon_type polygon(data.begin(), data.end()); + polygon_set_type pset; + pset += polygon; + + BOOST_CHECK_EQUAL(32.0, area(polygon)); + BOOST_CHECK_EQUAL(32.0, area(polygon)); +} |