Skip to content

Commit

Permalink
Add methods to add holes to shape and extrude markers
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Dec 29, 2022
1 parent 942cec6 commit ad77b49
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shape> holes = new ArrayList<>();
private float shapeMinY, shapeMaxY;
private boolean depthTest = true;
private int lineWidth = 2;
Expand Down Expand Up @@ -138,6 +143,15 @@ public void setShape(Shape shape, float minY, float maxY) {
this.shapeMaxY = maxY;
}

/**
* Getter for the <b>mutable</b> collection of holes in this {@link ExtrudeMarker}.
* <p>Any shape in this collection will be a hole in the main {@link Shape} of this marker</p>
* @return A <b>mutable</b> collection of hole-shapes
*/
public Collection<Shape> getHoles() {
return holes;
}

/**
* Sets the position of this {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box).
* <p><i>(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)</i></p>
Expand Down Expand Up @@ -272,6 +286,7 @@ public static class Builder extends ObjectMarker.Builder<ExtrudeMarker, Builder>

Shape shape;
float shapeMinY, shapeMaxY;
Collection<Shape> holes = new ArrayList<>();
Boolean depthTest;
Integer lineWidth;
Color lineColor;
Expand All @@ -294,6 +309,25 @@ public Builder shape(Shape shape, float minY, float maxY) {
return this;
}

/**
* <b>Adds</b> 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
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shape> holes = new ArrayList<>();
private float shapeY;
private boolean depthTest = true;
private int lineWidth = 2;
Expand Down Expand Up @@ -119,6 +124,15 @@ public void setShape(Shape shape, float y) {
this.shapeY = y;
}

/**
* Getter for the <b>mutable</b> collection of holes in this {@link ShapeMarker}.
* <p>Any shape in this collection will be a hole in the main {@link Shape} of this marker</p>
* @return A <b>mutable</b> collection of hole-shapes
*/
public Collection<Shape> getHoles() {
return holes;
}

/**
* Sets the position of this {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box).
* <p><i>(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)</i></p>
Expand Down Expand Up @@ -250,6 +264,7 @@ public static class Builder extends ObjectMarker.Builder<ShapeMarker, Builder> {

Shape shape;
float shapeY;
Collection<Shape> holes = new ArrayList<>();
Boolean depthTest;
Integer lineWidth;
Color lineColor;
Expand All @@ -269,6 +284,25 @@ public Builder shape(Shape shape, float y) {
return this;
}

/**
* <b>Adds</b> 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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ad77b49

Please sign in to comment.