Skip to content

Commit

Permalink
Merge pull request #4645 from kwvanderlinde/bugfix/4637-vision-sweep-…
Browse files Browse the repository at this point in the history
…bounds-not-around-origin

Fix issue with vision bounds not including the vision origin
  • Loading branch information
cwisniew authored Jan 21, 2024
2 parents f0c1b37 + f9d5b4d commit dbb53bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class EndpointSet {

private final int[] bucketSizes;

public EndpointSet(Coordinate origin, Envelope bounds) {
public EndpointSet(Coordinate origin) {
this.origin = origin;
this.envelope = new Envelope(bounds);
this.envelope = new Envelope();

this.buckets = new VisibilitySweepEndpoint[BUCKET_COUNT][];
Arrays.setAll(this.buckets, i -> new VisibilitySweepEndpoint[32]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public class VisibilityProblem {
*/
private final EndpointSet endpointSet;

/**
* Bounds on the vision and origin.
*
* <p>This will be used to guarantee that we have endpoints in every direction around the origin,
* and that we avoid infinite results.
*/
private final Envelope bounds;

/**
* The set of walls that are intersected by the current event line.
*
Expand All @@ -66,7 +74,9 @@ public class VisibilityProblem {
*/
public VisibilityProblem(Coordinate origin, Envelope visionBounds) {
this.origin = origin;
this.endpointSet = new EndpointSet(origin, visionBounds);
this.endpointSet = new EndpointSet(origin);
this.bounds = new Envelope(visionBounds);
this.bounds.expandToInclude(origin);
this.openWalls = new TreeSet<>(this::compareOpenWalls);
}

Expand Down Expand Up @@ -145,6 +155,7 @@ public void add(List<Coordinate> string) {

timer.start("add bounds");
final var envelope = endpointSet.getBounds();
envelope.expandToInclude(this.bounds);
// Exact expansion distance doesn't matter, we just don't want the boundary walls to overlap
// endpoints from real walls.
envelope.expandBy(1.0);
Expand Down

0 comments on commit dbb53bf

Please sign in to comment.