From c3ef8e1c4b7210e55356ea717bfc73551a7c62b3 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Sun, 21 Jul 2024 10:08:35 -0700 Subject: [PATCH] heavy refactor. update to java 22, use mvnw --- .github/workflows/maven.yml | 14 +- .mvn/wrapper/maven-wrapper.properties | 19 + .../luciferase/lucien/grid/EarSet.java | 72 +- .../luciferase/lucien/grid/Grid.java | 105 +- .../luciferase/lucien/grid/GridLocator.java | 38 +- .../luciferase/lucien/grid/MutableGrid.java | 30 +- .../luciferase/lucien/grid/OrientedFace.java | 28 +- .../luciferase/lucien/grid/StarVisitor.java | 28 +- .../luciferase/lucien/grid/Tetrahedron.java | 2119 ++++++++--------- .../hellblazer/luciferase/lucien/grid/V.java | 18 +- .../luciferase/lucien/grid/Vertex.java | 101 +- mvnw | 259 ++ mvnw.cmd | 149 ++ pom.xml | 2 +- .../archimedes/RhombicDodecahedron.java | 2 +- 15 files changed, 1667 insertions(+), 1317 deletions(-) create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100755 mvnw create mode 100644 mvnw.cmd diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2c2c31d..0e258f0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -8,16 +8,12 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Maven - uses: stCarolas/setup-maven@v4.5 - with: - maven-version: 3.9.4 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 - with: - java-version: '21' - distribution: graalvm + with: + java-version: '22' + distribution: 'graalvm' cache: 'maven' github-token: ${{ secrets.GITHUB_TOKEN }} - name: Build with Maven - run: mvn -batch-mode --update-snapshots clean install --file pom.xml \ No newline at end of file + run: ./mvnw -batch-mode --update-snapshots clean install --file pom.xml diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..93a0d79 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/EarSet.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/EarSet.java index 7ccb2d0..e2349e5 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/EarSet.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/EarSet.java @@ -1,33 +1,54 @@ /** * Copyright (C) 2010 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 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. + * 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 . + * 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 com.hellblazer.luciferase.common.OaHashSet; + import java.util.LinkedList; import java.util.List; import java.util.Set; -import com.hellblazer.luciferase.common.OaHashSet; - /** * @author Hal Hildebrand * */ public class EarSet implements StarVisitor { + private List ears = new LinkedList<>(); + private Set visited = new OaHashSet<>(); + + public List getEars() { + return ears; + } + + @Override + public void visit(V vertex, Tetrahedron t, Vertex x, Vertex y, Vertex z) { + OrientedFace face = t.getFace(z); + if (visited.add(new Ear(face))) { + ears.add(face); + } + face = t.getFace(x); + if (visited.add(new Ear(face))) { + ears.add(face); + } + face = t.getFace(y); + if (visited.add(new Ear(face))) { + ears.add(face); + } + } + private static class Ear { final OrientedFace face; final int hashcode; @@ -45,8 +66,8 @@ private static class Ear { public boolean equals(Object obj) { if (obj instanceof Ear) { Ear ear = (Ear) obj; - if ((face.getIncident() == ear.face.getIncident() && face.getAdjacent() == ear.face.getAdjacent()) || - (face.getAdjacent() == ear.face.getIncident() && face.getIncident() == ear.face.getAdjacent())) { + if ((face.getIncident() == ear.face.getIncident() && face.getAdjacent() == ear.face.getAdjacent()) || ( + face.getAdjacent() == ear.face.getIncident() && face.getIncident() == ear.face.getAdjacent())) { return true; } } @@ -58,27 +79,4 @@ public int hashCode() { return hashcode; } } - - private List ears = new LinkedList<>(); - private Set visited = new OaHashSet<>(); - - public List getEars() { - return ears; - } - - @Override - public void visit(V vertex, Tetrahedron t, Vertex x, Vertex y, Vertex z) { - OrientedFace face = t.getFace(z); - if (visited.add(new Ear(face))) { - ears.add(face); - } - face = t.getFace(x); - if (visited.add(new Ear(face))) { - ears.add(face); - } - face = t.getFace(y); - if (visited.add(new Ear(face))) { - ears.add(face); - } - } } diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Grid.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Grid.java index c88d64a..ceafd81 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Grid.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/Grid.java @@ -1,38 +1,27 @@ /** * Copyright (C) 2009-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 + * + * 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 + * + * 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 . + * + * 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 static com.hellblazer.luciferase.lucien.grid.V.A; -import static com.hellblazer.luciferase.lucien.grid.V.B; -import static com.hellblazer.luciferase.lucien.grid.V.C; -import static com.hellblazer.luciferase.lucien.grid.V.D; - -import java.util.Collections; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.Random; -import java.util.Set; -import java.util.Stack; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; +import com.hellblazer.luciferase.common.IdentitySet; import javax.vecmath.Tuple3f; +import java.util.*; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; -import com.hellblazer.luciferase.common.IdentitySet; +import static com.hellblazer.luciferase.lucien.grid.V.*; /** * A Delaunay tetrahedralization. This implementation is optimized for @@ -51,10 +40,10 @@ * topology. Because we throw the tetrahedra away on every rebuild, there's * really little need for an index and so random walk is used. It is assumed * that the vast majority, if not damn near entirety of operations concerning - * the Sentinel and its tracked components and topology will be operating with a - * vertex after the tetrahedralization has occurred. Consequently operations on - * Vertex and Tetrahedron are the defacto operation origination rather at the - * Sentinel level. + * the Grid and its tracked components and topology will be operating with a + * vertex after the tetrahedralization has occurred. Consequently, operations on + * Vertex and Tetrahedron are the de facto operation origination rather at the + * Grid level. * * @author Hal Hildebrand */ @@ -63,26 +52,42 @@ public class Grid implements Iterable { /** * Cannonical enumeration of the vertex ordinals */ - public static final V[] VERTICES = { A, B, C, D }; + public static final V[] VERTICES = { A, B, C, D }; /** * A pre-built table of all the permutations of remaining faces to check in * location. */ - protected static final V[][][] ORDER = new V[][][] { { { B, C, D }, { C, B, D }, { C, D, B }, { B, D, C }, - { D, B, C }, { D, C, B } }, + protected static final V[][][] ORDER = new V[][][] { + { { B, C, D }, { C, B, D }, { C, D, B }, { B, D, C }, { D, B, C }, { D, C, B } }, - { { A, C, D }, { C, A, D }, { C, D, A }, { A, D, C }, - { D, A, C }, { D, C, A } }, + { { A, C, D }, { C, A, D }, { C, D, A }, { A, D, C }, { D, A, C }, { D, C, A } }, - { { B, A, D }, { A, B, D }, { A, D, B }, { B, D, A }, - { D, B, A }, { D, A, B } }, + { { B, A, D }, { A, B, D }, { A, D, B }, { B, D, A }, { D, B, A }, { D, A, B } }, - { { B, C, A }, { C, B, A }, { C, A, B }, { B, A, C }, - { A, B, C }, { A, C, B } } }; + { { B, C, A }, { C, B, A }, { C, A, B }, { B, A, C }, { A, B, C }, { A, C, B } } }; /** * Scale of the universe */ - private static float SCALE = (float) Math.pow(2, 16); + private static float SCALE = (float) Math.pow(2, 16); + /** + * The four corners of the maximally bounding tetrahedron + */ + protected final Vertex[] fourCorners; + /** + * the Head of the vertices list + */ + protected Vertex head; + /** + * The number of points in this Grid + */ + protected int size = 0; + Grid(Vertex[] fourCorners) { + this.fourCorners = fourCorners; + } + Grid(Vertex[] fourCorners, Vertex head) { + this(fourCorners); + this.head = head; + } public static Vertex[] getFourCorners() { Vertex[] fourCorners = new Vertex[4]; @@ -107,28 +112,6 @@ public static Tetrahedron myOwnPrivateIdaho(Grid s) { return new Tetrahedron(U); } - /** - * The four corners of the maximally bounding tetrahedron - */ - protected final Vertex[] fourCorners; - /** - * the Head of the vertices list - */ - protected Vertex head; - /** - * The number of points in this Grid - */ - protected int size = 0; - - Grid(Vertex[] fourCorners) { - this.fourCorners = fourCorners; - } - - Grid(Vertex[] fourCorners, Vertex head) { - this(fourCorners); - this.head = head; - } - /** * Answer the four corners of the universe * 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 index 9bcdf61..3d4ef5a 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/GridLocator.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/GridLocator.java @@ -1,24 +1,21 @@ /** * 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 + * + * 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 + * + * 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 . + * + * 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 java.util.Random; - import javax.vecmath.Tuple3f; +import java.util.Random; /** * @author hal.hildebrand @@ -26,17 +23,20 @@ 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. + * 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(Tuple3f query, Random entropy) { - return last.locate(query, 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 76d674d..7536eb0 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 @@ -3,33 +3,27 @@ * * This file is part of the 3D Incremental Voronoi system * - * 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 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. + * 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 . + * 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 static com.hellblazer.luciferase.lucien.grid.V.A; -import static com.hellblazer.luciferase.lucien.grid.V.B; -import static com.hellblazer.luciferase.lucien.grid.V.C; -import static com.hellblazer.luciferase.lucien.grid.V.D; - +import javax.vecmath.Point3f; import java.util.ArrayList; import java.util.Deque; import java.util.List; import java.util.Random; -import javax.vecmath.Point3f; +import static com.hellblazer.luciferase.lucien.grid.V.*; /** * The dynamic, mutable version of the Grid @@ -39,8 +33,8 @@ */ public class MutableGrid extends Grid { - protected Vertex tail; - private Tetrahedron last; + protected Vertex tail; + private Tetrahedron last; public MutableGrid() { this(getFourCorners()); 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 7cc9a0e..b916493 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 @@ -3,32 +3,28 @@ * * This file is part of the 3D Incremental Voronoi system * - * 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 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. + * 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 . + * 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 static com.hellblazer.luciferase.lucien.grid.V.B; -import static com.hellblazer.luciferase.lucien.grid.V.C; -import static com.hellblazer.luciferase.lucien.grid.V.D; - import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; import java.util.function.Function; +import static com.hellblazer.luciferase.lucien.grid.V.*; + /** * An oriented face of a tetrahedron. *

@@ -157,7 +153,7 @@ public Tetrahedron flip(Vertex n, List ears) { /** * Perform the bistellar flip 2 -> 3. This produces three new tetrahedra from - * the receiver and tetrahdron that shares the receiver face + * the receiver and a tetrahdron that shares the receiver face * * @return the three created tetrahedron */ @@ -224,7 +220,7 @@ else if (t2.isDeleted()) * face, along with the tetrahedron on the reflexive edge of the face. *

* - * @param reflexiveEdge - the vertex opposite the reflexive edge of the face + * @param reflexEdge - the vertex opposite the reflex edge of the face * @return the two created tetrahedron */ public Tetrahedron[] flip3to2(int reflexEdge) { diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/StarVisitor.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/StarVisitor.java index f97b08f..535985f 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/StarVisitor.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/StarVisitor.java @@ -1,18 +1,16 @@ /** * Copyright (C) 2010 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 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. + * 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 . + * 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; @@ -27,16 +25,16 @@ public interface StarVisitor { /** * Visit the tetrahedron t in the start set. The central vertex of the star set * is vertex v in tetrahedron t. The other 3 vertices in tetrahedron t are given - * by {a, b, c} and are in counter clockwise order, where the central vertex of + * by {a, b, c} and are in counterclockwise order, where the central vertex of * the star is V ordinal D in t, following the right hand rule. - * + * * @param v - the V Ordinal of the central vertex Vc of the star in tetrahedron * t * @param t - a tetrahedron in the star set, where the central vertex of the * start is the vertex ordinal in t - * @param a - vertext A relative to Vc - * @param b - vertext B relative to Vc - * @param c - vertext C relative to Vc + * @param a - vertex A relative to Vc + * @param b - vertex B relative to Vc + * @param c - vertex C relative to Vc */ void visit(V v, Tetrahedron t, Vertex a, Vertex b, Vertex c); } 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 9544ae9..af39a80 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 @@ -3,40 +3,29 @@ * * This file is part of the 3D Incremental Voronoi system * - * 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 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. + * 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 . + * 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 static com.hellblazer.luciferase.geometry.Geometry.centerSphereFast; -import static com.hellblazer.luciferase.lucien.grid.V.A; -import static com.hellblazer.luciferase.lucien.grid.V.B; -import static com.hellblazer.luciferase.lucien.grid.V.C; -import static com.hellblazer.luciferase.lucien.grid.V.D; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.Stack; +import com.hellblazer.luciferase.common.IdentitySet; +import com.hellblazer.luciferase.geometry.Geometry; import javax.vecmath.Point3f; import javax.vecmath.Tuple3f; +import java.util.*; -import com.hellblazer.luciferase.common.IdentitySet; -import com.hellblazer.luciferase.geometry.Geometry; +import static com.hellblazer.luciferase.geometry.Geometry.centerSphereFast; +import static com.hellblazer.luciferase.lucien.grid.V.*; /** * An oriented, delaunay tetrahedral cell. The vertices of the tetrahedron are @@ -49,1304 +38,1292 @@ */ public class Tetrahedron implements Iterable { /** - * Represents the oriented face opposite vertex C - * - * @author hhildebrand - * + * Matrix used to determine the next neighbor in a voronoi face traversal */ - private class FaceADB extends OrientedFace { - - @Override - public Tetrahedron getAdjacent() { - return nC; - } - - @Override - public Vertex[] getEdge(Vertex v) { - switch (ordinalOf(v)) { - case A: { - return new Vertex[] { d, b }; - } - case D: { - return new Vertex[] { b, a }; - } - case B: { - return new Vertex[] { a, d }; - } - default: - throw new IllegalArgumentException("Invalid vertex ordinal"); - } - } - - @Override - public Tetrahedron getIncident() { - return Tetrahedron.this; - } - - @Override - public Vertex getIncidentVertex() { - return c; - } - - @Override - public Vertex getVertex(int v) { - switch (v) { - case 0: - return a; - case 1: - return d; - case 2: - return b; - default: - throw new IllegalArgumentException("Invalid vertex index: " + v); - } - } + private static final V[][][] VORONOI_FACE_NEXT = { + { null, { null, null, D, C }, { null, D, null, B }, { null, C, B, null } }, + { { null, null, D, C }, null, { D, null, null, A }, { C, null, A, null } }, + { { null, D, null, B }, { D, null, null, A }, null, { B, A, null, null } }, + { { null, C, B, null }, { C, null, A, null }, { B, A, null, null }, null } }; + /** + * Matrix used to determine the origin neighbor in a vororoni face traversal + */ + private static final V[][] VORONOI_FACE_ORIGIN = { { null, C, D, B }, { C, null, D, A }, { D, A, null, B }, + { B, C, A, null } }; + /** + * Vertex A + */ + private Vertex a; + /** + * Vertx B + */ + private Vertex b; + /** + * Vertex C + */ + private Vertex c; + /** + * Vertex D + */ + private Vertex d; + /** + * The neighboring tetrahedron opposite of vertex A + */ + private Tetrahedron nA; + /** + * The neighboring tetrahedron opposite of vertex B + */ + private Tetrahedron nB; + /** + * The neighboring tetrahedron opposite of vertex C + */ + private Tetrahedron nC; + /** + * The neighboring tetrahedron opposite of vertex D + */ + private Tetrahedron nD; - @Override - public boolean includes(Vertex v) { - if ((a == v) || (d == v) || (b == v)) { - return true; - } - return false; - } + /** + * Construct a tetrahedron from the four vertices + * + * @param x + * @param y + * @param z + * @param w + */ + public Tetrahedron(Vertex x, Vertex y, Vertex z, Vertex w) { + assert x != null & y != null & z != null & w != null; - @Override - public int indexOf(Vertex v) { - if (v == a) { - return 0; - } - if (v == d) { - return 1; - } - if (v == b) { - return 2; - } - throw new IllegalArgumentException("Vertex is not on face: " + v); - } + a = x; + b = y; + c = z; + d = w; - @Override - public boolean isConvex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } - switch (vertex) { - case 0: - return adjacentVertex.orientation(c, d, b) == -1; - case 1: - return adjacentVertex.orientation(a, c, b) == -1; - case 2: - return adjacentVertex.orientation(a, d, c) == -1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); - } - } + a.setAdjacent(this); + b.setAdjacent(this); + c.setAdjacent(this); + d.setAdjacent(this); + } - @Override - public boolean isReflex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } - switch (vertex) { - case 0: - return adjacentVertex.orientation(c, d, b) == 1; - case 1: - return adjacentVertex.orientation(a, c, b) == 1; - case 2: - return adjacentVertex.orientation(a, d, c) == 1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); - } - } + /** + * Construct a tetrahedron from the array of four vertices + * + * @param vertices + */ + public Tetrahedron(Vertex[] vertices) { + this(vertices[0], vertices[1], vertices[2], vertices[3]); + assert vertices.length == 4; + } - @Override - public int orientationOf(Vertex query) { - return orientationWrtADB(query); + /** + * Answer +1 if the orientation of the query is positive with respect to the + * plane defined by {a, b, c}, -1 if negative, or 0 if the test point is + * coplanar + *

+ * + * @param query - the point to query + * @param a , b, c - the points defining the plane + * @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 int orientation(Tuple3f query, Tuple3f a, Tuple3f b, Tuple3f 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, + query.z); + if (result > 0.0) { + return 1; + } else if (result < 0.0) { + return -1; } + return 0; + } - @Override - public String toString() { - return "Face ADB"; - } + /** + * Add the four faces defined by the tetrahedron to the list of faces + * + * @param faces + */ + public void addFaces(List faces) { + faces.add(new Vertex[] { a, d, b }); + faces.add(new Vertex[] { b, c, a }); + faces.add(new Vertex[] { c, b, d }); + faces.add(new Vertex[] { d, a, c }); + } + public Point3f center() { + float[] center = new float[3]; + centerSphereFast(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 Point3f(center[0], center[1], center[2]); } /** - * Represents the oriented face opposite of vertex D * - * @author hhildebrand + * Perform the 1 -> 4 bistellar flip. This produces 4 new tetrahedron from the + * original tetrahdron, by inserting the new point in the interior of the + * receiver tetrahedron. The star set of the newly inserted point is pushed onto + * the supplied stack. + *

* + * @param n - the inserted point + * @param ears - the stack of oriented faces that make up the ears of the + * inserted point + * @return one of the four new tetrahedra */ - private class FaceBCA extends OrientedFace { + public Tetrahedron flip1to4(Vertex n, List ears) { + Tetrahedron t0 = new Tetrahedron(a, b, c, n); + Tetrahedron t1 = new Tetrahedron(a, d, b, n); + Tetrahedron t2 = new Tetrahedron(a, c, d, n); + Tetrahedron t3 = new Tetrahedron(b, d, c, n); - @Override - public Tetrahedron getAdjacent() { - return nD; - } + t0.setNeighborA(t3); + t0.setNeighborB(t2); + t0.setNeighborC(t1); - @Override - public Vertex[] getEdge(Vertex v) { - switch (ordinalOf(v)) { - case B: { - return new Vertex[] { c, a }; - } - case C: { - return new Vertex[] { a, b }; - } - case A: { - return new Vertex[] { b, c }; - } - default: - throw new IllegalArgumentException("Invalid vertex ordinal"); - } - } - - @Override - public Tetrahedron getIncident() { - return Tetrahedron.this; - } - - @Override - public Vertex getIncidentVertex() { - return d; - } + t1.setNeighborA(t3); + t1.setNeighborB(t0); + t1.setNeighborC(t2); - @Override - public Vertex getVertex(int v) { - switch (v) { - case 0: - return b; - case 1: - return c; - case 2: - return a; - default: - throw new IllegalArgumentException("Invalid vertex index: " + v); - } - } + t2.setNeighborA(t3); + t2.setNeighborB(t1); + t2.setNeighborC(t0); - @Override - public boolean includes(Vertex v) { - if ((b == v) || (c == v) || (a == v)) { - return true; - } - return false; - } + t3.setNeighborA(t2); + t3.setNeighborB(t0); + t3.setNeighborC(t1); - @Override - public int indexOf(Vertex v) { - if (v == b) { - return 0; - } - if (v == c) { - return 1; - } - if (v == a) { - return 2; - } - throw new IllegalArgumentException("Vertex is not on face: " + v); - } + patch(D, t0, D); + patch(C, t1, D); + patch(B, t2, D); + patch(A, t3, D); - @Override - public boolean isConvex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } + delete(); - switch (vertex) { - case 0: - return adjacentVertex.orientation(d, c, a) == -1; - case 1: - return adjacentVertex.orientation(b, d, a) == -1; - case 2: - return adjacentVertex.orientation(b, c, d) == -1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); - } + OrientedFace newFace = t0.getFace(D); + if (newFace.hasAdjacent()) { + ears.add(newFace); } - - @Override - public boolean isReflex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } - - switch (vertex) { - case 0: - return adjacentVertex.orientation(d, c, a) == 1; - case 1: - return adjacentVertex.orientation(b, d, a) == 1; - case 2: - return adjacentVertex.orientation(b, c, d) == 1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); - } + newFace = t1.getFace(D); + if (newFace.hasAdjacent()) { + ears.add(newFace); } - - @Override - public int orientationOf(Vertex query) { - return orientationWrtBCA(query); + newFace = t2.getFace(D); + if (newFace.hasAdjacent()) { + ears.add(newFace); } - - @Override - public String toString() { - return "Face BCA"; + newFace = t3.getFace(D); + if (newFace.hasAdjacent()) { + ears.add(newFace); } - + return t1; } /** - * Represents the oriented face opposite of vertex A - * - * @author hhildebrand + * Answer the oriented face of the tetrahedron + *

* + * @param v - the vertex opposite the face + * @return the OrientedFace */ - private class FaceCBD extends OrientedFace { - - @Override - public Tetrahedron getAdjacent() { - return nA; - } - - @Override - public Vertex[] getEdge(Vertex v) { - switch (ordinalOf(v)) { - case C: { - return new Vertex[] { b, d }; - } - case B: { - return new Vertex[] { d, c }; - } - case D: { - return new Vertex[] { c, b }; - } - default: - throw new IllegalArgumentException("Invalid vertex ordinal"); - } - } - - @Override - public Tetrahedron getIncident() { - return Tetrahedron.this; - } - - @Override - public Vertex getIncidentVertex() { - return a; - } - - @Override - public Vertex getVertex(int v) { - switch (v) { - case 0: - return c; - case 1: - return b; - case 2: - return d; - default: - throw new IllegalArgumentException("Invalid vertex index: " + v); - } - } - - @Override - public boolean includes(Vertex v) { - if ((c == v) || (b == v) || (d == v)) { - return true; - } - return false; - } - - @Override - public int indexOf(Vertex v) { - if (v == c) { - return 0; - } - if (v == b) { - return 1; - } - if (v == d) { - return 2; - } - throw new IllegalArgumentException("Vertex is not on face: " + v); - } - - @Override - public boolean isConvex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } - switch (vertex) { - case 0: - return adjacentVertex.orientation(a, b, d) == -1; - case 1: - return adjacentVertex.orientation(c, a, d) == -1; - case 2: - return adjacentVertex.orientation(c, b, a) == -1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); - } + public OrientedFace getFace(V v) { + // return new OrientedFace(this, v); + switch (v) { + case A: + return new FaceCBD(); + case B: + return new FaceDAC(); + case C: + return new FaceADB(); + case D: + return new FaceBCA(); + default: + throw new IllegalArgumentException("Invalid vertex: " + v); } + } - @Override - public boolean isReflex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } - switch (vertex) { - case 0: - return adjacentVertex.orientation(a, b, d) == 1; - case 1: - return adjacentVertex.orientation(c, a, d) == 1; - case 2: - return adjacentVertex.orientation(c, b, a) == 1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); - } - } + /** + * Answer the oriented face opposite the vertex + * + * @param v + * @return + */ + public OrientedFace getFace(Vertex v) { + return getFace(ordinalOf(v)); + } - @Override - public int orientationOf(Vertex query) { - return orientationWrtCBD(query); - } + public List getFaces() { + List faces = new ArrayList<>(); + faces.add(new Vertex[] { a, d, b }); + faces.add(new Vertex[] { b, c, a }); + faces.add(new Vertex[] { c, b, d }); + faces.add(new Vertex[] { d, a, c }); + return faces; + } - @Override - public String toString() { - return "Face CBD"; + /** + * Answer the neighbor that is adjacent to the face opposite of the vertex + *

+ * + * @param v - the opposing vertex defining the face + * @return the neighboring tetrahedron, or null if none. + */ + public Tetrahedron getNeighbor(V v) { + switch (v) { + case A: + return nA; + case B: + return nB; + case C: + return nC; + case D: + return nD; + default: + throw new IllegalArgumentException("Invalid opposing vertex: " + v); } - } /** - * Represents the oriented face opposite of vertex B - * - * @author hhildebrand + * Answer the neighbor that is adjacent to the face opposite of the vertex + *

* + * @param vertex + * @return */ - private class FaceDAC extends OrientedFace { + public Tetrahedron getNeighbor(Vertex vertex) { + return getNeighbor(ordinalOf(vertex)); + } - @Override - public Tetrahedron getAdjacent() { - return nB; + /** + * Answer the vertex of the tetrahedron + * + * @param v the vertex + * @return the vertex + */ + public Vertex getVertex(V v) { + switch (v) { + case A: + return a; + case B: + return b; + case C: + return c; + case D: + return d; + default: + throw new IllegalStateException("No such point"); } + } - @Override - public Vertex[] getEdge(Vertex v) { - switch (ordinalOf(v)) { - case D: { - return new Vertex[] { a, c }; - } - case A: { - return new Vertex[] { c, d }; - } - case C: { - return new Vertex[] { d, a }; - } - default: - throw new IllegalArgumentException("Invalid vertex ordinal"); - } - } + /** + * Answer the four vertices that define the tetrahedron + * + * @return + */ + public Vertex[] getVertices() { + return new Vertex[] { a, b, c, d }; + } - @Override - public Tetrahedron getIncident() { - return Tetrahedron.this; - } + public boolean includes(Vertex query) { + return a == query || b == query || c == query || d == query; + } - @Override - public Vertex getIncidentVertex() { - return b; - } + /** + * Answer true if the query point is contained in the circumsphere of the + * tetrahedron + * + * @param query + * @return + */ + public boolean inSphere(Vertex query) { + return query.inSphere(a, b, c, d) > 0; + } - @Override - public Vertex getVertex(int v) { - switch (v) { - case 0: - return d; - case 1: - return a; - case 2: - return c; - default: - throw new IllegalArgumentException("Invalid vertex index: " + v); - } - } + /** + * Answer the iterator over the faces of the tetrahedron + *

+ * + * @return the iterator of the faces, in the order of the index their opposite + * vertex + */ + @Override + public Iterator iterator() { + return new Iterator<>() { + OrientedFace[] faces = { getFace(A), getFace(B), getFace(C), getFace(D) }; + int i = 0; - @Override - public boolean includes(Vertex v) { - if ((d == v) || (a == v) || (c == v)) { - return true; + @Override + public boolean hasNext() { + return i < 4; } - return false; - } - @Override - public int indexOf(Vertex v) { - if (v == d) { - return 0; - } - if (v == a) { - return 1; - } - if (v == c) { - return 2; + @Override + public OrientedFace next() { + return faces[i++]; } - throw new IllegalArgumentException("Vertex is not on face: " + v); - } - @Override - public boolean isConvex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } - switch (vertex) { - case 0: - return adjacentVertex.orientation(b, a, c) == -1; - case 1: - return adjacentVertex.orientation(d, b, c) == -1; - case 2: - return adjacentVertex.orientation(d, a, b) == -1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); + @Override + public void remove() { + throw new UnsupportedOperationException(); } - } + }; + } - @Override - public boolean isReflex(int vertex) { - Vertex adjacentVertex = getAdjacentVertex(); - if (adjacentVertex == null) { - return false; - } - switch (vertex) { - case 0: - return adjacentVertex.orientation(b, a, c) == 1; - case 1: - return adjacentVertex.orientation(d, b, c) == 1; - case 2: - return adjacentVertex.orientation(d, a, b) == 1; - default: - throw new IllegalArgumentException("Invalid vertex index: " + vertex); + public Tetrahedron locate(Tuple3f query, Random entropy) { + assert query != null; + + V o = null; + for (V face : Grid.VERTICES) { + if (orientationWrt(face, query) < 0) { + o = face; + break; } } - - @Override - public int orientationOf(Vertex query) { - return orientationWrtDAC(query); + if (o == null) { + // The query point is contained in the receiver + return this; } - @Override - public String toString() { - return "Face DAC"; + Tetrahedron current = this; + while (true) { + // get the tetrahedron on the other side of the face + Tetrahedron tetrahedron = current.getNeighbor(o); + int i = 0; + for (V v : Grid.ORDER[tetrahedron.ordinalOf(current).ordinal()][entropy.nextInt(6)]) { + o = v; + current = tetrahedron; + if (tetrahedron.orientationWrt(v, query) < 0) { + // we have found a face which the query point is on the other side + break; + } + if (i++ == 2) { + return tetrahedron; + } + } } } /** - * Matrix used to determine the next neighbor in a voronoi face traversal - */ - private static final V[][][] VORONOI_FACE_NEXT = { { null, { null, null, D, C }, { null, D, null, B }, - { null, C, B, null } }, - { { null, null, D, C }, null, { D, null, null, A }, - { C, null, A, null } }, - { { null, D, null, B }, { D, null, null, A }, null, - { B, A, null, null } }, - { { null, C, B, null }, { C, null, A, null }, - { B, A, null, null }, null } }; - - /** - * Matrix used to determine the origin neighbor in a vororoni face traversal + * Answer the vertex indicator of the the point + * + * @param v - the vertex + * @return the indicator of this vertex or null if not a vertex of this + * tetrahedron or the supplied vertex is null */ - private static final V[][] VORONOI_FACE_ORIGIN = { { null, C, D, B }, { C, null, D, A }, { D, A, null, B }, - { B, C, A, null } }; + public V ordinalOf(Vertex v) { + if (v == null) { + return null; + } + if (v == a) { + return A; + } else if (v == b) { + return B; + } else if (v == c) { + return C; + } else if (v == d) { + return D; + } else { + return null; + } + } /** - * Answer +1 if the orientation of the query is positive with respect to the - * plane defined by {a, b, c}, -1 if negative, or 0 if the test point is - * coplanar - *

+ * Answer > 0 if the query point is positively oriented with respect to the face + * opposite the vertex, < 0 if negatively oriented, 0 if the query point is + * coplanar to the face * - * @param query - the point to query - * @param a , b, c - the points defining the plane - * @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 + * @param face + * @param query + * @return */ - public static int orientation(Tuple3f query, Tuple3f a, Tuple3f b, Tuple3f 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, - query.z); - if (result > 0.0) { - return 1; - } else if (result < 0.0) { - return -1; + public int orientationWrt(V face, Tuple3f query) { + switch (face) { + case A: + return orientationWrtCBD(query); + case B: + return orientationWrtDAC(query); + case C: + return orientationWrtADB(query); + case D: + return orientationWrtBCA(query); + default: + throw new IllegalArgumentException("Invalid face: " + face); } - return 0; } /** - * Vertex A + * Answer > 0 if the query point is positively oriented with respect to the face + * ADB, < 0 if negatively oriented, 0 if the query point is coplanar to the face + * + * @param query + * @return */ - private Vertex a; + public int orientationWrtADB(Tuple3f query) { + return orientation(query, a, d, b); + } /** - * Vertx B + * Answer 1 if the query point is positively oriented with respect to the face + * BCA, -1 if negatively oriented, 0 if the query point is coplanar to the face + * + * @param query + * @return */ - private Vertex b; + public int orientationWrtBCA(Tuple3f query) { + return orientation(query, b, c, a); + } /** - * Vertex C + * Answer 1 if the query point is positively oriented with respect to the face + * CBD, -1 if negatively oriented, 0 if the query point is coplanar to the face + * + * @param query + * @return */ - private Vertex c; + public int orientationWrtCBD(Tuple3f query) { + return orientation(query, c, b, d); + } /** - * Vertex D + * Answer 1 if the query point is positively oriented with respect to the face + * DAC, -1 if negatively oriented, 0 if the query point is coplanar to the face + * + * @param query + * @return */ - private Vertex d; + public int orientationWrtDAC(Tuple3f query) { + return orientation(query, d, a, c); + } - /** - * The neighboring tetrahedron opposite of vertex A - */ - private Tetrahedron nA; + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("Tetrahedron ["); + if (isDeleted()) { + buf.append("DELETED]"); + return buf.toString(); + } + for (Vertex v : getVertices()) { + buf.append(v); + buf.append(", "); + } + buf.append(']'); + return buf.toString(); + } - /** - * The neighboring tetrahedron opposite of vertex B - */ - private Tetrahedron nB; + void children(Stack stack, Set processed) { + if (nA != null && !processed.contains(nA)) { + stack.push(nA); + } + if (nB != null && !processed.contains(nB)) { + stack.push(nB); + } + if (nC != null && !processed.contains(nC)) { + stack.push(nC); + } + if (nD != null && !processed.contains(nD)) { + stack.push(nD); + } + } /** - * The neighboring tetrahedron opposite of vertex C + * Clean up the pointers */ - private Tetrahedron nC; + void delete() { + nA = nB = nC = nD = null; + a = b = c = d = null; + } - /** - * The neighboring tetrahedron opposite of vertex D - */ - private Tetrahedron nD; + Vertex getA() { + return a; + } - /** - * Construct a tetrahedron from the four vertices - * - * @param x - * @param y - * @param z - * @param w - */ - public Tetrahedron(Vertex x, Vertex y, Vertex z, Vertex w) { - assert x != null & y != null & z != null & w != null; + Vertex getB() { + return b; + } - a = x; - b = y; - c = z; - d = w; + Vertex getC() { + return c; + } - a.setAdjacent(this); - b.setAdjacent(this); - c.setAdjacent(this); - d.setAdjacent(this); + Vertex getD() { + return d; + } + + boolean isDeleted() { + return a == null; } /** - * Construct a tetrahedron from the array of four vertices + * Answer the canonical ordinal of the opposite vertex of the neighboring + * tetrahedron * - * @param vertices + * @param neighbor + * @return */ - public Tetrahedron(Vertex[] vertices) { - this(vertices[0], vertices[1], vertices[2], vertices[3]); - assert vertices.length == 4; + V ordinalOf(Tetrahedron neighbor) { + if (neighbor == null) { + return null; + } + if (nA == neighbor) { + return A; + } + if (nB == neighbor) { + return B; + } + if (nC == neighbor) { + return C; + } + if (nD == neighbor) { + return D; + } + throw new IllegalArgumentException("Not a neighbor: " + neighbor); } /** - * Add the four faces defined by the tetrahedron to the list of faces + * Patch the new tetrahedron created by a flip of the receiver by seting the + * neighbor to the value in the receiver + *

* - * @param faces + * @param vOld - the opposing vertex the neighboring tetrahedron in the receiver + * @param n - the new tetrahedron to patch + * @param vNew - the opposing vertex of the neighbor to assign in the new + * tetrahedron */ - public void addFaces(List faces) { - faces.add(new Vertex[] { a, d, b }); - faces.add(new Vertex[] { b, c, a }); - faces.add(new Vertex[] { c, b, d }); - faces.add(new Vertex[] { d, a, c }); - } - - public Point3f center() { - float[] center = new float[3]; - centerSphereFast(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 Point3f(center[0], center[1], center[2]); + void patch(V vOld, Tetrahedron n, V vNew) { + Tetrahedron neighbor = getNeighbor(vOld); + if (neighbor != null) { + neighbor.setNeighbor(neighbor.ordinalOf(this), n); + n.setNeighbor(vNew, neighbor); + } } /** - * - * Perform the 1 -> 4 bistellar flip. This produces 4 new tetrahedron from the - * original tetrahdron, by inserting the new point in the interior of the - * receiver tetrahedron. The star set of the newly inserted point is pushed onto - * the supplied stack. + * Patch the new tetrahedron created by a flip of the receiver by seting the + * neighbor to the value in the receiver *

* - * @param n - the inserted point - * @param ears - the stack of oriented faces that make up the ears of the - * inserted point - * @return one of the four new tetrahedra + * @param old + * @param n + * @param vNew */ - public Tetrahedron flip1to4(Vertex n, List ears) { - Tetrahedron t0 = new Tetrahedron(a, b, c, n); - Tetrahedron t1 = new Tetrahedron(a, d, b, n); - Tetrahedron t2 = new Tetrahedron(a, c, d, n); - Tetrahedron t3 = new Tetrahedron(b, d, c, n); - - t0.setNeighborA(t3); - t0.setNeighborB(t2); - t0.setNeighborC(t1); - - t1.setNeighborA(t3); - t1.setNeighborB(t0); - t1.setNeighborC(t2); - - t2.setNeighborA(t3); - t2.setNeighborB(t1); - t2.setNeighborC(t0); - - t3.setNeighborA(t2); - t3.setNeighborB(t0); - t3.setNeighborC(t1); - - patch(D, t0, D); - patch(C, t1, D); - patch(B, t2, D); - patch(A, t3, D); - - delete(); + void patch(Vertex old, Tetrahedron n, V vNew) { + patch(ordinalOf(old), n, vNew); + } - OrientedFace newFace = t0.getFace(D); - if (newFace.hasAdjacent()) { - ears.add(newFace); - } - newFace = t1.getFace(D); - if (newFace.hasAdjacent()) { - ears.add(newFace); - } - newFace = t2.getFace(D); - if (newFace.hasAdjacent()) { - ears.add(newFace); + void removeAnyDegenerateTetrahedronPair() { + if (nA != null) { + if (nA == nB) { + removeDegenerateTetrahedronPair(V.A, V.B, V.C, V.D); + return; + } + if (nA == nC) { + removeDegenerateTetrahedronPair(V.A, V.C, V.B, V.D); + return; + } + if (nA == nD) { + removeDegenerateTetrahedronPair(V.A, V.D, V.B, V.C); + return; + } } - newFace = t3.getFace(D); - if (newFace.hasAdjacent()) { - ears.add(newFace); + + if (nB != null) { + if (nB == nC) { + removeDegenerateTetrahedronPair(V.B, V.C, V.A, V.D); + return; + } + if (nB == nD) { + removeDegenerateTetrahedronPair(V.B, V.D, V.A, V.C); + return; + } } - return t1; + + if (nC != null) + if (nC == nD) { + removeDegenerateTetrahedronPair(V.C, V.D, V.A, V.B); + return; + } } - /** - * Answer the oriented face of the tetrahedron - *

- * - * @param v - the vertex opposite the face - * @return the OrientedFace - */ - public OrientedFace getFace(V v) { - // return new OrientedFace(this, v); + void setNeighbor(V v, Tetrahedron n) { switch (v) { case A: - return new FaceCBD(); + nA = n; + break; case B: - return new FaceDAC(); + nB = n; + break; case C: - return new FaceADB(); + nC = n; + break; case D: - return new FaceBCA(); + nD = n; + break; default: throw new IllegalArgumentException("Invalid vertex: " + v); } } - /** - * Answer the oriented face opposite the vertex - * - * @param v - * @return - */ - public OrientedFace getFace(Vertex v) { - return getFace(ordinalOf(v)); + void setNeighborA(Tetrahedron t) { + nA = t; } - public List getFaces() { - List faces = new ArrayList<>(); - faces.add(new Vertex[] { a, d, b }); - faces.add(new Vertex[] { b, c, a }); - faces.add(new Vertex[] { c, b, d }); - faces.add(new Vertex[] { d, a, c }); - return faces; + void setNeighborB(Tetrahedron t) { + nB = t; + } + + void setNeighborC(Tetrahedron t) { + nC = t; + } + + void setNeighborD(Tetrahedron t) { + nD = t; } /** - * Answer the neighbor that is adjacent to the face opposite of the vertex + * Traverse the points which define the voronoi face defined by the dual of the + * line segement defined by the center point and the axis. Terminate the + * traversal if we have returned to the originating tetrahedron. *

* - * @param v - the opposing vertex defining the face - * @return the neighboring tetrahedron, or null if none. + * @param origin + * @param from + * @param vC + * @param axis + * @param face */ - public Tetrahedron getNeighbor(V v) { - switch (v) { - case A: - return nA; - case B: - return nB; - case C: - return nC; - case D: - return nD; - default: - throw new IllegalArgumentException("Invalid opposing vertex: " + v); + void traverseVoronoiFace(Tetrahedron origin, Tetrahedron from, Vertex vC, Vertex axis, List face) { + if (origin == this) { + return; + } + float[] center = new float[3]; + centerSphereFast(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 Point3f(center[0], center[1], center[2])); + V next = VORONOI_FACE_NEXT[ordinalOf(from).ordinal()][ordinalOf(vC).ordinal()][ordinalOf(axis).ordinal()]; + Tetrahedron t = getNeighbor(next); + if (t != null) { + t.traverseVoronoiFace(origin, this, vC, axis, face); } + } /** - * Answer the neighbor that is adjacent to the face opposite of the vertex + * Traverse the points which define the voronoi face defined by the dual of the + * line segement defined by the center point and the axis. *

* - * @param vertex - * @return + * @param vC + * @param axis + * @param face */ - public Tetrahedron getNeighbor(Vertex vertex) { - return getNeighbor(ordinalOf(vertex)); + void traverseVoronoiFace(Vertex vC, Vertex axis, List faces) { + ArrayList face = new ArrayList<>(); + float[] center = new float[3]; + centerSphereFast(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 Point3f(center[0], center[1], center[2])); + V v = VORONOI_FACE_ORIGIN[ordinalOf(vC).ordinal()][ordinalOf(axis).ordinal()]; + Tetrahedron next = getNeighbor(v); + if (next != null) { + next.traverseVoronoiFace(this, this, vC, axis, face); + } + faces.add(face.toArray(new Point3f[face.size()])); } /** - * Answer the vertex of the tetrahedron + * visit the receiver and push unvisited tetrahedrons around the supplied vertex * - * @param v the vertex - * @return the vertex + * @param vC - the center vertex + * @param visitor - the star visitor + * @param stack - the stack of visitations */ - public Vertex getVertex(V v) { - switch (v) { + void visit(Vertex vC, StarVisitor visitor, Stack stack, Set visited) { + switch (ordinalOf(vC)) { case A: - return a; + visitor.visit(A, this, c, b, d); + if (nC != null) { + stack.push(nC); + } + if (nB != null) { + stack.push(nC); + } + if (nD != null) { + stack.push(nD); + } + break; case B: - return b; + visitor.visit(B, this, d, a, c); + if (nD != null) { + stack.push(nD); + } + if (nA != null) { + stack.push(nA); + } + if (nC != null) { + stack.push(nC); + } + break; case C: - return c; + visitor.visit(C, this, a, d, b); + if (nA != null) { + stack.push(nA); + } + if (nD != null) { + stack.push(nD); + } + if (nB != null) { + stack.push(nB); + } + break; case D: - return d; + visitor.visit(D, this, b, c, a); + if (nB != null) { + stack.push(nB); + } + if (nA != null) { + stack.push(nB); + } + if (nC != null) { + stack.push(nC); + } + break; default: - throw new IllegalStateException("No such point"); + throw new IllegalArgumentException("Invalid center vertex: " + vC); } } /** - * Answer the four vertices that define the tetrahedron + * Visit the star tetrahedra set of the of the center vertex * - * @return + * @param vC - the center vertex + * @param visitor - the visitor to invoke for each tetrahedron in the star */ - public Vertex[] getVertices() { - return new Vertex[] { a, b, c, d }; + void visitStar(Vertex vC, StarVisitor visitor) { + Set tetrahedrons = new IdentitySet<>(10); + var stack = new Stack(); + stack.push(this); + while (!stack.isEmpty()) { + var t = stack.pop(); + if (tetrahedrons.add(t)) { + t.visit(vC, visitor, stack, tetrahedrons); + } + } } - public boolean includes(Vertex query) { - return a == query || b == query || c == query || d == query; - } + private void removeDegenerateTetrahedronPair(V ve1, V ve2, V vf1, V vf2) { + Tetrahedron nE = getNeighbor(ve1); + Tetrahedron nF1_that = nE.getNeighbor(getVertex(vf1)); + Tetrahedron nF2_that = nE.getNeighbor(getVertex(vf2)); - /** - * Answer true if the query point is contained in the circumsphere of the - * tetrahedron - * - * @param query - * @return - */ - public boolean inSphere(Vertex query) { - return query.inSphere(a, b, c, d) > 0; + patch(vf1, nF1_that, nF1_that.ordinalOf(nE)); + patch(vf2, nF2_that, nF2_that.ordinalOf(nE)); + + Vertex e1 = getVertex(ve1); + Vertex e2 = getVertex(ve2); + Vertex f1 = getVertex(vf1); + Vertex f2 = getVertex(vf2); + + delete(); + nE.delete(); + + e1.freshenAdjacent(nF1_that); + f2.freshenAdjacent(nF1_that); + e2.freshenAdjacent(nF2_that); + f1.freshenAdjacent(nF2_that); } /** - * Answer the iterator over the faces of the tetrahedron - *

+ * Represents the oriented face opposite vertex C + * + * @author hhildebrand * - * @return the iterator of the faces, in the order of the index their opposite - * vertex */ - @Override - public Iterator iterator() { - return new Iterator<>() { - OrientedFace[] faces = { getFace(A), getFace(B), getFace(C), getFace(D) }; - int i = 0; + private class FaceADB extends OrientedFace { - @Override - public boolean hasNext() { - return i < 4; + @Override + public Tetrahedron getAdjacent() { + return nC; + } + + @Override + public Vertex[] getEdge(Vertex v) { + switch (ordinalOf(v)) { + case A: { + return new Vertex[] { d, b }; + } + case D: { + return new Vertex[] { b, a }; + } + case B: { + return new Vertex[] { a, d }; } - - @Override - public OrientedFace next() { - return faces[i++]; + default: + throw new IllegalArgumentException("Invalid vertex ordinal"); } + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } + @Override + public Tetrahedron getIncident() { + return Tetrahedron.this; + } - public Tetrahedron locate(Tuple3f query, Random entropy) { - assert query != null; + @Override + public Vertex getIncidentVertex() { + return c; + } - V o = null; - for (V face : Grid.VERTICES) { - if (orientationWrt(face, query) < 0) { - o = face; - break; + @Override + public Vertex getVertex(int v) { + switch (v) { + case 0: + return a; + case 1: + return d; + case 2: + return b; + default: + throw new IllegalArgumentException("Invalid vertex index: " + v); } } - if (o == null) { - // The query point is contained in the receiver - return this; - } - Tetrahedron current = this; - while (true) { - // get the tetrahedron on the other side of the face - Tetrahedron tetrahedron = current.getNeighbor(o); - int i = 0; - for (V v : Grid.ORDER[tetrahedron.ordinalOf(current).ordinal()][entropy.nextInt(6)]) { - o = v; - current = tetrahedron; - if (tetrahedron.orientationWrt(v, query) < 0) { - // we have found a face which the query point is on the other side - break; - } - if (i++ == 2) { - return tetrahedron; - } + @Override + public boolean includes(Vertex v) { + if ((a == v) || (d == v) || (b == v)) { + return true; } + return false; } - } + @Override + public int indexOf(Vertex v) { + if (v == a) { + return 0; + } + if (v == d) { + return 1; + } + if (v == b) { + return 2; + } + throw new IllegalArgumentException("Vertex is not on face: " + v); + } - /** - * Answer the vertex indicator of the the point - * - * @param v - the vertex - * @return the indicator of this vertex or null if not a vertex of this - * tetrahedron or the supplied vertex is null - */ - public V ordinalOf(Vertex v) { - if (v == null) { - return null; + @Override + public boolean isConvex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; + } + switch (vertex) { + case 0: + return adjacentVertex.orientation(c, d, b) == -1; + case 1: + return adjacentVertex.orientation(a, c, b) == -1; + case 2: + return adjacentVertex.orientation(a, d, c) == -1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); + } } - if (v == a) { - return A; - } else if (v == b) { - return B; - } else if (v == c) { - return C; - } else if (v == d) { - return D; - } else { - return null; + + @Override + public boolean isReflex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; + } + switch (vertex) { + case 0: + return adjacentVertex.orientation(c, d, b) == 1; + case 1: + return adjacentVertex.orientation(a, c, b) == 1; + case 2: + return adjacentVertex.orientation(a, d, c) == 1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); + } } - } - /** - * Answer > 0 if the query point is positively oriented with respect to the face - * opposite the vertex, < 0 if negatively oriented, 0 if the query point is - * coplanar to the face - * - * @param face - * @param query - * @return - */ - public int orientationWrt(V face, Tuple3f query) { - switch (face) { - case A: - return orientationWrtCBD(query); - case B: - return orientationWrtDAC(query); - case C: + @Override + public int orientationOf(Vertex query) { return orientationWrtADB(query); - case D: - return orientationWrtBCA(query); - default: - throw new IllegalArgumentException("Invalid face: " + face); } - } - /** - * Answer > 0 if the query point is positively oriented with respect to the face - * ADB, < 0 if negatively oriented, 0 if the query point is coplanar to the face - * - * @param query - * @return - */ - public int orientationWrtADB(Tuple3f query) { - return orientation(query, a, d, b); - } + @Override + public String toString() { + return "Face ADB"; + } - /** - * Answer 1 if the query point is positively oriented with respect to the face - * BCA, -1 if negatively oriented, 0 if the query point is coplanar to the face - * - * @param query - * @return - */ - public int orientationWrtBCA(Tuple3f query) { - return orientation(query, b, c, a); } /** - * Answer 1 if the query point is positively oriented with respect to the face - * CBD, -1 if negatively oriented, 0 if the query point is coplanar to the face + * Represents the oriented face opposite of vertex D * - * @param query - * @return - */ - public int orientationWrtCBD(Tuple3f query) { - return orientation(query, c, b, d); - } - - /** - * Answer 1 if the query point is positively oriented with respect to the face - * DAC, -1 if negatively oriented, 0 if the query point is coplanar to the face + * @author hhildebrand * - * @param query - * @return */ - public int orientationWrtDAC(Tuple3f query) { - return orientation(query, d, a, c); - } + private class FaceBCA extends OrientedFace { - @Override - public String toString() { - StringBuffer buf = new StringBuffer(); - buf.append("Tetrahedron ["); - if (isDeleted()) { - buf.append("DELETED]"); - return buf.toString(); - } - for (Vertex v : getVertices()) { - buf.append(v); - buf.append(", "); + @Override + public Tetrahedron getAdjacent() { + return nD; } - buf.append(']'); - return buf.toString(); - } - void children(Stack stack, Set processed) { - if (nA != null && !processed.contains(nA)) { - stack.push(nA); + @Override + public Vertex[] getEdge(Vertex v) { + switch (ordinalOf(v)) { + case B: { + return new Vertex[] { c, a }; + } + case C: { + return new Vertex[] { a, b }; + } + case A: { + return new Vertex[] { b, c }; + } + default: + throw new IllegalArgumentException("Invalid vertex ordinal"); + } } - if (nB != null && !processed.contains(nB)) { - stack.push(nB); + + @Override + public Tetrahedron getIncident() { + return Tetrahedron.this; } - if (nC != null && !processed.contains(nC)) { - stack.push(nC); + + @Override + public Vertex getIncidentVertex() { + return d; } - if (nD != null && !processed.contains(nD)) { - stack.push(nD); + + @Override + public Vertex getVertex(int v) { + switch (v) { + case 0: + return b; + case 1: + return c; + case 2: + return a; + default: + throw new IllegalArgumentException("Invalid vertex index: " + v); + } } - } - - /** - * Clean up the pointers - */ - void delete() { - nA = nB = nC = nD = null; - a = b = c = d = null; - } - Vertex getA() { - return a; - } + @Override + public boolean includes(Vertex v) { + if ((b == v) || (c == v) || (a == v)) { + return true; + } + return false; + } - Vertex getB() { - return b; - } + @Override + public int indexOf(Vertex v) { + if (v == b) { + return 0; + } + if (v == c) { + return 1; + } + if (v == a) { + return 2; + } + throw new IllegalArgumentException("Vertex is not on face: " + v); + } - Vertex getC() { - return c; - } + @Override + public boolean isConvex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; + } - Vertex getD() { - return d; - } + switch (vertex) { + case 0: + return adjacentVertex.orientation(d, c, a) == -1; + case 1: + return adjacentVertex.orientation(b, d, a) == -1; + case 2: + return adjacentVertex.orientation(b, c, d) == -1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); + } + } - boolean isDeleted() { - return a == null; - } + @Override + public boolean isReflex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; + } - /** - * Answer the canonical ordinal of the opposite vertex of the neighboring - * tetrahedron - * - * @param neighbor - * @return - */ - V ordinalOf(Tetrahedron neighbor) { - if (neighbor == null) { - return null; - } - if (nA == neighbor) { - return A; - } - if (nB == neighbor) { - return B; - } - if (nC == neighbor) { - return C; + switch (vertex) { + case 0: + return adjacentVertex.orientation(d, c, a) == 1; + case 1: + return adjacentVertex.orientation(b, d, a) == 1; + case 2: + return adjacentVertex.orientation(b, c, d) == 1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); + } } - if (nD == neighbor) { - return D; + + @Override + public int orientationOf(Vertex query) { + return orientationWrtBCA(query); } - throw new IllegalArgumentException("Not a neighbor: " + neighbor); - } - /** - * Patch the new tetrahedron created by a flip of the receiver by seting the - * neighbor to the value in the receiver - *

- * - * @param vOld - the opposing vertex the neighboring tetrahedron in the receiver - * @param n - the new tetrahedron to patch - * @param vNew - the opposing vertex of the neighbor to assign in the new - * tetrahedron - */ - void patch(V vOld, Tetrahedron n, V vNew) { - Tetrahedron neighbor = getNeighbor(vOld); - if (neighbor != null) { - neighbor.setNeighbor(neighbor.ordinalOf(this), n); - n.setNeighbor(vNew, neighbor); + @Override + public String toString() { + return "Face BCA"; } + } /** - * Patch the new tetrahedron created by a flip of the receiver by seting the - * neighbor to the value in the receiver - *

+ * Represents the oriented face opposite of vertex A + * + * @author hhildebrand * - * @param old - * @param n - * @param vNew */ - void patch(Vertex old, Tetrahedron n, V vNew) { - patch(ordinalOf(old), n, vNew); - } + private class FaceCBD extends OrientedFace { - void removeAnyDegenerateTetrahedronPair() { - if (nA != null) { - if (nA == nB) { - removeDegenerateTetrahedronPair(V.A, V.B, V.C, V.D); - return; + @Override + public Tetrahedron getAdjacent() { + return nA; + } + + @Override + public Vertex[] getEdge(Vertex v) { + switch (ordinalOf(v)) { + case C: { + return new Vertex[] { b, d }; } - if (nA == nC) { - removeDegenerateTetrahedronPair(V.A, V.C, V.B, V.D); - return; + case B: { + return new Vertex[] { d, c }; } - if (nA == nD) { - removeDegenerateTetrahedronPair(V.A, V.D, V.B, V.C); - return; + case D: { + return new Vertex[] { c, b }; + } + default: + throw new IllegalArgumentException("Invalid vertex ordinal"); } } - if (nB != null) { - if (nB == nC) { - removeDegenerateTetrahedronPair(V.B, V.C, V.A, V.D); - return; - } - if (nB == nD) { - removeDegenerateTetrahedronPair(V.B, V.D, V.A, V.C); - return; - } + @Override + public Tetrahedron getIncident() { + return Tetrahedron.this; } - if (nC != null) - if (nC == nD) { - removeDegenerateTetrahedronPair(V.C, V.D, V.A, V.B); - return; - } - } + @Override + public Vertex getIncidentVertex() { + return a; + } - void setNeighbor(V v, Tetrahedron n) { - switch (v) { - case A: - nA = n; - break; - case B: - nB = n; - break; - case C: - nC = n; - break; - case D: - nD = n; - break; - default: - throw new IllegalArgumentException("Invalid vertex: " + v); + @Override + public Vertex getVertex(int v) { + switch (v) { + case 0: + return c; + case 1: + return b; + case 2: + return d; + default: + throw new IllegalArgumentException("Invalid vertex index: " + v); + } } - } - void setNeighborA(Tetrahedron t) { - nA = t; - } + @Override + public boolean includes(Vertex v) { + if ((c == v) || (b == v) || (d == v)) { + return true; + } + return false; + } - void setNeighborB(Tetrahedron t) { - nB = t; - } + @Override + public int indexOf(Vertex v) { + if (v == c) { + return 0; + } + if (v == b) { + return 1; + } + if (v == d) { + return 2; + } + throw new IllegalArgumentException("Vertex is not on face: " + v); + } - void setNeighborC(Tetrahedron t) { - nC = t; - } + @Override + public boolean isConvex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; + } + switch (vertex) { + case 0: + return adjacentVertex.orientation(a, b, d) == -1; + case 1: + return adjacentVertex.orientation(c, a, d) == -1; + case 2: + return adjacentVertex.orientation(c, b, a) == -1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); + } + } - void setNeighborD(Tetrahedron t) { - nD = t; - } + @Override + public boolean isReflex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; + } + switch (vertex) { + case 0: + return adjacentVertex.orientation(a, b, d) == 1; + case 1: + return adjacentVertex.orientation(c, a, d) == 1; + case 2: + return adjacentVertex.orientation(c, b, a) == 1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); + } + } - /** - * Traverse the points which define the voronoi face defined by the dual of the - * line segement defined by the center point and the axis. Terminate the - * traversal if we have returned to the originating tetrahedron. - *

- * - * @param origin - * @param from - * @param vC - * @param axis - * @param face - */ - void traverseVoronoiFace(Tetrahedron origin, Tetrahedron from, Vertex vC, Vertex axis, List face) { - if (origin == this) { - return; + @Override + public int orientationOf(Vertex query) { + return orientationWrtCBD(query); } - float[] center = new float[3]; - centerSphereFast(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 Point3f(center[0], center[1], center[2])); - V next = VORONOI_FACE_NEXT[ordinalOf(from).ordinal()][ordinalOf(vC).ordinal()][ordinalOf(axis).ordinal()]; - Tetrahedron t = getNeighbor(next); - if (t != null) { - t.traverseVoronoiFace(origin, this, vC, axis, face); + + @Override + public String toString() { + return "Face CBD"; } } /** - * Traverse the points which define the voronoi face defined by the dual of the - * line segement defined by the center point and the axis. - *

+ * Represents the oriented face opposite of vertex B + * + * @author hhildebrand * - * @param vC - * @param axis - * @param face */ - void traverseVoronoiFace(Vertex vC, Vertex axis, List faces) { - ArrayList face = new ArrayList<>(); - float[] center = new float[3]; - centerSphereFast(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 Point3f(center[0], center[1], center[2])); - V v = VORONOI_FACE_ORIGIN[ordinalOf(vC).ordinal()][ordinalOf(axis).ordinal()]; - Tetrahedron next = getNeighbor(v); - if (next != null) { - next.traverseVoronoiFace(this, this, vC, axis, face); + private class FaceDAC extends OrientedFace { + + @Override + public Tetrahedron getAdjacent() { + return nB; } - faces.add(face.toArray(new Point3f[face.size()])); - } - /** - * visit the receiver and push unvisited tetrahedrons around the supplied vertex - * - * @param vC - the center vertex - * @param visitor - the star visitor - * @param stack - the stack of visitations - */ - void visit(Vertex vC, StarVisitor visitor, Stack stack, Set visited) { - switch (ordinalOf(vC)) { - case A: - visitor.visit(A, this, c, b, d); - if (nC != null) { - stack.push(nC); - } - if (nB != null) { - stack.push(nC); + @Override + public Vertex[] getEdge(Vertex v) { + switch (ordinalOf(v)) { + case D: { + return new Vertex[] { a, c }; } - if (nD != null) { - stack.push(nD); + case A: { + return new Vertex[] { c, d }; } - break; - case B: - visitor.visit(B, this, d, a, c); - if (nD != null) { - stack.push(nD); + case C: { + return new Vertex[] { d, a }; } - if (nA != null) { - stack.push(nA); + default: + throw new IllegalArgumentException("Invalid vertex ordinal"); } - if (nC != null) { - stack.push(nC); + } + + @Override + public Tetrahedron getIncident() { + return Tetrahedron.this; + } + + @Override + public Vertex getIncidentVertex() { + return b; + } + + @Override + public Vertex getVertex(int v) { + switch (v) { + case 0: + return d; + case 1: + return a; + case 2: + return c; + default: + throw new IllegalArgumentException("Invalid vertex index: " + v); } - break; - case C: - visitor.visit(C, this, a, d, b); - if (nA != null) { - stack.push(nA); + } + + @Override + public boolean includes(Vertex v) { + if ((d == v) || (a == v) || (c == v)) { + return true; } - if (nD != null) { - stack.push(nD); + return false; + } + + @Override + public int indexOf(Vertex v) { + if (v == d) { + return 0; } - if (nB != null) { - stack.push(nB); + if (v == a) { + return 1; } - break; - case D: - visitor.visit(D, this, b, c, a); - if (nB != null) { - stack.push(nB); + if (v == c) { + return 2; } - if (nA != null) { - stack.push(nB); + throw new IllegalArgumentException("Vertex is not on face: " + v); + } + + @Override + public boolean isConvex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; } - if (nC != null) { - stack.push(nC); + switch (vertex) { + case 0: + return adjacentVertex.orientation(b, a, c) == -1; + case 1: + return adjacentVertex.orientation(d, b, c) == -1; + case 2: + return adjacentVertex.orientation(d, a, b) == -1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); } - break; - default: - throw new IllegalArgumentException("Invalid center vertex: " + vC); } - } - /** - * Visit the star tetrahedra set of the of the center vertex - * - * @param vC - the center vertex - * @param visitor - the visitor to invoke for each tetrahedron in the star - */ - void visitStar(Vertex vC, StarVisitor visitor) { - Set tetrahedrons = new IdentitySet<>(10); - var stack = new Stack(); - stack.push(this); - while (!stack.isEmpty()) { - var t = stack.pop(); - if (tetrahedrons.add(t)) { - t.visit(vC, visitor, stack, tetrahedrons); + @Override + public boolean isReflex(int vertex) { + Vertex adjacentVertex = getAdjacentVertex(); + if (adjacentVertex == null) { + return false; + } + switch (vertex) { + case 0: + return adjacentVertex.orientation(b, a, c) == 1; + case 1: + return adjacentVertex.orientation(d, b, c) == 1; + case 2: + return adjacentVertex.orientation(d, a, b) == 1; + default: + throw new IllegalArgumentException("Invalid vertex index: " + vertex); } } - } - - private void removeDegenerateTetrahedronPair(V ve1, V ve2, V vf1, V vf2) { - Tetrahedron nE = getNeighbor(ve1); - Tetrahedron nF1_that = nE.getNeighbor(getVertex(vf1)); - Tetrahedron nF2_that = nE.getNeighbor(getVertex(vf2)); - - patch(vf1, nF1_that, nF1_that.ordinalOf(nE)); - patch(vf2, nF2_that, nF2_that.ordinalOf(nE)); - Vertex e1 = getVertex(ve1); - Vertex e2 = getVertex(ve2); - Vertex f1 = getVertex(vf1); - Vertex f2 = getVertex(vf2); + @Override + public int orientationOf(Vertex query) { + return orientationWrtDAC(query); + } - delete(); - nE.delete(); + @Override + public String toString() { + return "Face DAC"; + } - e1.freshenAdjacent(nF1_that); - f2.freshenAdjacent(nF1_that); - e2.freshenAdjacent(nF2_that); - f1.freshenAdjacent(nF2_that); } } diff --git a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/V.java b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/V.java index 1c8a90c..bb3719c 100644 --- a/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/V.java +++ b/lucien/src/main/java/com/hellblazer/luciferase/lucien/grid/V.java @@ -3,18 +3,16 @@ * * This file is part of the 3D Incremental Voronoi system * - * 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 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. + * 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 . + * 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; 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 affd864..a91019b 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 @@ -3,38 +3,27 @@ * * This file is part of the 3D Incremental Voronoi system * - * 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 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. + * 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 . + * 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 java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Deque; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Random; -import java.util.Set; +import com.hellblazer.luciferase.common.IdentitySet; +import com.hellblazer.luciferase.geometry.Geometry; import javax.vecmath.Point3f; import javax.vecmath.Tuple3f; import javax.vecmath.Vector3f; - -import com.hellblazer.luciferase.common.IdentitySet; -import com.hellblazer.luciferase.geometry.Geometry; +import java.util.*; /** * @@ -42,12 +31,27 @@ * */ public class Vertex extends Vector3f implements Iterable { + static final Point3f ORIGIN = new Point3f(0, 0, 0); + private static final long serialVersionUID = 1L; /** - * Minimal zero + * One of the tetrahedra adjacent to the vertex */ - static final double EPSILON = Math.pow(10F, -20F); - static final Point3f ORIGIN = new Point3f(0, 0, 0); - private static final long serialVersionUID = 1L; + private Tetrahedron adjacent; + private Vertex next; // linked list o' vertices + + public Vertex(float i, float j, float k) { + x = i; + y = j; + z = k; + } + + public Vertex(float i, float j, float k, float scale) { + this(i * scale, j * scale, k * scale); + } + + public Vertex(Tuple3f p) { + this(p.x, p.y, p.z); + } /** * Create some random points in a sphere @@ -106,27 +110,6 @@ 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)); } - /** - * One of the tetrahedra adjacent to the vertex - */ - private Tetrahedron adjacent; - - private Vertex next; // linked list o' vertices - - public Vertex(float i, float j, float k) { - x = i; - y = j; - z = k; - } - - public Vertex(float i, float j, float k, float scale) { - this(i * scale, j * scale, k * scale); - } - - public Vertex(Tuple3f p) { - this(p.x, p.y, p.z); - } - /** * Answer the component model of the receiver corresponding to the model class * @@ -156,6 +139,16 @@ public final Tetrahedron getAdjacent() { return adjacent; } + /** + * Note one of the adjacent tetrahedron + *

+ * + * @param tetrahedron + */ + final void setAdjacent(Tetrahedron tetrahedron) { + adjacent = tetrahedron; + } + public final List getEars() { assert adjacent != null; EarSet aggregator = new EarSet(); @@ -193,7 +186,7 @@ public final Deque getStar() { /** * Answer the faces of the voronoi region around the receiver - * + * * @return the list of faces defining the voronoi region defined by the receiver */ public final List getVoronoiRegion() { @@ -219,7 +212,7 @@ public final List 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(Vertex, Vertex, Vertex)}), or + * orientation (as defined by {@link #orientation(Tuple3f, Tuple3f, Tuple3f)}), or * the sign of the result will be reversed. *

* @@ -340,14 +333,4 @@ void reset() { adjacent = null; } - /** - * Note one of the adjacent tetrahedron - *

- * - * @param tetrahedron - */ - final void setAdjacent(Tetrahedron tetrahedron) { - adjacent = tetrahedron; - } - } diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..19529dd --- /dev/null +++ b/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml index 638bf89..2a16402 100644 --- a/pom.xml +++ b/pom.xml @@ -423,4 +423,4 @@ - \ No newline at end of file + diff --git a/portal/src/main/java/com/hellblazer/luciferase/portal/mesh/polyhedra/archimedes/RhombicDodecahedron.java b/portal/src/main/java/com/hellblazer/luciferase/portal/mesh/polyhedra/archimedes/RhombicDodecahedron.java index c5d4759..f49f8e5 100644 --- a/portal/src/main/java/com/hellblazer/luciferase/portal/mesh/polyhedra/archimedes/RhombicDodecahedron.java +++ b/portal/src/main/java/com/hellblazer/luciferase/portal/mesh/polyhedra/archimedes/RhombicDodecahedron.java @@ -36,7 +36,7 @@ public static TriangleMesh createRhombicDodecahedron(double height) { mesh.getPoints() .addAll( - // in ascending z order and counter clockwise from the x axis as 0degrees + // in ascending z order and counter-clockwise from the x-axis as 0degrees 0, 0, -r, // A0 -z axis s, -s, -s, // B1 -s, -s, -s, // C2