Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

PerturbPolygon.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #ifdef OGDF_INCLUDE_CGAL
34 
36 
37 namespace ogdf {
38 namespace internal {
39 namespace gcm {
40 namespace geometry {
41 
45 template<typename Kernel>
46 Polygon_t<Kernel> peturb(const Polygon_t<Kernel>& polygon, double eps = 1e-5) {
47  using Segment = LineSegment_t<Kernel>;
48 
49  auto bisector = [&](const Segment& s1, const Segment& s2) {
50  const auto& v_in = s1.to_vector();
51  const auto& v_out = s2.to_vector();
52  auto bisected = bisect(-v_in, v_out);
53  if (geometry::right_turn(v_in, bisected)) {
54  bisected = -bisected;
55  }
56 
57  return bisected;
58  };
59 
60  Polygon_t<Kernel> perturbed;
61  auto itr = polygon.edges_circulator();
62  for (unsigned int i = 0; i < polygon.size(); ++i) {
63  perturbed.push_back(polygon[i] + bisector(*(itr - 1), *itr) * eps);
64  ++itr;
65  }
66  return perturbed;
67 }
68 
69 }
70 }
71 }
72 }
73 
74 #endif
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
Polygon.h