Skip to content

Commit

Permalink
revert back to Float instead of Double. Forgot how fast that was/is ;…
Browse files Browse the repository at this point in the history
…) some clean up on VON
  • Loading branch information
Hellblazer committed Jan 5, 2025
1 parent 3ea733d commit 4fdbf28
Show file tree
Hide file tree
Showing 23 changed files with 349 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import com.hellblazer.luciferase.common.IdentitySet;

import javax.vecmath.Tuple3d;
import javax.vecmath.Tuple3f;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -141,7 +141,7 @@ public Vertex next() {
* @param random - the source of entropy for the randomized algo
* @return the Tetrahedron containing the query
*/
public Tetrahedron locate(Tuple3d query, Tetrahedron start, Random random) {
public Tetrahedron locate(Tuple3f query, Tetrahedron start, Random random) {
assert query != null;
return start.locate(query, random);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.hellblazer.luciferase.lucien.grid;

import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
Expand Down Expand Up @@ -72,14 +72,14 @@ public void rebuild(Random entropy) {
* @param p - the point to be inserted
* @return the Vertex in the tetrahedralization
*/
public Vertex track(Point3d p, Random entropy) {
public Vertex track(Point3f p, Random entropy) {
assert p != null;
final var v = new Vertex(p);
add(v, locate(p, entropy));
return v;
}

public Tetrahedron locate(Point3d p, Random entropy) {
public Tetrahedron locate(Point3f p, Random entropy) {
return locate(p, last, entropy);
}

Expand All @@ -92,7 +92,7 @@ public Tetrahedron locate(Point3d p, Random entropy) {
* @param near - the nearby vertex
* @return the new Vertex in the tetrahedralization
*/
public Vertex track(Point3d p, Vertex near, Random entropy) {
public Vertex track(Point3f p, Vertex near, Random entropy) {
assert p != null;
final var v = new Vertex(p);
add(v, near.locate(p, entropy));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.hellblazer.luciferase.common.IdentitySet;
import com.hellblazer.luciferase.geometry.Geometry;

import javax.vecmath.Point3d;
import javax.vecmath.Tuple3d;
import javax.vecmath.Point3f;
import javax.vecmath.Tuple3f;
import java.util.*;

import static com.hellblazer.luciferase.geometry.Geometry.centerSphere;
Expand Down Expand Up @@ -128,8 +128,8 @@ public Tetrahedron(Vertex[] vertices) {
* @return +1 if the orientation of the query point is positive with respect to the plane, -1 if negative and 0 if
* the test point is coplanar
*/
public static double orientation(Tuple3d query, Tuple3d a, Tuple3d b, Tuple3d c) {
double result = Geometry.leftOfPlaneFast(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, query.x, query.y,
public static double orientation(Tuple3f query, Tuple3f a, Tuple3f b, Tuple3f c) {
var result = Geometry.leftOfPlaneFast(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, query.x, query.y,
query.z);
return Math.signum(result);
}
Expand All @@ -146,10 +146,10 @@ public void addFaces(List<Vertex[]> faces) {
faces.add(new Vertex[] { d, a, c });
}

public Point3d center() {
double[] center = new double[3];
public Point3f center() {
float[] center = new float[3];
centerSphere(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, center);
return new Point3d(center[0], center[1], center[2]);
return new Point3f(center[0], center[1], center[2]);
}

/**
Expand Down Expand Up @@ -357,12 +357,12 @@ public void remove() {
};
}

public Tetrahedron locate(Tuple3d query, Random entropy) {
public Tetrahedron locate(Tuple3f query, Random entropy) {
var order = Arrays.asList(Grid.VERTICES);
V o = null;
Collections.shuffle(order);
Collections.shuffle(order, entropy);
for (V face : order) {
if (orientationWrt(face, query) < 0.0) {
if (orientationWrt(face, query) < 0.0d) {
o = face;
break;
}
Expand Down Expand Up @@ -422,7 +422,7 @@ public V ordinalOf(Vertex v) {
* @param query
* @return
*/
public double orientationWrt(V face, Tuple3d query) {
public double orientationWrt(V face, Tuple3f query) {
if (face == A) {
return orientationWrtCBD(query);
}
Expand All @@ -445,7 +445,7 @@ public double orientationWrt(V face, Tuple3d query) {
* @param query
* @return
*/
public double orientationWrtADB(Tuple3d query) {
public double orientationWrtADB(Tuple3f query) {
return orientation(query, a, d, b);
}

Expand All @@ -456,7 +456,7 @@ public double orientationWrtADB(Tuple3d query) {
* @param query
* @return
*/
public double orientationWrtBCA(Tuple3d query) {
public double orientationWrtBCA(Tuple3f query) {
return orientation(query, b, c, a);
}

Expand All @@ -467,7 +467,7 @@ public double orientationWrtBCA(Tuple3d query) {
* @param query
* @return
*/
public double orientationWrtCBD(Tuple3d query) {
public double orientationWrtCBD(Tuple3f query) {
return orientation(query, c, b, d);
}

Expand All @@ -478,7 +478,7 @@ public double orientationWrtCBD(Tuple3d query) {
* @param query
* @return
*/
public double orientationWrtDAC(Tuple3d query) {
public double orientationWrtDAC(Tuple3f query) {
return orientation(query, d, a, c);
}

Expand Down Expand Up @@ -672,13 +672,13 @@ void setNeighborD(Tetrahedron t) {
* @param axis
* @param face
*/
void traverseVoronoiFace(Tetrahedron origin, Tetrahedron from, Vertex vC, Vertex axis, List<Point3d> face) {
void traverseVoronoiFace(Tetrahedron origin, Tetrahedron from, Vertex vC, Vertex axis, List<Point3f> face) {
if (origin == this) {
return;
}
var center = new double[3];
var center = new float[3];
centerSphere(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, center);
face.add(new Point3d(center[0], center[1], center[2]));
face.add(new Point3f(center[0], center[1], center[2]));
V next = VORONOI_FACE_NEXT[ordinalOf(from).ordinal()][ordinalOf(vC).ordinal()][ordinalOf(axis).ordinal()];
var t = getNeighbor(next);
if (t != null) {
Expand All @@ -696,17 +696,17 @@ void traverseVoronoiFace(Tetrahedron origin, Tetrahedron from, Vertex vC, Vertex
* @param axis
* @param faces
*/
void traverseVoronoiFace(Vertex vC, Vertex axis, List<Tuple3d[]> faces) {
var face = new ArrayList<Point3d>();
var center = new double[3];
void traverseVoronoiFace(Vertex vC, Vertex axis, List<Tuple3f[]> faces) {
var face = new ArrayList<Point3f>();
var center = new float[3];
centerSphere(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, center);
face.add(new Point3d(center[0], center[1], center[2]));
face.add(new Point3f(center[0], center[1], center[2]));
V v = VORONOI_FACE_ORIGIN[ordinalOf(vC).ordinal()][ordinalOf(axis).ordinal()];
var next = getNeighbor(v);
if (next != null) {
next.traverseVoronoiFace(this, this, vC, axis, face);
}
faces.add(face.toArray(new Point3d[face.size()]));
faces.add(face.toArray(new Point3f[face.size()]));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
import com.hellblazer.luciferase.common.IdentitySet;
import com.hellblazer.luciferase.geometry.Geometry;

import javax.vecmath.Point3d;
import javax.vecmath.Tuple3d;
import javax.vecmath.Vector3d;
import javax.vecmath.Point3f;
import javax.vecmath.Tuple3f;
import javax.vecmath.Vector3f;
import java.io.Serial;
import java.util.*;

/**
* @author <a href="mailto:[email protected]">Hal Hildebrand</a>
*/
public class Vertex extends Vector3d implements Iterable<Vertex> {
static final Point3d ORIGIN = new Point3d(0, 0, 0);
public class Vertex extends Vector3f implements Iterable<Vertex> {
static final Point3f ORIGIN = new Point3f(0, 0, 0);
@Serial
private static final long serialVersionUID = 1L;
/**
Expand All @@ -39,30 +39,30 @@ public class Vertex extends Vector3d implements Iterable<Vertex> {
private Tetrahedron adjacent;
private Vertex next; // linked list o' vertices

public Vertex(double i, double j, double k) {
public Vertex(float i, float j, float k) {
x = i;
y = j;
z = k;
}

public Vertex(double i, double j, double k, double scale) {
public Vertex(float i, float j, float k, float scale) {
this(i * scale, j * scale, k * scale);
}

public Vertex(Tuple3d p) {
public Vertex(Tuple3f p) {
this(p.x, p.y, p.z);
}

/**
* Generate a bounded random double
* Generate a bounded random float
*
* @param random
* @param min
* @param max
* @return
*/
public static double random(Random random, double min, double max) {
var result = random.nextDouble();
public static float random(Random random, float min, float max) {
var result = random.nextFloat();
if (min > max) {
result *= min - max;
result += max;
Expand All @@ -81,8 +81,8 @@ public static double random(Random random, double min, double max) {
* @param max
* @return
*/
public static Point3d randomPoint(Random random, double min, double max) {
return new Point3d(random(random, min, max), random(random, min, max), random(random, min, max));
public static Point3f randomPoint(Random random, float min, float max) {
return new Point3f(random(random, min, max), random(random, min, max), random(random, min, max));
}

/**
Expand All @@ -96,8 +96,8 @@ public <T> T as(Class<T> model) {
return null;
}

public final double distanceSquared(Tuple3d p1) {
double dx, dy, dz;
public final float distanceSquared(Tuple3f p1) {
float dx, dy, dz;

dx = x - p1.x;
dy = y - p1.y;
Expand Down Expand Up @@ -156,11 +156,11 @@ public final Deque<OrientedFace> getStar() {
*
* @return the list of faces defining the voronoi region defined by the receiver
*/
public final List<Tuple3d[]> getVoronoiRegion() {
public final List<Tuple3f[]> getVoronoiRegion() {
assert adjacent != null;

final var faces = new ArrayList<Tuple3d[]>();
var neighbors = new IdentitySet<Tuple3d>(10);
final var faces = new ArrayList<Tuple3f[]>();
var neighbors = new IdentitySet<Tuple3f>(10);
adjacent.visitStar(this, (vertex, t, x, y, z) -> {
if (neighbors.add(x)) {
t.traverseVoronoiFace(this, x, faces);
Expand All @@ -178,16 +178,16 @@ public final List<Tuple3d[]> getVoronoiRegion() {
/**
* Return +1 if the receiver lies inside the sphere passing through a, b, c, and d; -1 if it lies outside; and 0 if
* the five points are cospherical. The vertices a, b, c, and d must be ordered so that they have a positive
* orientation (as defined by {@link #orientation(Tuple3d, Tuple3d, Tuple3d)}), or the sign of the result will be
* orientation (as defined by {@link #orientation(Tuple3f, Tuple3f, Tuple3f)}), or the sign of the result will be
* reversed.
* <p>
*
* @param a , b, c, d - the points defining the sphere, in oriented order
* @return +1 if the receiver lies inside the sphere passing through a, b, c, and d; -1 if it lies outside; and 0 if
* the five points are cospherical
*/
public final double inSphere(Tuple3d a, Tuple3d b, Tuple3d c, Tuple3d d) {
var result = Geometry.inSphere(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, x, y, z);
public final double inSphere(Tuple3f a, Tuple3f b, Tuple3f c, Tuple3f d) {
var result = Geometry.inSphereFast(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, x, y, z);
return Math.signum(result);
}

Expand Down Expand Up @@ -220,12 +220,12 @@ public Vertex next() {
* @param entropy - entropy used for randomization of search
* @return the Tetrahedron that encompasses the query point
*/
public final Tetrahedron locate(Tuple3d query, Random entropy) {
public final Tetrahedron locate(Tuple3f query, Random entropy) {
assert adjacent != null;
return adjacent.locate(query, entropy);
}

public void moveBy(Tuple3d delta) {
public void moveBy(Tuple3f delta) {
x = x + delta.x;
y = y + delta.y;
z = z + delta.z;
Expand All @@ -240,7 +240,7 @@ public void moveBy(Tuple3d delta) {
* @return +1 if the orientation of the query point is positive with respect to the plane, -1 if negative and 0 if
* the test point is coplanar
*/
public final double orientation(Tuple3d a, Tuple3d b, Tuple3d c) {
public final double orientation(Tuple3f a, Tuple3f b, Tuple3f c) {
var result = Geometry.leftOfPlaneFast(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, x, y, z);
return Math.signum(result);
}
Expand Down
Loading

0 comments on commit 4fdbf28

Please sign in to comment.