Skip to content

Commit

Permalink
Fix issue with vision bounds not including the vision origin
Browse files Browse the repository at this point in the history
The vision sweep is only well-behaved if it has bounds surrounding the origin. It is not enough that we use the vision
bounds since certain cases may not guarantee that the vision shape include the vision origin. So we now make sure to
explicitly expands the sweep bounds to include the origin.

Also some separation of concerns: `EndpointSet` has no reason to know anything about vision, not even just to provide
initial bounds. So now it only tracks the bounding box of its contents and nothing else.
  • Loading branch information
kwvanderlinde committed Jan 17, 2024
1 parent f0c1b37 commit f9d5b4d
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 f9d5b4d

Please sign in to comment.