|
Geometry : |
Subject: [ggl] Incorrect polygon area and problem with the boost::geometry::correct
From: Vishnu (vrang3)
Date: 2011-03-17 11:57:20
I have two problems with a slightly edited version of the example program
'c06_custom_polygon_example.cpp'. My revisions to the example are very
minor, the substitution of a boost_array for holes with an std::vector, and
a call to 'correct' the polygon prior to calculating the area. The
differences between the example and my edited file are shown following the
problem description below.
1) The polygon area is correct when I use boost-geometry 0.6 along with
boost_1_43. The polygon area is wrong when I use boost-geometry 0.8 along
with boost_1_46_1. The correct area of the polygon is 0.92. However, with
boost geometry 0.8, I get an area of 1.08, so it appears that the areas of
the holes are added instead of being subtracted.
2) My edited version of the program compiles and builds with MS Visual
Studio 2008 with both versions of boost-geometry. However, on RHEL4 with g++
4.2.4, I can build it only with boost-geometry 0.6. The compilation error
with g++ when I use boost-geometry 0.8 is shown below (the boost geometry
files were put inside the boost_1_46_1 hierarchy). The program compiles if
I do not call 'correct'.
g++ -I/usr/raidhome/vishnu/boost_1_46_1 -o
c06_custom_polygon_example.2.using.bg0.8 c06_custom_polygon_example.2.cpp
/usr/raidhome/vishnu/boost_1_46_1/boost/geometry/algorithms/correct.hpp: In
static member function ?static void
boost::geometry::detail::correct::correct_polygon::apply(Polygon&) [with
Polygon = my_polygon]?:
/usr/raidhome/vishnu/boost_1_46_1/boost/geometry/algorithms/correct.hpp:238:
instantiated from ?void boost::geometry::correct(Geometry&) [with Geometry =
my_polygon]?
c06_custom_polygon_example.2.cpp:134: instantiated from here
/usr/raidhome/vishnu/boost_1_46_1/boost/geometry/algorithms/correct.hpp:161:
error: no matching function for call to
?boost::geometry::detail::correct::correct_ring<my_ring,
std::less<double> >::apply(my_ring)?
/usr/raidhome/vishnu/boost_1_46_1/boost/geometry/algorithms/correct.hpp:122:
note: candidates are: static void
boost::geometry::detail::correct::correct_ring<Ring,
Predicate>::apply(Ring&) [with Ring = my_ring, Predicate = std::less]
The diff output is shown below.
>diff
D:\users\vishnu\boost-geometry-0.8.0\example\c06_custom_polygon_example.cpp
c06_custom_polygon_example.2.cpp
9a10
> #include
38c39
< boost::array<my_ring, 2> holes;
--- > std::vector holes; 64c65 < typedef boost::array<my_ring, 2> type; --- > typedef std::vector type; 83c84 < typedef boost::array<my_ring, 2> holes_type; --- > typedef std::vector holes_type; 101a103,104 > using namespace boost::geometry; > 104,121c107,134 < // Fill it the my-way, triangle < p1.boundary.push_back(my_point(2, 0)); < p1.boundary.push_back(my_point(1, 5)); < p1.boundary.push_back(my_point(5, 5)); < p1.boundary.push_back(my_point(2, 0)); < < // Triangle < p1.holes[0].push_back(my_point(2, 1)); < p1.holes[0].push_back(my_point(1.9, 2)); < p1.holes[0].push_back(my_point(2.4, 2)); < p1.holes[0].push_back(my_point(2, 1)); < < // Box < p1.holes[1].push_back(my_point(3, 3)); < p1.holes[1].push_back(my_point(3, 4)); < p1.holes[1].push_back(my_point(4, 4)); < p1.holes[1].push_back(my_point(4, 3)); < p1.holes[1].push_back(my_point(3, 3)); --- > // Fill it with a square > p1.boundary.push_back(my_point(0, 0)); > p1.boundary.push_back(my_point(0, 1)); > p1.boundary.push_back(my_point(1, 1)); > p1.boundary.push_back(my_point(1, 0)); > p1.boundary.push_back(my_point(0, 0)); > > // Hole 1 > my_ring ring; > ring.push_back(my_point(0.2, 0.2)); > ring.push_back(my_point(0.2, 0.4)); > ring.push_back(my_point(0.4, 0.4)); > ring.push_back(my_point(0.4, 0.2)); > ring.push_back(my_point(0.2, 0.2)); > > p1.holes.push_back(ring); > > ring.clear(); > > ring.push_back(my_point(0.6, 0.6)); > ring.push_back(my_point(0.6, 0.8)); > ring.push_back(my_point(0.8, 0.8)); > ring.push_back(my_point(0.8, 0.6)); > ring.push_back(my_point(0.6, 0.6)); > > p1.holes.push_back(ring); > > correct(p1); -- View this message in context: http://boost-geometry.203548.n3.nabble.com/Incorrect-polygon-area-and-problem-with-the-boost-geometry-correct-tp2694059p2694059.html Sent from the Boost Geometry mailing list archive at Nabble.com.
Geometry list run by mateusz at loskot.net