Skip to content

Commit

Permalink
Handle infinite & empty regions
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 committed Nov 3, 2024
1 parent 2402a58 commit 4d021f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/tc/oc/pgm/regions/RegionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,12 @@ public MirroredRegion parseMirror(Element el) throws InvalidXMLException {

@MethodParser("resize")
public ResizedRegion parseResize(Element el) throws InvalidXMLException {
Region child = this.parseChildren(el);
Vector min = parser.vector(el, "min").attr().required();
Vector max = parser.vector(el, "max").attr().required();
boolean relative = parser.parseBool(el, "relative").attr().orFalse();
return new ResizedRegion(this.parseChildren(el), min, max, relative);
validate(child, BlockBoundedValidation.INSTANCE, new Node(el));
return new ResizedRegion(child, min, max, relative);
}

@MethodParser("everywhere")
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/tc/oc/pgm/regions/ResizedRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ private void ensureInitialized() {
if (matrix != null) return;

var oldBounds = region.getBounds();
if (oldBounds.isEmpty() || !oldBounds.isBlockFinite()) {
this.bounds = oldBounds;
this.matrix = this.inverse = TransformMatrix.identity();
return;
}

var oldSize = oldBounds.getSize();

if (relative) {
Expand Down
18 changes: 17 additions & 1 deletion util/src/main/java/tc/oc/pgm/util/math/TransformMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
import org.bukkit.util.Vector;

public class TransformMatrix {

private static final TransformMatrix IDENTITY = new TransformMatrix(new double[] {
1, 0, 0, 0, //
0, 1, 0, 0, //
0, 0, 1, 0, //
0, 0, 0, 1 //
});
private final double[] matrix;

private TransformMatrix(double[] matrix) {
this.matrix = matrix;
}

public static TransformMatrix identity() {
return IDENTITY;
}

public static TransformMatrix translate(Vector vector) {
return new TransformMatrix(new double[] {
1, 0, 0, vector.getX(),
Expand All @@ -31,7 +42,12 @@ public static TransformMatrix scale(Vector vector) {
double x = vector.getX();
double y = vector.getY();
double z = vector.getZ();
return new TransformMatrix(new double[] {x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1});
return new TransformMatrix(new double[] {
x, 0, 0, 0, //
0, y, 0, 0, //
0, 0, z, 0, //
0, 0, 0, 1 //
});
}

public static TransformMatrix concat(TransformMatrix... a) {
Expand Down

0 comments on commit 4d021f9

Please sign in to comment.