[orx-triangulation] Improve triangulation, add kotlin/js support

This commit is contained in:
Edwin Jakobs
2022-10-21 10:33:24 +02:00
parent ed6cda8cca
commit 1f16aa6a31
21 changed files with 1608 additions and 251 deletions

View File

@@ -0,0 +1,53 @@
import org.openrndr.extra.triangulation.Delaunay
import org.openrndr.extra.triangulation.delaunayTriangulation
import org.openrndr.math.Vector2
import org.openrndr.shape.Circle
import org.openrndr.shape.Rectangle
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class TestVoronoiDiagram {
@Test
fun testNeighbors() {
val c = Circle(200.0, 200.0, 150.0).contour.equidistantPositions(20).take(20)
val d = Delaunay.from(c)
val v = d.voronoi(Rectangle(0.0, 0.0, 400.0, 400.0))
for (j in c.indices) {
assertTrue(v.neighbors(j).toList().isNotEmpty())
}
}
@Test
fun testEmpty() {
val dt = listOf<Vector2>().delaunayTriangulation()
val v = dt.voronoiDiagram(Rectangle(0.0, 0.0, 400.0, 400.0))
assertEquals(0, dt.triangles().size)
assertEquals(0, v.cellPolygons().size)
}
@Test
fun testOnePoint() {
val dt = listOf(Vector2(100.0, 100.0)).delaunayTriangulation()
val v = dt.voronoiDiagram(Rectangle(0.0, 0.0, 400.0, 400.0))
assertEquals(0, dt.triangles().size)
assertEquals(1, v.cellPolygons().size)
}
@Test
fun testTwoPoints() {
val dt = listOf(Vector2(100.0, 100.0), Vector2(300.0, 300.0)).delaunayTriangulation()
val v = dt.voronoiDiagram(Rectangle(0.0, 0.0, 400.0, 400.0))
assertEquals(1, dt.triangles().size)
assertEquals(2, v.cellPolygons().size)
}
@Test
fun testThreePointsCollinear() {
val dt = listOf(Vector2(100.0, 100.0), Vector2(200.0, 200.0), Vector2(300.0, 300.0)).delaunayTriangulation()
val v = dt.voronoiDiagram(Rectangle(0.0, 0.0, 400.0, 400.0))
assertEquals(1, dt.triangles().size)
assertEquals(3, v.cellPolygons().size)
}
}