Skip to content

Commit

Permalink
Fix .update()
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardomatias committed Jan 29, 2021
1 parent 3c9a01e commit 7cc928f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 83 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ A Kotlin port of Mapbox's [Delaunator](https://github.com/mapbox/delaunator) inc

```graddle
repositories {
maven { jcenter() }
// or
maven { url "https://jitpack.io" }
}
dependencies {
compile "com.github.ricardomatias:delaunator:1.0.0"
compile "com.github.ricardomatias:delaunator:1.0.1"
}
```

Expand Down
124 changes: 61 additions & 63 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ buildscript {
dependencies {
classpath "com.netflix.nebula:nebula-publishing-plugin:17.3.0"
classpath "com.netflix.nebula:nebula-release-plugin:15.1.0"
classpath "com.github.ben-manes:gradle-versions-plugin:0.28.0"

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21"
}
}

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.21'
id 'idea'
id 'java'

id "com.github.ben-manes.versions" version '0.28.0'
id "com.jfrog.bintray" version "1.8.5"
id 'maven-publish'

}

project.ext {
Expand Down Expand Up @@ -42,81 +46,75 @@ tasks.create('javadocJar', Jar) {
archiveExtension.set("jar")
}

allprojects {
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven-publish'
apply plugin: 'nebula.contacts'
apply plugin: 'nebula.info'
apply plugin: 'nebula.maven-publish'
apply plugin: 'nebula.contacts'
apply plugin: 'nebula.info'
apply plugin: 'nebula.maven-publish'
apply plugin: 'nebula.release'

apply plugin: "com.github.ben-manes.versions"
group 'com.github.ricardomatias'
version '1.0.1'

group 'com.github.ricardomatias'
version '1.0.0'
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/java'
}

sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/java'
}

repositories {
jcenter()
maven {
url "https://jitpack.io"
}
// mavenLocal()
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
mavenLocal()
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}


publishing {
publications {
delaunatorPublishing(MavenPublication) {
from components.java
artifact tasks.sourceJar
artifact tasks.javadocJar
publishing {
publications {
delaunatorPublishing(MavenPublication) {
from components.java
artifact tasks.sourceJar
artifact tasks.javadocJar

groupId 'com.github.ricardomatias'
artifactId 'delaunator'
version '1.0.0'
}
groupId(project.group)
artifactId 'delaunator'
version(project.version)
}
}
}

bintray {
user = properties.getProperty("bintrayUser")
key = properties.getProperty("bintrayKey")
publications = ['delaunatorPublishing']

pkg {
repo = 'maven'
name = 'delaunator'
licenses = ['ISC']
userOrg = "ricardomatias"

version {
name = project.version
released = new Date()
vcsTag = "v${project.version}"
vcsUrl = 'https://github.com/ricardomatias/delaunator.git'
}
bintray {
user = properties.getProperty("bintrayUser")
key = properties.getProperty("bintrayKey")
publications = ['delaunatorPublishing']

pkg {
repo = 'maven'
name = 'delaunator'
licenses = ['ISC']
userOrg = "ricardomatias"
publish = true

version {
name = project.version
released = new Date()
vcsTag = "v${project.version}"
vcsUrl = 'https://github.com/ricardomatias/delaunator.git'
}
}
}

contacts {
'@ricardomatias' {
moniker 'Ricardo Matias'
github 'ricardomatias'
}
contacts {
'@ricardomatias' {
moniker 'Ricardo Matias'
github 'ricardomatias'
}
}
}
41 changes: 22 additions & 19 deletions src/main/kotlin/com/github/ricardomatias/Delaunator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class Delaunator(val coords: DoubleArray) {

// arrays that will store the triangulation graph
val maxTriangles = (2 * count - 5).coerceAtLeast(0)
var triangles = IntArray(maxTriangles * 3)
var halfedges = IntArray(maxTriangles * 3)
private val _triangles = IntArray(maxTriangles * 3)
private val _halfedges = IntArray(maxTriangles * 3)

lateinit var triangles: IntArray
lateinit var halfedges: IntArray

// temporary arrays for tracking the edges of the advancing convex hull
private var hashSize = ceil(sqrt(count * 1.0)).toInt()
Expand Down Expand Up @@ -109,7 +112,7 @@ class Delaunator(val coords: DoubleArray) {
var minRadius = Double.POSITIVE_INFINITY

// Find the third point which forms the smallest circumcircle with the first two
for(i in 0 until count) {
for (i in 0 until count) {
if(i == i0 || i == i1) continue

val r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1])
Expand Down Expand Up @@ -309,8 +312,8 @@ class Delaunator(val coords: DoubleArray) {
}

// trim typed triangle mesh arrays
triangles = triangles.copyOf(trianglesLen)
halfedges = halfedges.copyOf(trianglesLen)
triangles = _triangles.copyOf(trianglesLen)
halfedges = _halfedges.copyOf(trianglesLen)
}

private fun legalize(a: Int): Int {
Expand All @@ -320,7 +323,7 @@ class Delaunator(val coords: DoubleArray) {

// recursion eliminated with a fixed-size stack
while (true) {
val b = halfedges[na]
val b = _halfedges[na]

/* if the pair of triangles doesn't satisfy the Delaunay condition
* (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
Expand Down Expand Up @@ -350,10 +353,10 @@ class Delaunator(val coords: DoubleArray) {
val al = a0 + (na + 1) % 3
val bl = b0 + (b + 2) % 3

val p0 = triangles[ar]
val pr = triangles[na]
val pl = triangles[al]
val p1 = triangles[bl]
val p0 = _triangles[ar]
val pr = _triangles[na]
val pl = _triangles[al]
val p1 = _triangles[bl]

val illegal = inCircle(
coords[2 * p0], coords[2 * p0 + 1],
Expand All @@ -362,10 +365,10 @@ class Delaunator(val coords: DoubleArray) {
coords[2 * p1], coords[2 * p1 + 1])

if (illegal) {
triangles[na] = p1
triangles[b] = p0
_triangles[na] = p1
_triangles[b] = p0

val hbl = halfedges[bl]
val hbl = _halfedges[bl]

// edge swapped on the other side of the hull (rare) fix the halfedge reference
if (hbl == -1) {
Expand All @@ -379,7 +382,7 @@ class Delaunator(val coords: DoubleArray) {
} while (e != hullStart)
}
link(na, hbl)
link(b, halfedges[ar])
link(b, _halfedges[ar])
link(ar, bl)

val br = b0 + (b + 1) % 3
Expand All @@ -399,17 +402,17 @@ class Delaunator(val coords: DoubleArray) {
}

private fun link(a:Int, b:Int) {
halfedges[a] = b
if (b != -1) halfedges[b] = a
_halfedges[a] = b
if (b != -1) _halfedges[b] = a
}

// add a new triangle given vertex indices and adjacent half-edge ids
private fun addTriangle(i0: Int, i1: Int, i2: Int, a: Int, b: Int, c: Int): Int {
val t = trianglesLen

triangles[t] = i0
triangles[t + 1] = i1
triangles[t + 2] = i2
_triangles[t] = i0
_triangles[t + 1] = i1
_triangles[t + 2] = i2

link(t, a)
link(t + 1, b)
Expand Down

0 comments on commit 7cc928f

Please sign in to comment.