|
Boost Users : |
Subject: [Boost-users] [Polygon] using polygon for linesegment intersection
From: gast128 (gast128_at_[hidden])
Date: 2011-04-26 13:30:10
Hello all,
I was trying to use the Boost.Polygon library to test for line segment
intersection. I define 2 polygons (lines) and use the Boolean operators of the
polygon_set. However it gives an empty result:
void TestBoostPolygonIntersectLineSegment()
{
using namespace boost::polygon::operators;
typedef boost::polygon::polygon_data<int> Polygon;
typedef boost::polygon::point_data<int> Point;
typedef boost::polygon::polygon_set_data<int> PolygonSet;
typedef std::vector<Polygon> PolygonVector;
Point aPts1[] = { Point(0, 0),
Point(10, 0) };
Point aPts2[] = { Point(5, 5),
Point(5, -5) };
Polygon line1(aPts1, aPts1 + count_array(aPts1));
Polygon line2(aPts2, aPts2 + count_array(aPts2));
//both share point (5, 0)
assert(boost::polygon::contains(line1, Point(5, 0)));
assert(boost::polygon::contains(line2, Point(5, 0)));
//eh..., expected it to be 1, but anyway
assert(boost::polygon::size(line1) == 2);
assert(boost::polygon::size(line2) == 2);
PolygonSet ps1;
PolygonSet ps2;
ps1.insert(line1);
ps2.insert(line2);
PolygonSet ps3 = ps1 & ps2;
//gives no result
if (!ps3.empty()) //<---
{
PolygonVector vec1;
ps3.get(vec1);
}
}
Also the documentation states that the size function gives the number of edges,
but a line has only 1 edge:
assert(boost::polygon::size(line1) == 2); //not 1?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net