Rename SpatialUtils2

This commit is contained in:
extio-de
2025-12-26 16:08:30 +01:00
parent 3c840220a1
commit a119b4b5e9
6 changed files with 26 additions and 26 deletions

View File

@@ -16,7 +16,7 @@ import de.extio.game_engine.renderer.model.RenderingBo;
import de.extio.game_engine.renderer.model.RenderingBoLayer;
import de.extio.game_engine.renderer.model.bo.DrawEffectRenderingBo;
import de.extio.game_engine.renderer.model.bo.DrawEffectRenderingBoEffects;
import de.extio.game_engine.spatial2.WorldUtils2;
import de.extio.game_engine.spatial2.SpatialUtils2;
import de.extio.game_engine.spatial2.model.Area2;
import de.extio.game_engine.spatial2.model.CoordI2;
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
@@ -65,7 +65,7 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
final var x1 = x0 + coordinates.get(0).getX();
final var y1 = y0 + coordinates.get(0).getY();
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
final var area = SpatialUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
if (this.cull(area)) {
break;
}
@@ -84,7 +84,7 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
final var x1 = x0 + coordinates.get(0).getX();
final var y1 = y0 + coordinates.get(0).getY();
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
final var area = SpatialUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
if (this.cull(area)) {
break;
}
@@ -168,7 +168,7 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
yn = xn * sin + yn * cos + y0;
xn = x;
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create((int) xm, (int) ym), ImmutableCoordI2.create((int) xn, (int) yn));
final var area = SpatialUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create((int) xm, (int) ym), ImmutableCoordI2.create((int) xn, (int) yn));
if (this.cull(area)) {
break;
}
@@ -190,7 +190,7 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
final var x2 = x0 + coordinates.get(1).getX();
final var y2 = y0 + coordinates.get(1).getY();
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create(x2, y2));
final var area = SpatialUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1), ImmutableCoordI2.create(x2, y2));
if (this.cull(area)) {
break;
}
@@ -210,7 +210,7 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
final var x1 = x0 + coordinates.get(0).getX();
final var y1 = y0 + coordinates.get(0).getY();
final var area = WorldUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
final var area = SpatialUtils2.pointsToArea(ImmutableCoordI2.create(x0, y0), ImmutableCoordI2.create(x1, y1));
if (this.cull(area)) {
break;
}
@@ -243,7 +243,7 @@ public class G2DDrawEffect extends G2DAbstractRenderingBo implements DrawEffectR
private boolean cull(final Area2 area) {
final Frame mainFrame = ((G2DRenderer) this.rendererData.getRenderer()).getMainFrame();
return !WorldUtils2.intersects(area, new Area2(ImmutableCoordI2.zero(), MutableCoordI2.create(mainFrame.getWidth(), mainFrame.getHeight())));
return !SpatialUtils2.intersects(area, new Area2(ImmutableCoordI2.zero(), MutableCoordI2.create(mainFrame.getWidth(), mainFrame.getHeight())));
}
@Override

View File

@@ -14,7 +14,7 @@ import de.extio.game_engine.renderer.g2d.G2DRenderingHintFactory;
import de.extio.game_engine.renderer.g2d.control.G2DDrawControlTooltip;
import de.extio.game_engine.renderer.g2d.control.G2DDrawControlTooltip.TooltipRecord;
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl;
import de.extio.game_engine.spatial2.WorldUtils2;
import de.extio.game_engine.spatial2.SpatialUtils2;
import de.extio.game_engine.spatial2.model.CoordI2;
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
@@ -218,7 +218,7 @@ public abstract class G2DBaseControlImpl implements BaseControl {
if (this.enabled &&
this.tooltip != null &&
this.tooltipMousePosition != null &&
WorldUtils2.isInBounds(this.tooltipMousePosition, ImmutableCoordI2.create(Math.max(1, this.width), Math.max(1, this.height)))) {
SpatialUtils2.isInBounds(this.tooltipMousePosition, ImmutableCoordI2.create(Math.max(1, this.width), Math.max(1, this.height)))) {
G2DDrawControlTooltip.TOOLTIP = new TooltipRecord(ImmutableCoordI2.create(this.x + 10 + this.tooltipMousePosition.getX(), this.y + 10 + this.tooltipMousePosition.getY()), this.tooltip);
}

View File

@@ -23,7 +23,7 @@ import de.extio.game_engine.util.rng.ThreadLocalXorShift128Random;
/**
* Library for geometric problems
*/
public final class WorldUtils2 {
public final class SpatialUtils2 {
/**
* The Pythagorean theorem

View File

@@ -6,7 +6,7 @@ import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import de.extio.game_engine.spatial2.WorldUtils2;
import de.extio.game_engine.spatial2.SpatialUtils2;
import de.extio.game_engine.spatial2.model.CoordI2;
import de.extio.game_engine.spatial2.model.ImmutableCoordI2;
import de.extio.game_engine.spatial2.model.SpatialIndex2Capable;
@@ -51,7 +51,7 @@ public final class LinearSearchIndex2D<T extends SpatialIndex2Capable> implement
for (var i = 0; i < this.objects.size(); i++) {
final var obj = this.objects.get(i);
if (WorldUtils2.intersects(position, dimension, obj.getPosition(), obj.getDimension())) {
if (SpatialUtils2.intersects(position, dimension, obj.getPosition(), obj.getDimension())) {
if (filter == null || filter.test(obj)) {
if (result == null) {
result = new ArrayList<>(dimension.equals(ImmutableCoordI2.one()) ? RESULT_DIM_START : this.resultDim);
@@ -76,7 +76,7 @@ public final class LinearSearchIndex2D<T extends SpatialIndex2Capable> implement
for (var i = 0; i < this.objects.size(); i++) {
final var obj = this.objects.get(i);
if (WorldUtils2.intersects(position, ImmutableCoordI2.one(), obj.getPosition(), obj.getDimension())) {
if (SpatialUtils2.intersects(position, ImmutableCoordI2.one(), obj.getPosition(), obj.getDimension())) {
if (filter == null || filter.test(obj)) {
return obj;
}
@@ -91,7 +91,7 @@ public final class LinearSearchIndex2D<T extends SpatialIndex2Capable> implement
for (var i = 0; i < this.objects.size(); i++) {
final var obj = this.objects.get(i);
if (WorldUtils2.intersects(position, ImmutableCoordI2.one(), obj.getPosition(), obj.getDimension())) {
if (SpatialUtils2.intersects(position, ImmutableCoordI2.one(), obj.getPosition(), obj.getDimension())) {
if (filter == null || filter.test(obj)) {
consumer.accept(obj);
}

View File

@@ -1,6 +1,6 @@
package de.extio.game_engine.spatial2.model;
import de.extio.game_engine.spatial2.WorldUtils2;
import de.extio.game_engine.spatial2.SpatialUtils2;
/**
* Helper to convert between mutable and immutable representations of tuples (coordinates and vectors)
@@ -59,7 +59,7 @@ public interface Coord2Conversion {
vNorm = (CoordD2) this;
}
final var length = WorldUtils2.getDistance(vNorm);
final var length = SpatialUtils2.getDistance(vNorm);
if (length > 0.0) {
vNorm = vNorm.divide(length);
}

View File

@@ -80,10 +80,10 @@ public class WorldUtils2Tests {
public void testWorldUtils2PointsToArea() {
final CoordI2 point0 = ImmutableCoordI2.create(6, 8);
final CoordI2 point1 = ImmutableCoordI2.create(6, 9);
assertEquals(ImmutableCoordI2.create(6, 8), WorldUtils2.pointsToArea(point0, point1).getPosition());
assertEquals(ImmutableCoordI2.create(1, 2), WorldUtils2.pointsToArea(point0, point1).getDimension());
assertEquals(ImmutableCoordI2.create(6, 8), WorldUtils2.pointsToArea(point1, point0).getPosition());
assertEquals(ImmutableCoordI2.create(1, 2), WorldUtils2.pointsToArea(point1, point0).getDimension());
assertEquals(ImmutableCoordI2.create(6, 8), SpatialUtils2.pointsToArea(point0, point1).getPosition());
assertEquals(ImmutableCoordI2.create(1, 2), SpatialUtils2.pointsToArea(point0, point1).getDimension());
assertEquals(ImmutableCoordI2.create(6, 8), SpatialUtils2.pointsToArea(point1, point0).getPosition());
assertEquals(ImmutableCoordI2.create(1, 2), SpatialUtils2.pointsToArea(point1, point0).getDimension());
}
@Test
@@ -97,20 +97,20 @@ public class WorldUtils2Tests {
public void testSector() {
final Area2 area = new Area2(ImmutableCoordI2.create(100, 100), ImmutableCoordI2.create(20, 20));
assertEquals(Edge2.RIGHT, WorldUtils2.getSector(ImmutableCoordI2.create(120, 110), area));
assertEquals(Edge2.LEFT, WorldUtils2.getSector(ImmutableCoordI2.create(105, 110), area));
assertEquals(Edge2.TOP, WorldUtils2.getSector(ImmutableCoordI2.create(110, 100), area));
assertEquals(Edge2.BOTTOM, WorldUtils2.getSector(ImmutableCoordI2.create(110, 120), area));
assertEquals(Edge2.RIGHT, SpatialUtils2.getSector(ImmutableCoordI2.create(120, 110), area));
assertEquals(Edge2.LEFT, SpatialUtils2.getSector(ImmutableCoordI2.create(105, 110), area));
assertEquals(Edge2.TOP, SpatialUtils2.getSector(ImmutableCoordI2.create(110, 100), area));
assertEquals(Edge2.BOTTOM, SpatialUtils2.getSector(ImmutableCoordI2.create(110, 120), area));
}
@Test
public void testPedalNaN() {
final CoordD2 result = WorldUtils2.getPedalOnLineSegmentAB(ImmutableCoordI2.create(-802, -905), ImmutableCoordI2.create(-805, -887), ImmutableCoordI2.create(-804, -893));
final CoordD2 result = SpatialUtils2.getPedalOnLineSegmentAB(ImmutableCoordI2.create(-802, -905), ImmutableCoordI2.create(-805, -887), ImmutableCoordI2.create(-804, -893));
assertNull(result);
}
private void calcAngle(final CoordD2 v0, final CoordD2 v1) {
System.out.println(WorldUtils2.getVectorAngle(v0, v1) + " " + v0 + " " + v1);
System.out.println(SpatialUtils2.getVectorAngle(v0, v1) + " " + v0 + " " + v1);
}
}