Skip to content

Commit

Permalink
[orx-triangulator] fix .update() methods (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardomatias authored Jan 29, 2021
1 parent a3fea2d commit b58870b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion orx-triangulation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions orx-triangulation/src/main/kotlin/Delaunay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions orx-triangulation/src/main/kotlin/Voronoi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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]) {
Expand Down

0 comments on commit b58870b

Please sign in to comment.