mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 13:34:10 +00:00
Testcases for difference, assign, append
[SVN r69254]
This commit is contained in:
parent
985a945819
commit
f3ee8984ef
@ -26,22 +26,44 @@
|
||||
|
||||
|
||||
template <typename G>
|
||||
void test_geometry()
|
||||
void test_geometry(bool check = true)
|
||||
{
|
||||
G geometry;
|
||||
typedef typename bg::point_type<G>::type P;
|
||||
|
||||
bg::append(geometry, bg::make_zero<P>());
|
||||
BOOST_CHECK_EQUAL(bg::num_points(geometry), 1u);
|
||||
if (check)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(bg::num_points(geometry), 1u);
|
||||
}
|
||||
|
||||
// Append a range
|
||||
std::vector<P> v;
|
||||
v.push_back(bg::make_zero<P>());
|
||||
v.push_back(bg::make_zero<P>());
|
||||
bg::append(geometry, v);
|
||||
|
||||
if (check)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(bg::num_points(geometry), 3u);
|
||||
}
|
||||
|
||||
bg::clear(geometry);
|
||||
BOOST_CHECK_EQUAL(bg::num_points(geometry), 0u);
|
||||
|
||||
if (check)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(bg::num_points(geometry), 0u);
|
||||
}
|
||||
|
||||
//P p = boost::range::front(geometry);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void test_all()
|
||||
{
|
||||
test_geometry<P>(false);
|
||||
test_geometry<bg::model::box<P> >(false);
|
||||
test_geometry<bg::model::segment<P> >(false);
|
||||
test_geometry<bg::model::linestring<P> >();
|
||||
test_geometry<bg::model::ring<P> >();
|
||||
test_geometry<bg::model::polygon<P> >();
|
||||
@ -50,7 +72,7 @@ void test_all()
|
||||
test_geometry<std::deque<P> >();
|
||||
//test_geometry<std::list<P> >();
|
||||
|
||||
test_geometry<test::wrapped_boost_array<P, 2> >();
|
||||
test_geometry<test::wrapped_boost_array<P, 3> >();
|
||||
}
|
||||
|
||||
int test_main(int, char* [])
|
||||
|
@ -17,13 +17,13 @@
|
||||
#include <test_common/test_point.hpp>
|
||||
|
||||
|
||||
template <typename L>
|
||||
void check_linestring_2d(const L& line)
|
||||
template <typename Linestring>
|
||||
void check_linestring_2d(Linestring const& line)
|
||||
{
|
||||
BOOST_CHECK((boost::size(line) == 3));
|
||||
BOOST_CHECK((bg::num_points(line) == 3));
|
||||
|
||||
typedef typename bg::point_type<L>::type point_type;
|
||||
typedef typename bg::point_type<Linestring>::type point_type;
|
||||
point_type const& p0 = line[0];
|
||||
BOOST_CHECK(bg::get<0>(p0) == 1);
|
||||
BOOST_CHECK(bg::get<1>(p0) == 2);
|
||||
@ -37,10 +37,10 @@ void check_linestring_2d(const L& line)
|
||||
BOOST_CHECK(bg::get<1>(p2) == 6);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
template <typename Point>
|
||||
void test_assign_linestring_2d()
|
||||
{
|
||||
bg::model::linestring<P> line;
|
||||
bg::model::linestring<Point> line;
|
||||
|
||||
// Test assignment of plain array (note that this is only possible if adapted c-array is included!
|
||||
const double coors[3][2] = { {1, 2}, {3, 4}, {5, 6} };
|
||||
@ -48,7 +48,7 @@ void test_assign_linestring_2d()
|
||||
check_linestring_2d(line);
|
||||
|
||||
// Test assignment of point array
|
||||
P points[3];
|
||||
Point points[3];
|
||||
bg::assign(points[0], 1, 2);
|
||||
bg::assign(points[1], 3, 4);
|
||||
bg::assign(points[2], 5, 6);
|
||||
@ -64,36 +64,50 @@ void test_assign_linestring_2d()
|
||||
check_linestring_2d(line);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void test_assign_box_2d()
|
||||
namespace detail
|
||||
{
|
||||
template <typename BoxOrSegment>
|
||||
void test_assign_box_or_segment_2d()
|
||||
{
|
||||
BoxOrSegment geometry;
|
||||
bg::assign(geometry, 1, 2, 3, 4);
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 0>(geometry) == 1));
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 1>(geometry) == 2));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 0>(geometry) == 3));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 1>(geometry) == 4));
|
||||
|
||||
typedef bg::model::box<P> B;
|
||||
B b;
|
||||
bg::assign(b, 1, 2, 3, 4);
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 0>(b) == 1));
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 1>(b) == 2));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 0>(b) == 3));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 1>(b) == 4));
|
||||
|
||||
bg::assign_zero(b);
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 0>(b) == 0));
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 1>(b) == 0));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 0>(b) == 0));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 1>(b) == 0));
|
||||
|
||||
bg::assign_inverse(b);
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 0>(b) > 9999));
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 1>(b) > 9999));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 0>(b) < 9999));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 1>(b) < 9999));
|
||||
bg::assign_zero(geometry);
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 0>(geometry) == 0));
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 1>(geometry) == 0));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 0>(geometry) == 0));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 1>(geometry) == 0));
|
||||
|
||||
bg::assign_inverse(geometry);
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 0>(geometry) > 9999));
|
||||
BOOST_CHECK((bg::get<bg::min_corner, 1>(geometry) > 9999));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 0>(geometry) < 9999));
|
||||
BOOST_CHECK((bg::get<bg::max_corner, 1>(geometry) < 9999));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
template <typename Point>
|
||||
void test_assign_box_or_segment_2d()
|
||||
{
|
||||
detail::test_assign_box_or_segment_2d<bg::model::box<Point> >();
|
||||
detail::test_assign_box_or_segment_2d<bg::model::segment<Point> >();
|
||||
}
|
||||
|
||||
template <typename Point>
|
||||
void test_assign_box_2d()
|
||||
{
|
||||
detail::test_assign_box_or_segment_2d<bg::model::box<Point> >();
|
||||
}
|
||||
|
||||
|
||||
template <typename Point>
|
||||
void test_assign_point_3d()
|
||||
{
|
||||
P p;
|
||||
Point p;
|
||||
bg::assign(p, 1, 2, 3);
|
||||
BOOST_CHECK(bg::get<0>(p) == 1);
|
||||
BOOST_CHECK(bg::get<1>(p) == 2);
|
||||
@ -111,10 +125,10 @@ void test_assign_point_3d()
|
||||
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
template <typename Point>
|
||||
void test_assign_point_2d()
|
||||
{
|
||||
P p;
|
||||
Point p;
|
||||
bg::assign(p, 1, 2);
|
||||
BOOST_CHECK(bg::get<0>(p) == 1);
|
||||
BOOST_CHECK(bg::get<1>(p) == 2);
|
||||
@ -145,12 +159,14 @@ int test_main(int, char* [])
|
||||
test_assign_point_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
|
||||
test_assign_point_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
|
||||
|
||||
// Segment (currently) cannot handle array's because derived from std::pair
|
||||
test_assign_box_2d<int[2]>();
|
||||
test_assign_box_2d<float[2]>();
|
||||
test_assign_box_2d<double[2]>();
|
||||
test_assign_box_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
|
||||
test_assign_box_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
|
||||
test_assign_box_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
|
||||
|
||||
test_assign_box_or_segment_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
|
||||
test_assign_box_or_segment_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
|
||||
test_assign_box_or_segment_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
|
||||
|
||||
test_assign_linestring_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
|
||||
test_assign_linestring_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
|
||||
|
@ -17,9 +17,11 @@
|
||||
#include <algorithms/test_difference.hpp>
|
||||
#include <algorithms/test_overlay.hpp>
|
||||
#include <algorithms/overlay/overlay_cases.hpp>
|
||||
#include <multi/algorithms/overlay/multi_overlay_cases.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/correct.hpp>
|
||||
#include <boost/geometry/algorithms/perimeter.hpp>
|
||||
#include <boost/geometry/multi/algorithms/correct.hpp>
|
||||
#include <boost/geometry/extensions/gis/io/wkb/read_wkb.hpp>
|
||||
#include <boost/geometry/extensions/gis/io/wkb/utility.hpp>
|
||||
|
||||
@ -32,7 +34,9 @@
|
||||
template <typename P>
|
||||
void test_all()
|
||||
{
|
||||
typedef bg::model::box<P> box;
|
||||
typedef bg::model::polygon<P> polygon;
|
||||
typedef bg::model::ring<P> ring;
|
||||
|
||||
test_one<polygon, polygon, polygon>(
|
||||
"star_ring", example_star, example_ring,
|
||||
@ -93,6 +97,61 @@ void test_all()
|
||||
8, 22, 2.43452380952381,
|
||||
7, 27, 3.18452380952381);
|
||||
|
||||
// Other combi's
|
||||
{
|
||||
test_one<polygon, polygon, ring>(
|
||||
"star_ring_ring", example_star, example_ring,
|
||||
5, 22, 1.1901714, 5, 27, 1.6701714);
|
||||
|
||||
test_one<polygon, ring, polygon>(
|
||||
"ring_star_ring", example_ring, example_star,
|
||||
5, 22, 1.6701714, 5, 27, 1.1901714);
|
||||
|
||||
static std::string const clip = "POLYGON((2.5 0.5,5.5 2.5))";
|
||||
|
||||
test_one<polygon, box, ring>("star_box",
|
||||
clip, example_star,
|
||||
4, 11, 2.833333, 4, 11, 0.833333);
|
||||
|
||||
test_one<polygon, ring, box>("box_star",
|
||||
example_star, clip,
|
||||
4, 11, 0.833333, 4, 11, 2.833333);
|
||||
}
|
||||
|
||||
// Counter clockwise
|
||||
{
|
||||
typedef bg::model::polygon<P, false> polygon_ccw;
|
||||
test_one<polygon, polygon_ccw, polygon_ccw>(
|
||||
"star_ring_ccw", example_star, example_ring,
|
||||
5, 22, 1.1901714, 5, 27, 1.6701714);
|
||||
test_one<polygon, polygon, polygon_ccw>(
|
||||
"star_ring_ccw1", example_star, example_ring,
|
||||
5, 22, 1.1901714, 5, 27, 1.6701714);
|
||||
test_one<polygon, polygon_ccw, polygon>(
|
||||
"star_ring_ccw2", example_star, example_ring,
|
||||
5, 22, 1.1901714, 5, 27, 1.6701714);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Multi
|
||||
{
|
||||
typedef bg::model::multi_polygon<polygon> mp;
|
||||
|
||||
test_one<polygon, mp, mp>("simplex_multi",
|
||||
case_multi_simplex[0], case_multi_simplex[1],
|
||||
5, 12, 5.58, 4, 12, 2.58);
|
||||
|
||||
static std::string const clip = "POLYGON((2 2,4 4))";
|
||||
|
||||
test_one<polygon, box, mp>("simplex_multi_box_mp",
|
||||
clip, case_multi_simplex[0],
|
||||
3, 11, 4.53333, 3, 11, 8.53333);
|
||||
test_one<polygon, mp, box>("simplex_multi_mp_box",
|
||||
case_multi_simplex[0], clip,
|
||||
3, 11, 8.53333, 3, 11, 4.53333);
|
||||
}
|
||||
|
||||
/***
|
||||
Experimental (cut), does not work:
|
||||
test_one<polygon, polygon, polygon>(
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <boost/geometry/algorithms/difference.hpp>
|
||||
#include <boost/geometry/algorithms/sym_difference.hpp>
|
||||
#include <boost/geometry/multi/algorithms/difference.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/area.hpp>
|
||||
#include <boost/geometry/algorithms/num_points.hpp>
|
||||
@ -23,6 +24,11 @@
|
||||
|
||||
#include <boost/geometry/geometries/geometries.hpp>
|
||||
|
||||
|
||||
#include <boost/geometry/multi/geometries/multi_point.hpp>
|
||||
#include <boost/geometry/multi/geometries/multi_linestring.hpp>
|
||||
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/strategies.hpp>
|
||||
|
||||
#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
|
||||
@ -49,11 +55,11 @@ void test_difference(std::string const& caseid, G1 const& g1, G2 const& g2,
|
||||
|
||||
if (sym)
|
||||
{
|
||||
bg::sym_difference<OutputType>(g1, g2, clip);
|
||||
bg::sym_difference(g1, g2, clip);
|
||||
}
|
||||
else
|
||||
{
|
||||
bg::difference<OutputType>(g1, g2, clip);
|
||||
bg::difference(g1, g2, clip);
|
||||
}
|
||||
|
||||
double area = 0;
|
||||
@ -154,6 +160,9 @@ void test_one(std::string const& caseid,
|
||||
G2 g2;
|
||||
bg::read_wkt(wkt2, g2);
|
||||
|
||||
bg::correct(g1);
|
||||
bg::correct(g2);
|
||||
|
||||
test_difference<OutputType, void>(caseid + "_a", g1, g2,
|
||||
expected_count1, expected_point_count1,
|
||||
expected_area1, percentage);
|
||||
|
Loading…
x
Reference in New Issue
Block a user