|
Boost Users : |
Subject: [Boost-users] [polygon] Incorrect output from get_trapezoids(..., HORIZONTAL)
From: Patrick J. LoPresti (lopresti_at_[hidden])
Date: 2014-10-07 15:29:37
I apologize for sending this to the mailing list, but when I tried to
file a bug report via Trac, it said "Trac thinks your submission might
be Spam. To prove otherwise please provide a response to the
following"... And then there was no "following".
Please let me know if there is a better forum to report this sort of issue.
I am using Boost 1.56. The following program uses boost::polygon to
slice up a figure (with a "hole" cut out of it) into horizontal
trapezoids. The output I get is:
Output:
polygon (4 3) (4 0) (0 0) (0 3) (4 3)
...which is clearly wrong. I am pretty sure my code is correct,
because if I replace bg::HORIZONTAL with bg::VERTICAL, I get the
correct output of a bunch of vertical trapezoids.
For my application, I really want horizontal traps. I suppose I can
just swap x and y on input and output... But this seemed worth
reporting.
Thanks.
- Pat
#include <boost/polygon/polygon.hpp>
#include <iostream>
namespace bp = boost::polygon;
typedef bp::polygon_set_data<int> PolygonSet;
typedef bp::polygon_data<PolygonSet::coordinate_type> Polygon;
typedef bp::polygon_traits<Polygon>::point_type Point;
std::ostream &
operator<<(std::ostream &os, const Point &pt)
{
return os << "(" << bp::x(pt) << " " << bp::y(pt) << ")";
}
std::ostream &
operator<<(std::ostream &os, const Polygon &poly)
{
os << "polygon ";
for (Polygon::iterator_type p = poly.begin() ; p != poly.end() ; ++p)
os << " " << *p;
return os;
}
std::ostream &
operator<<(std::ostream &os, const PolygonSet &ps)
{
std::vector<Polygon> temp;
ps.get(temp);
os << "polygonset ";
for (std::vector<Polygon>::const_iterator p = temp.begin()
; p != temp.end() ; ++p)
os << " " << *p;
return os;
}
int
main(int argc, char *argv[])
{
const Point points[] = {
Point(2,0),
Point(4,0),
Point(4,3),
Point(0,3),
Point(0,0),
Point(2,0),
Point(2,1),
Point(1,1),
Point(1,2),
Point(3,2),
Point(3,1),
Point(2,1)
};
Polygon poly;
bp::set_points(poly, &points[0],
&points[sizeof(points)/sizeof(points[0])]);
std::cout << "Input: " << poly << "\n";
PolygonSet ps;
ps.insert(poly);
std::cout << "ps = " << ps << "\n";
std::vector<Polygon> traps;
// Note: bp::VERTICAL works fine
bp::get_trapezoids(traps, ps, bp::HORIZONTAL);
std::cout << "Output:\n";
for (std::vector<Polygon>::const_iterator p = traps.begin()
; p != traps.end() ; ++p)
std::cout << *p << "\n";
}
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