diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/GridLocator.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/GridLocator.java deleted file mode 100644 index bc2985c..0000000 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/GridLocator.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (C) 2023 Hal Hildebrand. All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General - * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more - * details. - * - * You should have received a copy of the GNU Affero General Public License along with this program. If not, see - * . - */ -package com.hellblazer.luciferase.lucien.grid; - -import javax.vecmath.Tuple3d; -import java.util.Random; - -/** - * @author hal.hildebrand - */ -public class GridLocator { - private Tetrahedron last; - - public GridLocator(Tetrahedron initial) { - last = initial; - } - - /** - * Locate the tetrahedron which contains the query point via a stochastic walk through the delaunay triangulation. - * This location algorithm is a slight variation of the 3D jump and walk algorithm found in: "Fast randomized point - * location without preprocessing in two- and three-dimensional Delaunay triangulations", Computational Geometry 12 - * (1999) 63-83. z - * - * @param query - the query point - * @return the Tetrahedron containing the query - */ - public Tetrahedron locate(Tuple3d query, Random entropy) { - return last = last.locate(query, entropy); - } -} diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/MutableGrid.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/MutableGrid.java index 7bcec06..ff66f5c 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/MutableGrid.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/MutableGrid.java @@ -18,7 +18,6 @@ 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; @@ -30,7 +29,6 @@ * The dynamic, mutable version of the Grid * * @author Hal Hildebrand - * */ public class MutableGrid extends Grid { @@ -43,7 +41,6 @@ public MutableGrid() { /** * Construct a Sentinel using the supplied random number generator - * */ public MutableGrid(Vertex[] fourCorners) { super(fourCorners); @@ -68,8 +65,8 @@ public void rebuild(Random entropy) { } /** - * Track the point into the tetrahedralization. See "Computing the 3D Voronoi - * Diagram Robustly: An Easy Explanation", by Hugo Ledoux + * Track the point into the tetrahedralization. See "Computing the 3D Voronoi Diagram Robustly: An Easy + * Explanation", by Hugo Ledoux *

* * @param p - the point to be inserted @@ -78,13 +75,17 @@ public void rebuild(Random entropy) { public Vertex track(Point3d p, Random entropy) { assert p != null; final var v = new Vertex(p); - add(v, locate(p, last, entropy)); + add(v, locate(p, entropy)); return v; } + public Tetrahedron locate(Point3d p, Random entropy) { + return locate(p, last, entropy); + } + /** - * Track the point into the tetrahedralization. See "Computing the 3D Voronoi - * Diagram Robustly: An Easy Explanation", by Hugo Ledoux + * Track the point into the tetrahedralization. See "Computing the 3D Voronoi Diagram Robustly: An Easy + * Explanation", by Hugo Ledoux *

* * @param p - the point to be inserted @@ -109,7 +110,6 @@ public void untrack(Vertex v) { * Perform the 4->1 bistellar flip. This flip is the inverse of the 1->4 flip. * * @param n - the vertex who's star defines the 4 tetrahedron - * * @return the tetrahedron created from the flip */ protected Tetrahedron flip4to1(Vertex n) { diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/OrientedFace.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/OrientedFace.java index b137e67..05544b4 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/OrientedFace.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/OrientedFace.java @@ -34,12 +34,6 @@ public abstract class OrientedFace implements Iterable { - private volatile V adjacentVertexOrdinal; - - void clear() { - adjacentVertexOrdinal = null; - } - /** * Perform a flip for deletion of the vertex from the tetrahedralization. The incident and adjacent tetrahedra form * an ear of the star set of tetrahedra adjacent to v. @@ -119,7 +113,7 @@ public Tetrahedron flip(Vertex n, List ears) { Tetrahedron returned = null; if (reflexEdges == 0 && !isRegular()) { // Only one face of the opposing tetrahedron is visible - for (Tetrahedron t : flip2to3()) { + for (var t : flip2to3()) { var f = t.getFace(n); if (f.hasAdjacent()) { ears.add(f); @@ -132,7 +126,7 @@ public Tetrahedron flip(Vertex n, List ears) { var t1 = getIncident().getNeighbor(opposingVertex); var t2 = getAdjacent().getNeighbor(opposingVertex); if (t1 != null && t1 == t2) { - for (Tetrahedron t : flip3to2(reflexEdge)) { + for (var t : flip3to2(reflexEdge)) { OrientedFace f = t.getFace(n); if (f.hasAdjacent()) { ears.add(f); @@ -152,14 +146,18 @@ public Tetrahedron flip(Vertex n, List ears) { * @return the three created tetrahedron */ public Tetrahedron[] flip2to3() { - assert getAdjacentVertexOrdinal() != null; var incident = getIncident(); var opposingVertex = getAdjacentVertex(); var incidentVertex = getIncidentVertex(); - var t0 = new Tetrahedron(getVertex(0), incidentVertex, getVertex(1), opposingVertex); - var t1 = new Tetrahedron(getVertex(1), incidentVertex, getVertex(2), opposingVertex); - var t2 = new Tetrahedron(getVertex(0), getVertex(2), incidentVertex, opposingVertex); + + var vertex0 = getVertex(0); + var vertex1 = getVertex(1); + var vertex2 = getVertex(2); + + var t0 = new Tetrahedron(vertex0, incidentVertex, vertex1, opposingVertex); + var t1 = new Tetrahedron(vertex1, incidentVertex, vertex2, opposingVertex); + var t2 = new Tetrahedron(vertex0, vertex2, incidentVertex, opposingVertex); t0.setNeighborA(t1); t0.setNeighborC(t2); @@ -170,15 +168,15 @@ public Tetrahedron[] flip2to3() { t2.setNeighborA(t1); t2.setNeighborB(t0); - incident.patch(getVertex(2), t0, D); - incident.patch(getVertex(0), t1, D); - incident.patch(getVertex(1), t2, D); + incident.patch(vertex2, t0, D); + incident.patch(vertex0, t1, D); + incident.patch(vertex1, t2, D); var adjacent = getAdjacent(); - adjacent.patch(getVertex(0), t1, B); - adjacent.patch(getVertex(1), t2, C); - adjacent.patch(getVertex(2), t0, B); + adjacent.patch(vertex0, t1, B); + adjacent.patch(vertex1, t2, C); + adjacent.patch(vertex2, t0, B); incident.delete(); adjacent.delete(); @@ -221,7 +219,6 @@ public Tetrahedron[] flip2to3() { * @return the two created tetrahedron */ public Tetrahedron[] flip3to2(int reflexEdge) { - assert getAdjacentVertexOrdinal() != null; var incident = getIncident(); var o2 = getIncident().getNeighbor(getVertex(reflexEdge)); @@ -293,11 +290,12 @@ public Tetrahedron[] flip3to2(int reflexEdge) { * @return */ public Vertex getAdjacentVertex() { - var current = getAdjacentVertexOrdinal(); + Tetrahedron adjacent = getAdjacent(); + var current = adjacent == null ? null : adjacent.ordinalOf(getIncident()); if (current == null) { return null; } - return getAdjacent().getVertex(current); + return adjacent.getVertex(current); } /** @@ -306,12 +304,8 @@ public Vertex getAdjacentVertex() { * @return */ public V getAdjacentVertexOrdinal() { - var current = adjacentVertexOrdinal; - if (current == null) { - Tetrahedron adjacent = getAdjacent(); - current = adjacentVertexOrdinal = adjacent == null ? null : adjacent.ordinalOf(getIncident()); - } - return current; + Tetrahedron adjacent = getAdjacent(); + return adjacent == null ? null : adjacent.ordinalOf(getIncident()); } /** @@ -428,13 +422,13 @@ private boolean inSphere(Vertex query, Vertex b, Vertex c, Vertex d) { b = a; a = tmp; } - return query.inSphere(a, b, c, d) > 0; + return query.inSphere(a, b, c, d) > 0.0; } private boolean isFlippable3ear(Vertex n) { var opposingFace = getIncident().getFace(n); opposingFace.getAdjacent().getFace(opposingFace.getAdjacentVertex()); - return opposingFace.orientationOf(n) > 0; + return opposingFace.orientationOf(n) > 0.0; } diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Tetrahedron.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Tetrahedron.java index 1a269c6..80ed27c 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Tetrahedron.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Tetrahedron.java @@ -94,8 +94,6 @@ public class Tetrahedron implements Iterable { * @param w */ public Tetrahedron(Vertex x, Vertex y, Vertex z, Vertex w) { - assert x != null & y != null & z != null & w != null; - a = x; b = y; c = z; @@ -118,7 +116,6 @@ public Tetrahedron(Vertex x, Vertex y, Vertex z, Vertex w) { */ public Tetrahedron(Vertex[] vertices) { this(vertices[0], vertices[1], vertices[2], vertices[3]); - assert vertices.length == 4; } /** @@ -328,7 +325,7 @@ public boolean includes(Vertex query) { * @return */ public boolean inSphere(Vertex query) { - return query.inSphere(a, b, c, d) > 0; + return query.inSphere(a, b, c, d) > 0.0; } /** @@ -361,11 +358,11 @@ public void remove() { } public Tetrahedron locate(Tuple3d query, Random entropy) { - assert query != null; - + var order = Arrays.asList(Grid.VERTICES); V o = null; - for (V face : Grid.VERTICES) { - if (orientationWrt(face, query) < 0) { + Collections.shuffle(order); + for (V face : order) { + if (orientationWrt(face, query) < 0.0) { o = face; break; } @@ -383,7 +380,7 @@ public Tetrahedron locate(Tuple3d query, Random entropy) { for (V v : Grid.ORDER[tetrahedron.ordinalOf(current).ordinal()][entropy.nextInt(6)]) { o = v; current = tetrahedron; - if (tetrahedron.orientationWrt(v, query) < 0) { + if (tetrahedron.orientationWrt(v, query) < 0.0) { // we have found a face which the query point is on the other side break; } @@ -569,13 +566,6 @@ V ordinalOf(Tetrahedron neighbor) { throw new IllegalArgumentException("Not a neighbor: " + neighbor); } - private void clear() { - faceADB.clear(); - faceBCA.clear(); - faceCBD.clear(); - faceDAC.clear(); - } - /** * Patch the new tetrahedron created by a flip of the receiver by seting the neighbor to the value in the receiver *

@@ -640,7 +630,6 @@ void removeAnyDegenerateTetrahedronPair() { } void setNeighbor(V v, Tetrahedron n) { - clear(); if (v == A) { nA = n; return; @@ -657,22 +646,18 @@ void setNeighbor(V v, Tetrahedron n) { } void setNeighborA(Tetrahedron t) { - clear(); nA = t; } void setNeighborB(Tetrahedron t) { - clear(); nB = t; } void setNeighborC(Tetrahedron t) { - clear(); nC = t; } void setNeighborD(Tetrahedron t) { - clear(); nD = t; } @@ -906,13 +891,13 @@ public boolean isConvex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(c, d, b) < 0; + return adjacentVertex.orientation(c, d, b) < 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(a, c, b) < 0; + return adjacentVertex.orientation(a, c, b) < 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(a, d, c) < 0; + return adjacentVertex.orientation(a, d, c) < 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } @@ -924,13 +909,13 @@ public boolean isReflex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(c, d, b) > 0; + return adjacentVertex.orientation(c, d, b) > 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(a, c, b) > 0; + return adjacentVertex.orientation(a, c, b) > 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(a, d, c) > 0; + return adjacentVertex.orientation(a, d, c) > 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } @@ -1027,13 +1012,13 @@ public boolean isConvex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(d, c, a) < 0; + return adjacentVertex.orientation(d, c, a) < 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(b, d, a) < 0; + return adjacentVertex.orientation(b, d, a) < 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(b, c, d) < 0; + return adjacentVertex.orientation(b, c, d) < 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } @@ -1045,13 +1030,13 @@ public boolean isReflex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(d, c, a) > 0; + return adjacentVertex.orientation(d, c, a) > 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(b, d, a) > 0; + return adjacentVertex.orientation(b, d, a) > 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(b, c, d) > 0; + return adjacentVertex.orientation(b, c, d) > 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } @@ -1148,13 +1133,13 @@ public boolean isConvex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(a, b, d) < 0; + return adjacentVertex.orientation(a, b, d) < 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(c, a, d) < 0; + return adjacentVertex.orientation(c, a, d) < 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(c, b, a) < 0; + return adjacentVertex.orientation(c, b, a) < 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } @@ -1166,13 +1151,13 @@ public boolean isReflex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(a, b, d) > 0; + return adjacentVertex.orientation(a, b, d) > 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(c, a, d) > 0; + return adjacentVertex.orientation(c, a, d) > 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(c, b, a) > 0; + return adjacentVertex.orientation(c, b, a) > 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } @@ -1269,13 +1254,13 @@ public boolean isConvex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(b, a, c) < 0; + return adjacentVertex.orientation(b, a, c) < 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(d, b, c) < 0; + return adjacentVertex.orientation(d, b, c) < 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(d, a, b) < 0; + return adjacentVertex.orientation(d, a, b) < 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } @@ -1287,13 +1272,13 @@ public boolean isReflex(int vertex) { return false; } if (vertex == 0) { - return adjacentVertex.orientation(b, a, c) > 0; + return adjacentVertex.orientation(b, a, c) > 0.0; } if (vertex == 1) { - return adjacentVertex.orientation(d, b, c) > 0; + return adjacentVertex.orientation(d, b, c) > 0.0; } if (vertex == 2) { - return adjacentVertex.orientation(d, a, b) > 0; + return adjacentVertex.orientation(d, a, b) > 0.0; } throw new IllegalArgumentException("Invalid vertex index: " + vertex); } diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Vertex.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Vertex.java index 52f3881..8b51643 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Vertex.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Vertex.java @@ -129,7 +129,7 @@ final void setAdjacent(Tetrahedron tetrahedron) { * * @return the collection of neighboring vertices */ - public final Collection getNeighbors() { + public Collection getNeighbors() { assert adjacent != null; final var neighbors = new IdentitySet(); diff --git a/lucien/src/test/java/com/hellblazer/luciferase/lucien/grid/MutableGridTest.java b/lucien/src/test/java/com/hellblazer/luciferase/lucien/grid/MutableGridTest.java index d74f528..86ae309 100644 --- a/lucien/src/test/java/com/hellblazer/luciferase/lucien/grid/MutableGridTest.java +++ b/lucien/src/test/java/com/hellblazer/luciferase/lucien/grid/MutableGridTest.java @@ -63,10 +63,10 @@ public void smokin() throws Exception { var sentinel = new MutableGrid(); var sites = new ArrayList(); var entropy = new Random(0x666); - for (var p : getRandomPoints(entropy, 256, 10, true)) { + for (var p : getRandomPoints(entropy, 1024, 10, true)) { sites.add(sentinel.track(p, entropy)); } - int iterations = 10_000; + int iterations = 1_000; long now = System.nanoTime(); for (int i = 0; i < iterations; i++) { for (var site : sites) { diff --git a/von/src/main/java/com/hellblazer/luciferase/lucien/von/SphereOfInteraction.java b/von/src/main/java/com/hellblazer/luciferase/lucien/von/SphereOfInteraction.java index 8f4d314..ef3c24e 100644 --- a/von/src/main/java/com/hellblazer/luciferase/lucien/von/SphereOfInteraction.java +++ b/von/src/main/java/com/hellblazer/luciferase/lucien/von/SphereOfInteraction.java @@ -17,6 +17,8 @@ package com.hellblazer.luciferase.lucien.von; +import com.hellblazer.luciferase.lucien.grid.Vertex; + import javax.vecmath.Point3d; import javax.vecmath.Tuple3d; import java.util.Collection; @@ -36,21 +38,13 @@ public interface SphereOfInteraction { */ Node closestTo(Point3d coord); - /** - * Answer the Node aliased to the Node - * - * @param peer - * @return - */ - Node getAliased(Node peer); - /** * get a list of enclosing neighbors * * @param id * @return */ - Collection getEnclosingNeighbors(Node id); + List getEnclosingNeighbors(Node id); Iterable getPeers(); @@ -76,7 +70,7 @@ public interface SphereOfInteraction { * @param radiusSquared * @return */ - boolean isBoundary(Node peer, Tuple3d center, float radiusSquared); + boolean isBoundary(Node peer, Vertex center, float radiusSquared); /** * check if the node 'id' is an enclosing neighbor of 'center_node_id' diff --git a/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/AbstractCursor.java b/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/AbstractCursor.java deleted file mode 100644 index 31b533a..0000000 --- a/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/AbstractCursor.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.hellblazer.luciferase.lucien.von.impl; - -import com.hellblazer.luciferase.lucien.von.Cursor; -import com.hellblazer.luciferase.lucien.von.Perceiving; -import com.hellblazer.luciferase.lucien.grid.Vertex; - -import javax.vecmath.Point3d; -import javax.vecmath.Tuple3d; - -/** - * @author hal.hildebrand - **/ -public class AbstractCursor implements Cursor, Cloneable { - protected Vertex location; - - public AbstractCursor(Vertex location) { - this.location = location; - } - - @Override - public Point3d getLocation() { - return new Point3d(location); - } - - @Override - public void moveBy(Tuple3d velocity) { - location.moveBy(velocity); - } -} diff --git a/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/AbstractNode.java b/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/AbstractNode.java index 9a70069..b8d60e3 100644 --- a/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/AbstractNode.java +++ b/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/AbstractNode.java @@ -17,16 +17,18 @@ package com.hellblazer.luciferase.lucien.von.impl; +import com.hellblazer.luciferase.lucien.grid.Vertex; +import com.hellblazer.luciferase.lucien.von.Cursor; import com.hellblazer.luciferase.lucien.von.Node; import com.hellblazer.luciferase.lucien.von.Perceiving; -import com.hellblazer.luciferase.lucien.grid.Vertex; + +import javax.vecmath.Point3d; /** * @author Hal Hildebrand */ -abstract public class AbstractNode extends AbstractCursor implements Node { - +abstract public class AbstractNode extends Vertex implements Node, Cursor { protected float aoiRadius; protected float maximumVelocity; protected float maxRadiusSquared; @@ -41,6 +43,11 @@ public AbstractNode(E entity, Vertex location, float aoiRadius, float maximumVel this.maxRadiusSquared = maxExtent * maxExtent; } + @Override + public Point3d getLocation() { + return new Point3d(x, y, z); + } + @Override public float getAoiRadius() { return aoiRadius; @@ -65,6 +72,6 @@ public E getSim() { public String toString() { String className = getClass().getCanonicalName(); int index = className.lastIndexOf('.'); - return className.substring(index + 1) + " (" + location.x + ", " + location.y + ") aoi: " + getAoiRadius(); + return className.substring(index + 1) + " (" + x + ", " + y + ", " + z + ") aoi: " + getAoiRadius(); } } diff --git a/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/GridSoI.java b/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/GridSoI.java new file mode 100644 index 0000000..2d172dd --- /dev/null +++ b/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/GridSoI.java @@ -0,0 +1,92 @@ +package com.hellblazer.luciferase.lucien.von.impl; + +import com.hellblazer.luciferase.lucien.grid.V; +import com.hellblazer.luciferase.lucien.grid.Vertex; +import com.hellblazer.luciferase.lucien.von.Node; +import com.hellblazer.luciferase.lucien.von.SphereOfInteraction; + +import javax.vecmath.Point3d; +import java.util.List; +import java.util.Random; + +/** + * @author hal.hildebrand + **/ +public class GridSoI implements SphereOfInteraction { + private final Random entropy; + private final Perceptron foci; + + public GridSoI(Random entropy, Perceptron foci) { + this.entropy = entropy; + this.foci = foci; + } + + @Override + public Node closestTo(Point3d coord) { + record dist(Vertex v, double distSquared) { + } + var tet = foci.locate(coord, entropy); + var min = new dist(tet.getVertex(V.A), Double.MAX_VALUE); + var vertex = tet.getVertex(V.B); + var distanceSquared = vertex.distanceSquared(coord); + if (distanceSquared < min.distSquared) { + min = new dist(vertex, distanceSquared); + } + vertex = tet.getVertex(V.C); + distanceSquared = vertex.distanceSquared(coord); + if (distanceSquared < min.distSquared) { + min = new dist(vertex, distanceSquared); + } + vertex = tet.getVertex(V.D); + distanceSquared = vertex.distanceSquared(coord); + if (distanceSquared < min.distSquared) { + min = new dist(vertex, distanceSquared); + } + return (Node) vertex; + } + + @Override + public List getEnclosingNeighbors(Node id) { + return foci.getNeighbors().stream().map(v -> (Node) v).toList(); + } + + @Override + public Iterable getPeers() { + return null; + } + + @Override + public boolean includes(Node peer) { + return false; + } + + @Override + public void insert(Node id, Point3d coord) { + + } + + @Override + public boolean isBoundary(Node peer, Vertex center, float radiusSquared) { + return false; + } + + @Override + public boolean isEnclosing(Node peer, Node center_node_id) { + return false; + } + + @Override + public boolean overlaps(Node peer, Point3d center, float radiusSquared) { + return false; + } + + @Override + public boolean remove(Node peer) { + return false; + } + + @Override + public void update(Node peer, Point3d coord) { + + } +} diff --git a/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/Perceptron.java b/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/Perceptron.java index 2191673..05d966f 100644 --- a/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/Perceptron.java +++ b/von/src/main/java/com/hellblazer/luciferase/lucien/von/impl/Perceptron.java @@ -27,6 +27,7 @@ import javax.vecmath.Vector3d; import java.util.ArrayList; import java.util.Collection; +import java.util.List; /** * @author Hal Hildebrand @@ -48,16 +49,6 @@ public void fadeFrom(Node neighbor) { remove(neighbor); } - public Collection getNeighbors() { - final var neighbors = new ArrayList(); - for (var peer : soi.getPeers()) { - if (!peer.equals(this)) { - neighbors.add(peer); - } - } - return neighbors; - } - public void join(Node gateway) { if (!gateway.equals(this)) { gateway.query(this, this); @@ -116,7 +107,7 @@ public void moveBy(Tuple3d velocity) { removeNonOverlapped(); for (var peer : soi.getPeers()) { if (!peer.equals(this)) { - if (soi.isBoundary(peer, location, maxRadiusSquared)) { + if (soi.isBoundary(peer, this, maxRadiusSquared)) { peer.moveBoundary(this); } else { peer.move(this); @@ -190,7 +181,7 @@ protected void notifySimMove(Node neighbor, Point3d oldLocation) { notifySimNotice(neighbor); return; } - var distance = new Vector3d(location); + var distance = new Vector3d(x, y, z); distance.sub(neighbor.getLocation()); if (distance.lengthSquared() <= maxRadiusSquared) { var velocity = new Vector3d(); @@ -203,7 +194,7 @@ protected void notifySimMove(Node neighbor, Point3d oldLocation) { } protected void notifySimNotice(Node neighbor) { - var distance = new Vector3d(location); + var distance = new Vector3d(x, y, z); distance.sub(neighbor.getLocation()); if (distance.lengthSquared() <= maxRadiusSquared) { sim.notice(neighbor.getSim(), neighbor.getLocation()); @@ -238,13 +229,12 @@ protected void removeNonOverlapped() { } protected Point3d update(Node node) { - var neighbor = soi.getAliased(node); - if (neighbor == null) { + if (!soi.includes(node)) { soi.insert(node, node.getLocation()); return null; } - var oldLocation = new Point3d(neighbor.getLocation()); - soi.update(neighbor, node.getLocation()); + var oldLocation = new Point3d(node.getLocation()); + soi.update(node, node.getLocation()); return oldLocation; } }