newer CGAL really needs exect kernel for polygon intersections and differences
Stefan

Stefan commited on 2013-07-13 20:29:44
Showing 2 changed files, with 17 additions and 10 deletions.

... ...
@@ -7,7 +7,9 @@
7 7
 #include <iostream>
8 8
 #include <vector>
9 9
 
10
-#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
10
+#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
11
+#include <CGAL/Gmpq.h>
12
+#include <CGAL/number_utils.h>
11 13
 #include <CGAL/Polygon_2.h>
12 14
 #include <CGAL/Polygon_with_holes_2.h>
13 15
 #include <CGAL/Boolean_set_operations_2.h>
... ...
@@ -179,9 +181,10 @@ bool Polygons::createInnerOffset(double offset, Polygons &offsetPolys) const
179 181
   for (poly = mPolys.begin(); poly != mPolys.end(); ++poly) {
180 182
 
181 183
     // create inner offset polygons
184
+    CGAL::Lazy_exact_nt<CGAL::Gmpq> offs(offset);
182 185
     CgPolyHolesPtrVec offPolys =
183 186
       CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2(
184
-        offset, *poly);
187
+        offs, *poly);
185 188
 
186 189
     // add offset polygons to output polygons
187 190
     CgPolyHolesPtrVec::const_iterator offPoly;
... ...
@@ -247,8 +250,9 @@ bool Polygons::fillInnerOffset(double offset, Polygons &offsetPolys) const
247 250
     for (i = 1; ; ++i) {
248 251
 
249 252
       // create inner offset polygons
253
+      CGAL::Lazy_exact_nt<CGAL::Gmpq> offs_i(offset * i);
250 254
       CgPolyPtrVec offPolys =
251
-        CGAL::create_offset_polygons_2<CgPoly>(offset * i, *skel);
255
+        CGAL::create_offset_polygons_2<CgPoly>(offs_i, *skel);
252 256
 
253 257
       // no offset polygons -> done
254 258
       if (offPolys.empty())
... ...
@@ -298,9 +302,12 @@ bool Polygons::createOuterOffsetPoly(const CgPolyHoles &poly, double offset,
298 302
                                      CgPolyHoles &offsetPoly)
299 303
 {
300 304
   // calculate outer offset of outer bondary
305
+  CGAL::Lazy_exact_nt<CGAL::Gmpq> offs(offset);
301 306
   const CgPoly &outer = poly.outer_boundary();
307
+  CgKern kern;
302 308
   CgPolyPtrVec outOffPolys =
303
-    CGAL::create_exterior_skeleton_and_offset_polygons_2(offset, outer);
309
+    CGAL::create_exterior_skeleton_and_offset_polygons_2(
310
+      offs, outer, kern, kern);
304 311
   /* outer Offset should now contain 2 polygons,
305 312
      the artificially added very outer boundary and the offset polygon */
306 313
   if (outOffPolys.size() != 2) {
... ...
@@ -315,7 +322,8 @@ bool Polygons::createOuterOffsetPoly(const CgPolyHoles &poly, double offset,
315 322
     CgPoly holeRev = *hole; // reverse orientation (make hole a normal poly)
316 323
     holeRev.reverse_orientation();
317 324
     CgPolyPtrVec inOffPolys =
318
-      CGAL::create_interior_skeleton_and_offset_polygons_2(offset, holeRev);
325
+      CGAL::create_interior_skeleton_and_offset_polygons_2(
326
+        offs, holeRev, kern, kern);
319 327
     CgPolyPtrVec::iterator inOff; // add inner offset polys as new holes
320 328
     for (inOff = inOffPolys.begin(); inOff != inOffPolys.end(); ++inOff) {
321 329
       (*inOff)->reverse_orientation(); // re-reverse (make poly a hole again)
... ...
@@ -342,10 +350,9 @@ void Polygons::PolyToLayer(const CgPoly &poly, Layer &layer)
342 350
   // add all points
343 351
   CgPoly::Vertex_const_iterator v;
344 352
   for (v = poly.vertices_begin(); v != poly.vertices_end(); ++v)
345
-    path.addPoint(v->x(), v->y());
353
+    path.addPoint(CGAL::to_double(v->x()), CGAL::to_double(v->y()));
346 354
   // add first point again to close path
347
-  v = poly.vertices_begin();
348
-  path.addPoint(v->x(), v->y());
355
+  path.addPoint(path.mPoints.front());
349 356
 }
350 357
 
351 358
 /**
... ...
@@ -9,7 +9,7 @@
9 9
 #include <boost/shared_ptr.hpp>
10 10
 #include <vector>
11 11
 
12
-#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
12
+#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
13 13
 #include <CGAL/Polygon_2.h>
14 14
 #include <CGAL/Polygon_with_holes_2.h>
15 15
 #include <CGAL/create_straight_skeleton_from_polygon_with_holes_2.h>
... ...
@@ -19,7 +19,7 @@
19 19
 /// a set of polygons
20 20
 class Polygons {
21 21
 public:
22
-  typedef CGAL::Exact_predicates_inexact_constructions_kernel CgKern;
22
+  typedef CGAL::Exact_predicates_exact_constructions_kernel CgKern;
23 23
 
24 24
   typedef CgKern::Point_2                    CgPoint;
25 25
   typedef CGAL::Polygon_2<CgKern>            CgPoly;
26 26