Skip to content

Commit

Permalink
short-circuit single point filter
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 24, 2023
1 parent 92c8ff5 commit 90b05ee
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ public record VectorGeometry(int[] commands, GeometryType geomType, int scale) {
private static final int BOTTOM = 1 << 3;
private static final int INSIDE = 0;
private static final int ALL = TOP | LEFT | RIGHT | BOTTOM;
private static final VectorGeometry EMPTY_POINT = new VectorGeometry(new int[0], GeometryType.POINT, 0);

public VectorGeometry {
if (scale < 0) {
Expand Down Expand Up @@ -894,6 +895,10 @@ public VectorGeometry filterPointsOutsideBuffer(double buffer) {
y += zigZagDecode(commands[i++]);
if (x < min || y < min || x > max || y > max) {
if (result == null) {
// short-circuit the common case of only a single point that gets filtered-out
if (commands.length == 3) {
return EMPTY_POINT;
}
result = new IntArrayList(commands.length);
result.add(commands, 0, i - 2);
}
Expand Down

0 comments on commit 90b05ee

Please sign in to comment.