Subject: CGAL users discussion list
List archive
- From: "Sebastien Loriot (GeometryFactory)" <>
- To:
- Subject: Re: [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex
- Date: Fri, 23 Jan 2015 09:22:56 +0100
- Organization: GeometryFactory
The bug is in your code.
You return the polygon by copy.
When you write:
Polygon::Vertex_const_iterator vertices = polygon.getCGALPolygon().vertices_begin();
you are taking an iterator to a std::vector that get destroyed at the
end of the line.
Then when you are using the iterator the object having been
destroyed you get only crappy things.
Sebastien.
On 01/20/2015 11:24 AM, Thomas Kluth wrote:
Dear CGAL-Team,
I think I found a bug in the Polygon_2::Vertex_const_iterator.
I've attached a minimal working example that you should be able to compile
and run with
cmake .
make
./polytest
You should see this output:
cgal version: 4.5.1
Polygon: Polygon_2(
PointC2(10, 20)
PointC2(10, 40)
PointC2(50, 20)
)
first vertex: PointC2(10, 20)
vertices of the polygon from Printer.hhp:
CGAl Point: PointC2(0, 20)
raw coordinates: 0, 20
CGAl Point: PointC2(10, 40)
raw coordinates: 10, 40
CGAl Point: PointC2(50, 20)
raw coordinates: 50, 20
first vertex again:
CGAl Point: PointC2(10, 20)
raw coordinates: 10, 20
The bug here is that Polygon_2::Vertex_const_iterator gives a wrong value of
the x-value of the first vertex of the polygon in Printer.hpp, but not in
MyPolygon.hpp (0 instead of 10).
Furthermore, the same call of polygon.vertices_begin() gives a different
output in the Printer.hpp. Please look to the attached code to understand
the failure.
The output was generated with CGAL 4.5.1 on Fedora 21, the version that is
in the repository. I had similar prolems with CGAL 4.4.x on Fedora 20.
Interestingly, the bug does _not_ happen with the same code and CGAL 4.5 on
Mac OS X 10.7.5, installed via homebrew.
It might be that I just have to little knowledge about objects, classes and
CGAL and this is not a bug but actually I did a mistake.
If this is the case I would be happy to know, how to pass CGAL-Objects from
one object to another object correctly.
Otherwise I'm asking you to fix the bug.
Thank you!
Thomas Kluth
P.S.: It might be that my example is not minimal, but it reflects the way I
use CGAL in my bigger project. cgalbug.zip
<http://cgal-discuss.949826.n4.nabble.com/file/n4660327/cgalbug.zip>
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Polygon-2-Vertex-const-iterator-reports-wrong-first-vertex-tp4660327.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex, Thomas Kluth, 01/20/2015
- Re: [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex, Sebastien Loriot (GeometryFactory), 01/23/2015
- Re: [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex, Thomas Kluth, 01/23/2015
- Re: [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex, Sebastien Loriot (GeometryFactory), 01/23/2015
Archive powered by MHonArc 2.6.18.