mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 13:34:10 +00:00
Updates in test for partition addition
[SVN r69944]
This commit is contained in:
parent
4d147a71d3
commit
9d68c93eaa
@ -12,19 +12,22 @@
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
||||
#include <boost/geometry/geometry.hpp>
|
||||
#include <boost/geometry/multi/geometries/multi_point.hpp>
|
||||
#include <boost/geometry/geometries/register/point.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
|
||||
#include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
|
||||
#include <boost/geometry/algorithms/detail/partition.hpp>
|
||||
|
||||
#include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
|
||||
#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
|
||||
|
||||
|
||||
template <typename Box>
|
||||
struct sample_item
|
||||
struct box_item
|
||||
{
|
||||
int id;
|
||||
Box box;
|
||||
sample_item(int i = 0, std::string const& wkt = "")
|
||||
box_item(int i = 0, std::string const& wkt = "")
|
||||
: id(i)
|
||||
{
|
||||
if (! wkt.empty())
|
||||
@ -55,12 +58,12 @@ struct ovelaps_box
|
||||
|
||||
|
||||
template <typename Box>
|
||||
struct sample_visitor
|
||||
struct box_visitor
|
||||
{
|
||||
int count;
|
||||
typename bg::area_result<Box>::type area;
|
||||
|
||||
sample_visitor()
|
||||
box_visitor()
|
||||
: count(0)
|
||||
, area(0)
|
||||
{}
|
||||
@ -81,13 +84,13 @@ struct sample_visitor
|
||||
|
||||
|
||||
template <typename Box>
|
||||
void test_geometry(std::string const& wkt_box_list, double expected_area, int expected_count)
|
||||
void test_boxes(std::string const& wkt_box_list, double expected_area, int expected_count)
|
||||
{
|
||||
std::vector<std::string> wkt_boxes;
|
||||
|
||||
boost::split(wkt_boxes, wkt_box_list, boost::is_any_of(";"), boost::token_compress_on);
|
||||
|
||||
typedef sample_item<Box> sample;
|
||||
typedef box_item<Box> sample;
|
||||
std::vector<sample> boxes;
|
||||
|
||||
int index = 1;
|
||||
@ -96,11 +99,11 @@ void test_geometry(std::string const& wkt_box_list, double expected_area, int ex
|
||||
boxes.push_back(sample(index++, wkt));
|
||||
}
|
||||
|
||||
sample_visitor<Box> visitor;
|
||||
box_visitor<Box> visitor;
|
||||
bg::partition
|
||||
<
|
||||
Box, get_box, ovelaps_box
|
||||
>::apply(boxes, visitor);
|
||||
>::apply(boxes, visitor, 1);
|
||||
|
||||
BOOST_CHECK_CLOSE(visitor.area, expected_area, 0.001);
|
||||
BOOST_CHECK_EQUAL(visitor.count, expected_count);
|
||||
@ -108,27 +111,107 @@ void test_geometry(std::string const& wkt_box_list, double expected_area, int ex
|
||||
|
||||
|
||||
|
||||
struct point_item
|
||||
{
|
||||
point_item()
|
||||
: id(0)
|
||||
{}
|
||||
|
||||
int id;
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
|
||||
BOOST_GEOMETRY_REGISTER_POINT_2D(point_item, double, cs::cartesian, x, y)
|
||||
|
||||
|
||||
struct get_point
|
||||
{
|
||||
template <typename Box, typename InputItem>
|
||||
static inline void apply(Box& total, InputItem const& item)
|
||||
{
|
||||
bg::expand(total, item);
|
||||
}
|
||||
};
|
||||
|
||||
struct ovelaps_point
|
||||
{
|
||||
template <typename Box, typename InputItem>
|
||||
static inline bool apply(Box const& box, InputItem const& item)
|
||||
{
|
||||
return ! bg::disjoint(item, box);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct point_visitor
|
||||
{
|
||||
int count;
|
||||
|
||||
point_visitor()
|
||||
: count(0)
|
||||
{}
|
||||
|
||||
template <typename Item>
|
||||
inline void apply(Item const& item1, Item const& item2)
|
||||
{
|
||||
if (bg::equals(item1, item2))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void test_points(std::string const& wkt1, std::string const& wkt2, int expected_count)
|
||||
{
|
||||
bg::model::multi_point<point_item> mp1, mp2;
|
||||
bg::read_wkt(wkt1, mp1);
|
||||
bg::read_wkt(wkt2, mp2);
|
||||
|
||||
int id = 1;
|
||||
BOOST_FOREACH(point_item& p, mp1)
|
||||
{ p.id = id++; }
|
||||
id = 1;
|
||||
BOOST_FOREACH(point_item& p, mp2)
|
||||
{ p.id = id++; }
|
||||
|
||||
point_visitor visitor;
|
||||
bg::partition
|
||||
<
|
||||
bg::model::box<point_item>, get_point, ovelaps_point
|
||||
>::apply(mp1, mp2, visitor, 1);
|
||||
|
||||
BOOST_CHECK_EQUAL(visitor.count, expected_count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename P>
|
||||
void test_all()
|
||||
{
|
||||
typedef bg::model::box<P> box;
|
||||
|
||||
test_geometry<box>(
|
||||
test_boxes<box>(
|
||||
// 1 2 3 4 5 6 7
|
||||
"box(0 0,1 1); box(0 0,2 2); box(9 9,10 10); box(8 8,9 9); box(4 4,6 6); box(2 4,6 8); box(7 1,8 2)",
|
||||
5, // Area(Intersection(1,2)) + A(I(5,6))
|
||||
3);
|
||||
|
||||
test_geometry<box>(
|
||||
test_boxes<box>(
|
||||
"box(0 0,10 10); box(4 4,6 6); box(3 3,7 7)",
|
||||
4 + 16 + 4, // A(I(1,2)) + A(I(1,3)) + A(I(2,3))
|
||||
3);
|
||||
|
||||
test_geometry<box>(
|
||||
test_boxes<box>(
|
||||
"box(0 2,10 3); box(3 1,4 5); box(7 1,8 5)",
|
||||
1 + 1, // A(I(1,2)) + A(I(1,3))
|
||||
2);
|
||||
|
||||
test_points("multipoint((1 1))", "multipoint((1 1))", 1);
|
||||
test_points("multipoint((0 0),(1 1),(7 3),(10 10))", "multipoint((1 1),(2 2),(7 3))", 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,13 +51,14 @@ void test_sectionalize_part()
|
||||
Geometry geometry;
|
||||
geometry.push_back(bg::make<point_type>(1, 1));
|
||||
|
||||
bg::ring_identifier ring_id;
|
||||
int index = 0;
|
||||
int ndi = 0;
|
||||
sectionalize_part::apply(sections, section, index, ndi, geometry);
|
||||
sectionalize_part::apply(sections, section, index, ndi, geometry, ring_id);
|
||||
// There should not yet be anything generated, because it is only ONE point
|
||||
|
||||
geometry.push_back(bg::make<point_type>(2, 2));
|
||||
sectionalize_part::apply(sections, section, index, ndi, geometry);
|
||||
sectionalize_part::apply(sections, section, index, ndi, geometry, ring_id);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C++ Express 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sectionalize", "sectionalize.vcproj", "{50410F81-7B83-49D9-BDAE-FA3F0ADB2ADC}"
|
||||
|
@ -73,7 +73,7 @@ void test_areal()
|
||||
5, 33, 9);
|
||||
test_one<Polygon, MultiPolygon, MultiPolygon>("case_78_multi",
|
||||
case_78_multi[0], case_78_multi[1],
|
||||
1, 17, 22);
|
||||
1, 16, 22); // In "get_turns" using partitioning, #points went from 17 to 16
|
||||
test_one<Polygon, MultiPolygon, MultiPolygon>("case_101_multi",
|
||||
case_101_multi[0], case_101_multi[1],
|
||||
4, 22, 4.75);
|
||||
|
Loading…
x
Reference in New Issue
Block a user