[orx-triangulator] fix .update() methods (#163)

This commit is contained in:
Ricardo Matias
2021-01-29 12:24:44 +01:00
committed by GitHub
parent a3fea2daa6
commit b58870bee9
3 changed files with 14 additions and 7 deletions

View File

@@ -8,10 +8,13 @@ sourceSets {
}
}
def useSnapshot = false
def delaunatorVersion = (useSnapshot) ? "0.4.0-SNAPSHOT" : "1.0.1"
dependencies {
implementation project(":orx-noise")
implementation("com.github.ricardomatias:delaunator:1.0.0")
implementation("com.github.ricardomatias:delaunator:$delaunatorVersion")
demoImplementation("org.openrndr:openrndr-core:$openrndrVersion")
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")

View File

@@ -59,10 +59,8 @@ class Delaunay(val points: DoubleArray) {
private var delaunator = Delaunator(points)
val inedges = IntArray(points.size / 2) { -1 }
private val hullIndex = IntArray(points.size / 2) { -1 }
private var collinear = IntArray(points.size / 2) { it }
val inedges = IntArray(points.size / 2)
private val hullIndex = IntArray(points.size / 2)
var halfedges = delaunator.halfedges
var hull = delaunator.hull
@@ -82,6 +80,9 @@ class Delaunay(val points: DoubleArray) {
hull = delaunator.hull
triangles = delaunator.triangles
inedges.fill(-1)
hullIndex.fill(-1)
// Compute an index from each point to an (arbitrary) incoming halfedge
// Used to give the first neighbor of each point for this reason,
// on the hull we give priority to exterior halfedges

View File

@@ -37,7 +37,8 @@ THIS SOFTWARE.
*/
class Voronoi(val delaunay: Delaunay, val bounds: Rectangle) {
private val _circumcenters = DoubleArray(delaunay.points.size * 2)
val circumcenters = _circumcenters.copyOf(delaunay.triangles.size / 3 * 2)
lateinit var circumcenters: DoubleArray
private set
val vectors = DoubleArray(delaunay.points.size * 2)
@@ -55,6 +56,8 @@ class Voronoi(val delaunay: Delaunay, val bounds: Rectangle) {
val triangles = delaunay.triangles
val hull = delaunay.hull
circumcenters = _circumcenters.copyOf(delaunay.triangles.size / 3 * 2)
// Compute circumcenters
var i = 0
var j = 0
@@ -160,7 +163,7 @@ class Voronoi(val delaunay: Delaunay, val bounds: Rectangle) {
val polygon = mutableListOf(Vector2(points[0], points[1]))
var n = points.size
while (points[0] == points[n-2] && points[1] == points[n-1] && n > 1) n -= 2
while (n > 1 && points[0] == points[n - 2] && points[1] == points[n - 1]) n -= 2
for (idx in 2 until n step 2) {
if (points[idx] != points[idx - 2] || points[idx + 1] != points[idx - 1]) {