Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(JOML): migrate polyworlds #35

Merged
merged 16 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions src/main/java/org/terasology/math/delaunay/Edge.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

package org.terasology.math.delaunay;

import org.joml.Vector2f;
import org.joml.Vector2fc;
import org.terasology.joml.geom.Rectanglef;

import java.util.EnumMap;
import java.util.Map;

import org.terasology.math.geom.BaseVector2f;
import org.terasology.math.geom.LineSegment;
import org.terasology.math.geom.Rect2f;
import org.terasology.math.geom.Vector2f;

/**
* The line segment connecting the two Sites is part of the Delaunay
* triangulation; the line segment connecting the two Vertices is part of the
Expand All @@ -49,7 +48,7 @@ public final class Edge {
* Once clipVertices() is called, this HashMap will hold two Points
* representing the clipped coordinates of the left and right ends...
*/
private final Map<LR, Vector2f> clippedVertices = new EnumMap<LR, Vector2f>(LR.class);
private final Map<LR, Vector2fc> clippedVertices = new EnumMap<LR, Vector2fc>(LR.class);

/**
* The two input Sites for which this Edge is a bisector:
Expand Down Expand Up @@ -107,17 +106,17 @@ public static Edge createBisectingEdge(Site site0, Site site1) {
return edge;
}

public LineSegment delaunayLine() {
public Line2f delaunayLine() {
// draw a line connecting the input Sites for which the edge is a bisector:
return new LineSegment(getLeftSite().getCoord(), getRightSite().getCoord());
return new Line2f(getLeftSite().getCoord(), getRightSite().getCoord());
}

public LineSegment voronoiEdge() {
public Line2f voronoiEdge() {
if (!isVisible()) {
return null;
}
return new LineSegment(clippedVertices.get(LR.LEFT),
clippedVertices.get(LR.RIGHT));
return new Line2f(clippedVertices.get(LR.LEFT),
clippedVertices.get(LR.RIGHT));
}

public Vertex getLeftVertex() {
Expand All @@ -141,7 +140,7 @@ public boolean isPartOfConvexHull() {
}

public float sitesDistance() {
return BaseVector2f.distance(getLeftSite().getCoord(), getRightSite().getCoord());
return getLeftSite().getCoord().distance(getRightSite().getCoord());
}

public static float compareSitesDistancesMax(Edge edge0, Edge edge1) {
Expand All @@ -160,7 +159,7 @@ public static float compareSitesDistances(Edge edge0, Edge edge1) {
return -compareSitesDistancesMax(edge0, edge1);
}

public Map<LR, Vector2f> getClippedEnds() {
public Map<LR, Vector2fc> getClippedEnds() {
return clippedVertices;
}

Expand Down Expand Up @@ -205,11 +204,11 @@ public String toString() {
* @param bounds
*
*/
public void clipVertices(Rect2f bounds) {
float xmin = bounds.minX();
float ymin = bounds.minY();
float xmax = bounds.maxX();
float ymax = bounds.maxY();
public void clipVertices(Rectanglef bounds) {
float xmin = bounds.minX;
float ymin = bounds.minY;
float xmax = bounds.maxX;
float ymax = bounds.maxY;

Vertex vertex0;
Vertex vertex1;
Expand All @@ -228,17 +227,17 @@ public void clipVertices(Rect2f bounds) {

if (getA() == 1.0) {
y0 = ymin;
if (vertex0 != null && vertex0.getY() > ymin) {
y0 = vertex0.getY();
if (vertex0 != null && vertex0.y() > ymin) {
y0 = vertex0.y();
}
if (y0 > ymax) {
return;
}
x0 = getC() - getB() * y0;

y1 = ymax;
if (vertex1 != null && vertex1.getY() < ymax) {
y1 = vertex1.getY();
if (vertex1 != null && vertex1.y() < ymax) {
y1 = vertex1.y();
}
if (y1 < ymin) {
return;
Expand Down Expand Up @@ -266,17 +265,17 @@ public void clipVertices(Rect2f bounds) {
}
} else {
x0 = xmin;
if (vertex0 != null && vertex0.getX() > xmin) {
x0 = vertex0.getX();
if (vertex0 != null && vertex0.x() > xmin) {
x0 = vertex0.x();
}
if (x0 > xmax) {
return;
}
y0 = getC() - getA() * x0;

x1 = xmax;
if (vertex1 != null && vertex1.getX() < xmax) {
x1 = vertex1.getX();
if (vertex1 != null && vertex1.x() < xmax) {
x1 = vertex1.x();
}
if (x1 < xmin) {
return;
Expand Down Expand Up @@ -316,11 +315,11 @@ public void clipVertices(Rect2f bounds) {
// overwrite previously computed coordinates with exact vertex locations
// where possible. This avoids rounding errors and ensures that equals() works properly.
// TODO: check before computing the clipped vertices
if (leftVertex != null && bounds.contains(leftVertex.getX(), leftVertex.getY())) {
clippedVertices.put(LR.LEFT, leftVertex.getCoord());
if (leftVertex != null && bounds.containsPoint(leftVertex.x(), leftVertex.y())) {
clippedVertices.put(LR.LEFT, new Vector2f(leftVertex.getCoord()));
}

if (rightVertex != null && bounds.contains(rightVertex.getX(), rightVertex.getY())) {
if (rightVertex != null && bounds.containsPoint(rightVertex.x(), rightVertex.y())) {
clippedVertices.put(LR.RIGHT, rightVertex.getCoord());
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/terasology/math/delaunay/EdgeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package org.terasology.math.delaunay;

import org.joml.Vector2fc;

import java.util.ArrayList;
import java.util.List;

import org.terasology.math.geom.Vector2f;

final class EdgeList {

private float deltax;
Expand Down Expand Up @@ -89,13 +89,13 @@ public void remove(Halfedge halfEdge) {
* @return
*
*/
public Halfedge edgeListLeftNeighbor(Vector2f p) {
public Halfedge edgeListLeftNeighbor(Vector2fc p) {
int i;
int bucket;
Halfedge halfEdge;

/* Use hash table to get close to desired halfedge */
bucket = (int) ((p.getX() - xmin) / deltax * hashsize);
bucket = (int) ((p.x() - xmin) / deltax * hashsize);
if (bucket < 0) {
bucket = 0;
}
Expand Down Expand Up @@ -134,8 +134,8 @@ public Halfedge edgeListLeftNeighbor(Vector2f p) {
return halfEdge;
}

/**
* Get entry from hash table, pruning any deleted nodes
/**
* Get entry from hash table, pruning any deleted nodes
*/
private Halfedge getHash(int b) {
Halfedge halfEdge;
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/terasology/math/delaunay/Halfedge.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.terasology.math.delaunay;

import org.terasology.math.geom.Vector2f;
import org.joml.Vector2fc;

final class Halfedge {

Expand All @@ -26,7 +26,7 @@ final class Halfedge {
public Edge edge;
public LR leftRight;
public Vertex vertex;

// the vertex's y-coordinate in the transformed Voronoi space V*
public float ystar;

Expand All @@ -44,7 +44,7 @@ public static Halfedge create(Edge edge, LR lr) {
public static Halfedge createDummy() {
return create(null, null);
}

@Override
public String toString() {
return "Halfedge (leftRight: " + leftRight + "; vertex: " + vertex + ")";
Expand Down Expand Up @@ -73,7 +73,7 @@ public void reallyDispose() {
vertex = null;
}

public boolean isLeftOf(Vector2f p) {
public boolean isLeftOf(Vector2fc p) {
Site topSite;
boolean rightOfSite;
boolean above;
Expand All @@ -87,7 +87,7 @@ public boolean isLeftOf(Vector2f p) {
float yl;

topSite = edge.getRightSite();
rightOfSite = p.getX() > topSite.getX();
rightOfSite = p.x() > topSite.getX();
if (rightOfSite && this.leftRight == LR.LEFT) {
return true;
}
Expand All @@ -96,14 +96,14 @@ public boolean isLeftOf(Vector2f p) {
}

if (edge.getA() == 1.0) {
dyp = p.getY() - topSite.getY();
dxp = p.getX() - topSite.getX();
dyp = p.y() - topSite.getY();
dxp = p.x() - topSite.getX();
fast = false;
if ((!rightOfSite && edge.getB() < 0.0) || (rightOfSite && edge.getB() >= 0.0)) {
above = dyp >= edge.getB() * dxp;
fast = above;
} else {
above = p.getX() + p.getY() * edge.getB() > edge.getC();
above = p.x() + p.y() * edge.getB() > edge.getC();
if (edge.getB() < 0.0) {
above = !above;
}
Expand All @@ -120,9 +120,9 @@ public boolean isLeftOf(Vector2f p) {
}
}
} else /* edge.b == 1.0 */ {
yl = edge.getC() - edge.getA() * p.getX();
t1 = p.getY() - yl;
t2 = p.getX() - topSite.getX();
yl = edge.getC() - edge.getA() * p.x();
t1 = p.y() - yl;
t2 = p.x() - topSite.getX();
t3 = yl - topSite.getY();
above = t1 * t1 > t2 * t2 + t3 * t3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package org.terasology.math.delaunay;

import org.joml.Vector2f;

import java.util.ArrayList;
import java.util.List;

import org.terasology.math.geom.Vector2f;

final class HalfedgePriorityQueue {
private List<Halfedge> hash;
private int count;
Expand All @@ -37,7 +37,7 @@ public HalfedgePriorityQueue(float ymin, float deltay, int sqrtNumSites) {
count = 0;
minBucket = 0;
hash = new ArrayList<Halfedge>(hashsize);

// dummy Halfedge at the top of each hash
for (int i = 0; i < hashsize; ++i) {
hash.add(Halfedge.createDummy());
Expand All @@ -64,7 +64,7 @@ public void insert(Halfedge halfEdge) {
}
previous = hash.get(insertionBucket);
next = previous.nextInPriorityQueue;
while (next != null && (halfEdge.ystar > next.ystar || (halfEdge.ystar == next.ystar && halfEdge.vertex.getX() > next.vertex.getX()))) {
while (next != null && (halfEdge.ystar > next.ystar || (halfEdge.ystar == next.ystar && halfEdge.vertex.x() > next.vertex.x()))) {
previous = next;
next = previous.nextInPriorityQueue;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public boolean empty() {
public Vector2f min() {
adjustMinBucket();
Halfedge answer = hash.get(minBucket).nextInPriorityQueue;
return new Vector2f(answer.vertex.getX(), answer.ystar);
return new Vector2f(answer.vertex.x(), answer.ystar);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/terasology/math/delaunay/ICoord.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package org.terasology.math.delaunay;

import org.terasology.math.geom.Vector2f;
import org.joml.Vector2fc;

public interface ICoord {

Vector2f getCoord();
Vector2fc getCoord();
}
Loading