Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex


Chronological Thread 
  • From: Thomas Kluth <>
  • To:
  • Subject: Re: [cgal-discuss] Polygon_2::Vertex_const_iterator reports wrong first vertex
  • Date: Fri, 23 Jan 2015 02:12:00 -0800 (PST)

Hi,

thanks for pointing me to this.

I've changed my code now, so that getCGALPolygon() returns a pointer to
the CGAL polygon:

Polygon* getCGALPolygon(){
        return &(this->polygon);
}

and the other class calls

Polygon::Vertex_const_iterator vertices =
polygon.getCGALPolygon->vertices_begin()

A quick test showed that my bug disappeared. I hope, I didn't introduced
more bugs now?

However, what keeps being strange is that the code did not show the bug
at Mac OS. But this seems to be a compiler issue, I suppose.

Thanks for the help!

Best,
Thomas


Am 23.01.15 um 09:19 schrieb Sebastien Loriot (GeometryFactory) [via
cgal-discuss]:

>
>
> 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.
>>
>
>

--
Thomas Kluth, Ph.D. Student
Language & Cognition Group
CITEC, University of Bielefeld
web: http://www.techfak.de/~tkluth
My public PGP-key: http://www.techfak.de/~tkluth/0xD6E3EEB3.asc


View this message in context: Re: Polygon_2::Vertex_const_iterator reports wrong first vertex
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.18.

Top of Page