Skip to content

Commit

Permalink
simplify with getsize
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Jan 24, 2021
1 parent 407c69d commit a259e2e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/terasology/math/delaunay/Site.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void connect(List<Vector2fc> 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;
Expand All @@ -243,7 +243,7 @@ private void connect(List<Vector2fc> 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;
Expand All @@ -260,7 +260,7 @@ private void connect(List<Vector2fc> 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;
Expand All @@ -277,7 +277,7 @@ private void connect(List<Vector2fc> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class NaivePointSampling implements PointSampling {
public List<Vector2fc> create(Rectanglef bounds, int numSites, Random rng) {
List<Vector2fc> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -69,8 +69,8 @@ public List<Vector2fc> 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);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ 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++) {
g.drawLine((int) (i * cellWidth), 0, (int) (i * cellWidth), (int) (bounds.maxY - bounds.minY));
}
for (int i = 0; i <= rows; i++) {
g.drawLine(0, (int) (i * cellHeight), (int) (bounds.maxX - bounds.minX), (int) (i * cellHeight));
g.drawLine(0, (int) (i * cellHeight), (int) (bounds.getSizeX()), (int) (i * cellHeight));
}
g.translate(-bounds.minX, -bounds.minY);
}
Expand Down

0 comments on commit a259e2e

Please sign in to comment.