Bound slope placement rotation

- Use the radial three-dimensional bound whenever rotateTowardsSlope is set, including placements whose configured rotation is disabled
- Group the support read margin helper with the other static factories
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-21 21:09:57 -04:00
1 parent 7aaf346ce3
commit b34e5e7676
2 files changed
+20 -9

No files matched your search

@@ -61,6 +61,10 @@ public record PlacementReach(int horizontal, int readMargin) {
return new Profile(Objects.requireNonNull(placement, "placement")); return new Profile(Objects.requireNonNull(placement, "placement"));
} }
public static int supportReadMargin(int surfaceSupportBuffer) {
return 1 + Math.max(0, surfaceSupportBuffer);
}
public int input() { public int input() {
return saturate((long) horizontal + readMargin); return saturate((long) horizontal + readMargin);
} }
@@ -75,10 +79,6 @@ public record PlacementReach(int horizontal, int readMargin) {
return minimumReadMargin <= readMargin ? this : new PlacementReach(horizontal, minimumReadMargin); return minimumReadMargin <= readMargin ? this : new PlacementReach(horizontal, minimumReadMargin);
} }
public static int supportReadMargin(int surfaceSupportBuffer) {
return 1 + Math.max(0, surfaceSupportBuffer);
}
private static int roundedBound(double maximumMagnitude) { private static int roundedBound(double maximumMagnitude) {
return saturate((long) Math.floor(maximumMagnitude + 0.5D + ROUNDING_SLACK)); return saturate((long) Math.floor(maximumMagnitude + 0.5D + ROUNDING_SLACK));
} }
@@ -99,6 +99,7 @@ public record PlacementReach(int horizontal, int readMargin) {
private final IrisBlockVector translation; private final IrisBlockVector translation;
private final boolean rotating; private final boolean rotating;
private final boolean radial; private final boolean radial;
private final boolean vertical;
private final int[] spinsX; private final int[] spinsX;
private final int[] spinsY; private final int[] spinsY;
private final int[] spinsZ; private final int[] spinsZ;
@@ -117,7 +118,9 @@ public record PlacementReach(int horizontal, int readMargin) {
this.spinsY = rotating ? distinctSpins(configuredRotation, Axis.Y) : new int[]{0}; this.spinsY = rotating ? distinctSpins(configuredRotation, Axis.Y) : new int[]{0};
this.spinsZ = rotating ? distinctSpins(configuredRotation, Axis.Z) : new int[]{0}; this.spinsZ = rotating ? distinctSpins(configuredRotation, Axis.Z) : new int[]{0};
long kernels = (long) spinsX.length * spinsY.length * spinsZ.length; long kernels = (long) spinsX.length * spinsY.length * spinsZ.length;
this.radial = rotating && (placement.isRotateTowardsSlope() || kernels > MAXIMUM_ROTATION_KERNELS); this.radial = placement.isRotateTowardsSlope() || (rotating && kernels > MAXIMUM_ROTATION_KERNELS);
this.vertical = placement.isRotateTowardsSlope()
|| (rotating && (configuredRotation.canRotateX() || configuredRotation.canRotateZ()));
this.additive = saturate((long) warpReach(placement.getWarp()) + vacuumReach(placement)); this.additive = saturate((long) warpReach(placement.getWarp()) + vacuumReach(placement));
this.readMargin = supportReadMargin(placement.getSurfaceSupportBuffer()); this.readMargin = supportReadMargin(placement.getSurfaceSupportBuffer());
} }
@@ -134,12 +137,12 @@ public record PlacementReach(int horizontal, int readMargin) {
} }
private int rotatedReach(Extent extent) { private int rotatedReach(Extent extent) {
if (!rotating) {
return unrotatedReach(extent);
}
if (radial) { if (radial) {
return radialReach(extent); return radialReach(extent);
} }
if (!rotating) {
return unrotatedReach(extent);
}
double maximum = 0D; double maximum = 0D;
for (int spinX : spinsX) { for (int spinX : spinsX) {
for (int spinY : spinsY) { for (int spinY : spinsY) {
@@ -172,7 +175,6 @@ public record PlacementReach(int horizontal, int readMargin) {
} }
private int radialReach(Extent extent) { private int radialReach(Extent extent) {
boolean vertical = rotation.canRotateX() || rotation.canRotateZ();
double translateX = translation == null ? 0D : translation.getX(); double translateX = translation == null ? 0D : translation.getX();
double translateY = translation == null ? 0D : translation.getY(); double translateY = translation == null ? 0D : translation.getY();
double translateZ = translation == null ? 0D : translation.getZ(); double translateZ = translation == null ? 0D : translation.getZ();
@@ -107,6 +107,15 @@ public class PlacementReachTest {
assertEquals(14, PlacementReach.of(object, placement, 1D).horizontal()); assertEquals(14, PlacementReach.of(object, placement, 1D).horizontal());
} }
@Test
public void slopeRotationIsBoundedEvenWhenTheConfiguredRotationIsDisabled() {
IrisObject object = singleBlockObject(21, 9, 21);
IrisObjectPlacement placement = new IrisObjectPlacement().setRotation(IrisObjectRotation.of(0D, 0D, 0D));
assertEquals(10, PlacementReach.of(object, placement, 1D).horizontal());
assertEquals(15, PlacementReach.of(object, placement.setRotateTowardsSlope(true), 1D).horizontal());
}
@Test @Test
public void unionKeepsTheLargestReachAndTheLargestInput() { public void unionKeepsTheLargestReachAndTheLargestInput() {
PlacementReach union = new PlacementReach(10, 2).union(new PlacementReach(4, 12)); PlacementReach union = new PlacementReach(10, 2).union(new PlacementReach(4, 12));