[orx-shapes] Add simple alphaShape interface

This commit is contained in:
Edwin Jakobs
2021-11-20 23:53:01 +01:00
parent 085bca0106
commit 43b78954e5

View File

@@ -8,6 +8,13 @@ import kotlin.math.min
import kotlin.math.pow
import kotlin.math.sqrt
/**
* Create an alpha shape from list of [Vector2]
*/
fun List<Vector2>.alphaShape(): Shape {
return AlphaShape(this).createShape()
}
private fun circumradius(p1: Vector2, p2: Vector2, p3: Vector2): Double {
val a = (p2 - p1).length
val b = (p3 - p2).length
@@ -96,8 +103,8 @@ class AlphaShape(val points: List<Vector2>) {
* As alpha goes to infinity, the alpha shape becomes equal to the convex hull of the input points.
* @return A list of [LineSegment]s representing the perimeter of the alpha shape.
*/
fun createSegments(alpha: Double): List<LineSegment>
= createBase(alpha).map { LineSegment(getVec(it.first), getVec(it.second)) }
fun createSegments(alpha: Double): List<LineSegment> =
createBase(alpha).map { LineSegment(getVec(it.first), getVec(it.second)) }
private fun getVec(i: Int) = Vector2(delaunay.points[i], delaunay.points[i + 1])