From 061830705f46373791ea9551b0f36b6e6e1bb7e8 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 24 Jan 2021 08:45:36 -0800 Subject: [PATCH] simplify with getsize --- src/main/java/org/terasology/math/delaunay/Site.java | 8 ++++---- .../terasology/polyworld/sampling/NaivePointSampling.java | 4 ++-- .../polyworld/sampling/PoissonDiscSampling.java | 8 ++++---- .../polyworld/sampling/PoissonDiscTestView.java | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/terasology/math/delaunay/Site.java b/src/main/java/org/terasology/math/delaunay/Site.java index e30a77e..d998049 100644 --- a/src/main/java/org/terasology/math/delaunay/Site.java +++ b/src/main/java/org/terasology/math/delaunay/Site.java @@ -226,7 +226,7 @@ private void connect(List points, int j, Rectanglef bounds, boolean c points.add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.LEFT) != 0) { - if (rightPoint.y() - bounds.minY + newPoint.y() - bounds.minY < (bounds.maxY - bounds.minY)) { + if (rightPoint.y() - bounds.minY + newPoint.y() - bounds.minY < bounds.getSizeY()) { py = bounds.minY; } else { py = bounds.maxY; @@ -243,7 +243,7 @@ private void connect(List points, int j, Rectanglef bounds, boolean c py = bounds.minY; points.add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.RIGHT) != 0) { - if (rightPoint.y() - bounds.minY + newPoint.y() - bounds.minY < (bounds.maxY - bounds.minY)) { + if (rightPoint.y() - bounds.minY + newPoint.y() - bounds.minY < bounds.getSizeY()) { py = bounds.minY; } else { py = bounds.maxY; @@ -260,7 +260,7 @@ private void connect(List points, int j, Rectanglef bounds, boolean c px = bounds.minX; points.add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.BOTTOM) != 0) { - if (rightPoint.x() - bounds.minX + newPoint.x() - bounds.minX < (bounds.maxX - bounds.minX)) { + if (rightPoint.x() - bounds.minX + newPoint.x() - bounds.minX < bounds.getSizeX()) { px = bounds.minX; } else { px = bounds.maxX; @@ -277,7 +277,7 @@ private void connect(List points, int j, Rectanglef bounds, boolean c px = bounds.minX; points.add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.TOP) != 0) { - if (rightPoint.x() - bounds.minX + newPoint.x() - bounds.minX < (bounds.maxX - bounds.minX)) { + if (rightPoint.x() - bounds.minX + newPoint.x() - bounds.minX < bounds.getSizeX()) { px = bounds.minX; } else { px = bounds.maxX; diff --git a/src/main/java/org/terasology/polyworld/sampling/NaivePointSampling.java b/src/main/java/org/terasology/polyworld/sampling/NaivePointSampling.java index d4a3c37..3694ef3 100644 --- a/src/main/java/org/terasology/polyworld/sampling/NaivePointSampling.java +++ b/src/main/java/org/terasology/polyworld/sampling/NaivePointSampling.java @@ -36,8 +36,8 @@ public class NaivePointSampling implements PointSampling { public List create(Rectanglef bounds, int numSites, Random rng) { List points = Lists.newArrayListWithCapacity(numSites); for (int i = 0; i < numSites; i++) { - float px = bounds.minX + rng.nextFloat() * (bounds.maxX - bounds.minX); - float py = bounds.minY + rng.nextFloat() * (bounds.maxY - bounds.minY); + float px = bounds.minX + rng.nextFloat() * bounds.getSizeX(); + float py = bounds.minY + rng.nextFloat() * bounds.getSizeY(); points.add(new Vector2f(px, py)); } return points; diff --git a/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java b/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java index f722e6c..82ef285 100644 --- a/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java +++ b/src/main/java/org/terasology/polyworld/sampling/PoissonDiscSampling.java @@ -56,8 +56,8 @@ protected float getMinRadius(Rectanglef bounds, int numSites) { int cols = dims.x(); int rows = dims.y(); - float cellWidth = (bounds.maxX - bounds.minX) / cols; - float cellHeight = (bounds.maxY - bounds.minY) / rows; + float cellWidth = bounds.getSizeX() / cols; + float cellHeight = bounds.getSizeY() / rows; float minRad = Math.min(cellHeight, cellWidth) * 0.5f; // they should be identical return minRad; } @@ -69,8 +69,8 @@ public List create(Rectanglef bounds, int numSites, Random rng) { int cols = dims.x(); int rows = dims.y(); - float cellWidth = (bounds.maxX - bounds.minX) / cols; - float cellHeight = (bounds.maxY - bounds.minY) / rows; + float cellWidth = bounds.getSizeX() / cols; + float cellHeight = bounds.getSizeY() / rows; float minRad = getMinRadius(bounds, numSites); diff --git a/src/test/java/org/terasology/polyworld/sampling/PoissonDiscTestView.java b/src/test/java/org/terasology/polyworld/sampling/PoissonDiscTestView.java index d866ca8..e4dba59 100644 --- a/src/test/java/org/terasology/polyworld/sampling/PoissonDiscTestView.java +++ b/src/test/java/org/terasology/polyworld/sampling/PoissonDiscTestView.java @@ -90,8 +90,8 @@ private void drawDebug(Rectanglef bounds, Graphics2D g) { int cols = dims.x(); int rows = dims.y(); - float cellWidth = (float) (bounds.maxX - bounds.minX) / cols; - float cellHeight = (float) (bounds.maxY - bounds.minY) / rows; + float cellWidth = (float) bounds.getSizeX() / cols; + float cellHeight = (float) bounds.getSizeY() / rows; g.translate(bounds.minX, bounds.minY); for (int i = 0; i <= cols; i++) {