From ad77b492dde3b50ffd79860b2ae0b71640b117c2 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Thu, 29 Dec 2022 17:39:28 +0100 Subject: [PATCH] Add methods to add holes to shape and extrude markers --- .../bluemap/api/markers/ExtrudeMarker.java | 35 +++++++++++++++++++ .../bluemap/api/markers/ShapeMarker.java | 35 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/main/java/de/bluecolored/bluemap/api/markers/ExtrudeMarker.java b/src/main/java/de/bluecolored/bluemap/api/markers/ExtrudeMarker.java index 69b77fe..8dff3e2 100644 --- a/src/main/java/de/bluecolored/bluemap/api/markers/ExtrudeMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/markers/ExtrudeMarker.java @@ -30,13 +30,18 @@ import de.bluecolored.bluemap.api.math.Color; import de.bluecolored.bluemap.api.math.Shape; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Objects; +@SuppressWarnings("FieldMayBeFinal") @DebugDump public class ExtrudeMarker extends ObjectMarker { private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1); private Shape shape; + private Collection holes = new ArrayList<>(); private float shapeMinY, shapeMaxY; private boolean depthTest = true; private int lineWidth = 2; @@ -138,6 +143,15 @@ public void setShape(Shape shape, float minY, float maxY) { this.shapeMaxY = maxY; } + /** + * Getter for the mutable collection of holes in this {@link ExtrudeMarker}. + *

Any shape in this collection will be a hole in the main {@link Shape} of this marker

+ * @return A mutable collection of hole-shapes + */ + public Collection getHoles() { + return holes; + } + /** * Sets the position of this {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box). *

(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)

@@ -272,6 +286,7 @@ public static class Builder extends ObjectMarker.Builder Shape shape; float shapeMinY, shapeMaxY; + Collection holes = new ArrayList<>(); Boolean depthTest; Integer lineWidth; Color lineColor; @@ -294,6 +309,25 @@ public Builder shape(Shape shape, float minY, float maxY) { return this; } + /** + * Adds some hole-{@link Shape}s. + * @param holes the additional holes + * @return this builder for chaining + */ + public Builder holes(Shape... holes) { + this.holes.addAll(Arrays.asList(holes)); + return this; + } + + /** + * Removes all hole-shapes from this Builder. + * @return this builder for chaining + */ + public Builder clearHoles() { + this.holes.clear(); + return this; + } + /** * Sets the position of the {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box). * @return this builder for chaining @@ -361,6 +395,7 @@ public ExtrudeMarker build() { shapeMinY, shapeMaxY ); + marker.getHoles().addAll(holes); if (depthTest != null) marker.setDepthTestEnabled(depthTest); if (lineWidth != null) marker.setLineWidth(lineWidth); if (lineColor != null) marker.setLineColor(lineColor); diff --git a/src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java b/src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java index ddc5fbc..5bc6a71 100644 --- a/src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java @@ -31,13 +31,18 @@ import de.bluecolored.bluemap.api.math.Color; import de.bluecolored.bluemap.api.math.Shape; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Objects; +@SuppressWarnings("FieldMayBeFinal") @DebugDump public class ShapeMarker extends ObjectMarker { private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1); private Shape shape; + private Collection holes = new ArrayList<>(); private float shapeY; private boolean depthTest = true; private int lineWidth = 2; @@ -119,6 +124,15 @@ public void setShape(Shape shape, float y) { this.shapeY = y; } + /** + * Getter for the mutable collection of holes in this {@link ShapeMarker}. + *

Any shape in this collection will be a hole in the main {@link Shape} of this marker

+ * @return A mutable collection of hole-shapes + */ + public Collection getHoles() { + return holes; + } + /** * Sets the position of this {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box). *

(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)

@@ -250,6 +264,7 @@ public static class Builder extends ObjectMarker.Builder { Shape shape; float shapeY; + Collection holes = new ArrayList<>(); Boolean depthTest; Integer lineWidth; Color lineColor; @@ -269,6 +284,25 @@ public Builder shape(Shape shape, float y) { return this; } + /** + * Adds some hole-{@link Shape}s. + * @param holes the additional holes + * @return this builder for chaining + */ + public Builder holes(Shape... holes) { + this.holes.addAll(Arrays.asList(holes)); + return this; + } + + /** + * Removes all hole-shapes from this Builder. + * @return this builder for chaining + */ + public Builder clearHoles() { + this.holes.clear(); + return this; + } + /** * Sets the position of the {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box). * @return this builder for chaining @@ -334,6 +368,7 @@ public ShapeMarker build() { checkNotNull(shape, "shape"), shapeY ); + marker.getHoles().addAll(holes); if (depthTest != null) marker.setDepthTestEnabled(depthTest); if (lineWidth != null) marker.setLineWidth(lineWidth); if (lineColor != null) marker.setLineColor(lineColor);