Skip to content

Commit ad77b49

Browse files
committed
Add methods to add holes to shape and extrude markers
1 parent 942cec6 commit ad77b49

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/main/java/de/bluecolored/bluemap/api/markers/ExtrudeMarker.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@
3030
import de.bluecolored.bluemap.api.math.Color;
3131
import de.bluecolored.bluemap.api.math.Shape;
3232

33+
import java.util.ArrayList;
34+
import java.util.Arrays;
35+
import java.util.Collection;
3336
import java.util.Objects;
3437

38+
@SuppressWarnings("FieldMayBeFinal")
3539
@DebugDump
3640
public class ExtrudeMarker extends ObjectMarker {
3741
private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1);
3842

3943
private Shape shape;
44+
private Collection<Shape> holes = new ArrayList<>();
4045
private float shapeMinY, shapeMaxY;
4146
private boolean depthTest = true;
4247
private int lineWidth = 2;
@@ -138,6 +143,15 @@ public void setShape(Shape shape, float minY, float maxY) {
138143
this.shapeMaxY = maxY;
139144
}
140145

146+
/**
147+
* Getter for the <b>mutable</b> collection of holes in this {@link ExtrudeMarker}.
148+
* <p>Any shape in this collection will be a hole in the main {@link Shape} of this marker</p>
149+
* @return A <b>mutable</b> collection of hole-shapes
150+
*/
151+
public Collection<Shape> getHoles() {
152+
return holes;
153+
}
154+
141155
/**
142156
* Sets the position of this {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box).
143157
* <p><i>(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)</i></p>
@@ -272,6 +286,7 @@ public static class Builder extends ObjectMarker.Builder<ExtrudeMarker, Builder>
272286

273287
Shape shape;
274288
float shapeMinY, shapeMaxY;
289+
Collection<Shape> holes = new ArrayList<>();
275290
Boolean depthTest;
276291
Integer lineWidth;
277292
Color lineColor;
@@ -294,6 +309,25 @@ public Builder shape(Shape shape, float minY, float maxY) {
294309
return this;
295310
}
296311

312+
/**
313+
* <b>Adds</b> some hole-{@link Shape}s.
314+
* @param holes the additional holes
315+
* @return this builder for chaining
316+
*/
317+
public Builder holes(Shape... holes) {
318+
this.holes.addAll(Arrays.asList(holes));
319+
return this;
320+
}
321+
322+
/**
323+
* Removes all hole-shapes from this Builder.
324+
* @return this builder for chaining
325+
*/
326+
public Builder clearHoles() {
327+
this.holes.clear();
328+
return this;
329+
}
330+
297331
/**
298332
* Sets the position of the {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box).
299333
* @return this builder for chaining
@@ -361,6 +395,7 @@ public ExtrudeMarker build() {
361395
shapeMinY,
362396
shapeMaxY
363397
);
398+
marker.getHoles().addAll(holes);
364399
if (depthTest != null) marker.setDepthTestEnabled(depthTest);
365400
if (lineWidth != null) marker.setLineWidth(lineWidth);
366401
if (lineColor != null) marker.setLineColor(lineColor);

src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@
3131
import de.bluecolored.bluemap.api.math.Color;
3232
import de.bluecolored.bluemap.api.math.Shape;
3333

34+
import java.util.ArrayList;
35+
import java.util.Arrays;
36+
import java.util.Collection;
3437
import java.util.Objects;
3538

39+
@SuppressWarnings("FieldMayBeFinal")
3640
@DebugDump
3741
public class ShapeMarker extends ObjectMarker {
3842
private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1);
3943

4044
private Shape shape;
45+
private Collection<Shape> holes = new ArrayList<>();
4146
private float shapeY;
4247
private boolean depthTest = true;
4348
private int lineWidth = 2;
@@ -119,6 +124,15 @@ public void setShape(Shape shape, float y) {
119124
this.shapeY = y;
120125
}
121126

127+
/**
128+
* Getter for the <b>mutable</b> collection of holes in this {@link ShapeMarker}.
129+
* <p>Any shape in this collection will be a hole in the main {@link Shape} of this marker</p>
130+
* @return A <b>mutable</b> collection of hole-shapes
131+
*/
132+
public Collection<Shape> getHoles() {
133+
return holes;
134+
}
135+
122136
/**
123137
* Sets the position of this {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box).
124138
* <p><i>(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)</i></p>
@@ -250,6 +264,7 @@ public static class Builder extends ObjectMarker.Builder<ShapeMarker, Builder> {
250264

251265
Shape shape;
252266
float shapeY;
267+
Collection<Shape> holes = new ArrayList<>();
253268
Boolean depthTest;
254269
Integer lineWidth;
255270
Color lineColor;
@@ -269,6 +284,25 @@ public Builder shape(Shape shape, float y) {
269284
return this;
270285
}
271286

287+
/**
288+
* <b>Adds</b> some hole-{@link Shape}s.
289+
* @param holes the additional holes
290+
* @return this builder for chaining
291+
*/
292+
public Builder holes(Shape... holes) {
293+
this.holes.addAll(Arrays.asList(holes));
294+
return this;
295+
}
296+
297+
/**
298+
* Removes all hole-shapes from this Builder.
299+
* @return this builder for chaining
300+
*/
301+
public Builder clearHoles() {
302+
this.holes.clear();
303+
return this;
304+
}
305+
272306
/**
273307
* Sets the position of the {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box).
274308
* @return this builder for chaining
@@ -334,6 +368,7 @@ public ShapeMarker build() {
334368
checkNotNull(shape, "shape"),
335369
shapeY
336370
);
371+
marker.getHoles().addAll(holes);
337372
if (depthTest != null) marker.setDepthTestEnabled(depthTest);
338373
if (lineWidth != null) marker.setLineWidth(lineWidth);
339374
if (lineColor != null) marker.setLineColor(lineColor);

0 commit comments

Comments
 (0)