Skip to content

Commit

Permalink
Visibility: fix algo to detect halfedges
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Nov 20, 2023
1 parent 919eb14 commit e0bfb8f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/algorithm/visibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ visibility(const Geometry &polygon, const Geometry &pointA,

Point_2 startPoint{pointA.as<Point>().toPoint_2()};
Point_2 endPoint{pointB.as<Point>().toPoint_2()};
Point_2 queryPoint{pointB.as<Point>().toPoint_2()};

// insert geometry into the arrangement
CGAL::Polygon_with_holes_2 pwh{
Expand All @@ -175,12 +176,21 @@ visibility(const Geometry &polygon, const Geometry &pointA,

// If the point is in a boundary segment, find the corresponding half edge
Halfedge_const_handle he = arr.halfedges_begin();
while (he->source()->point() != startPoint ||
he->target()->point() != endPoint) {
bool cont = !Segment_2(he->source()->point(), he->target()->point())
.has_on(queryPoint) ||
he->source()->point() == startPoint ||
he->target()->point() == endPoint || he->face()->is_unbounded();
// While we are not in the right half edge, or while q is the source,
// continue
while (cont) {
he++;
if (he == arr.halfedges_end()) {
BOOST_THROW_EXCEPTION(Exception("Can not find corresponding half edge."));
}

cont = !Segment_2(he->source()->point(), he->target()->point())
.has_on(queryPoint) ||
he->source()->point() == queryPoint || he->face()->is_unbounded();
}

// visibility query
Expand Down

0 comments on commit e0bfb8f

Please sign in to comment.