[orx-shapes] Fix RectifiedPath.kt for closed contours; Closes #334

This commit is contained in:
Edwin Jakobs
2024-05-14 23:09:55 +02:00
parent 4db8f28543
commit cebc217c94
2 changed files with 30 additions and 1 deletions

View File

@@ -14,9 +14,11 @@ abstract class RectifiedPath<T : EuclideanVector<T>>(
distanceTolerance: Double = 0.5,
lengthScale: Double = 1.0
) {
val points =
val candidatePoints =
originalPath.equidistantPositionsWithT((originalPath.length * lengthScale).toInt().coerceAtLeast(2), distanceTolerance)
val points = if (originalPath.closed) candidatePoints + candidatePoints.first() else candidatePoints
val intervals by lazy {
points.zipWithNext().map {
Pair(it.first.second, it.second.second)

View File

@@ -0,0 +1,27 @@
package rectify
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.rectify.rectified
import org.openrndr.shape.Circle
import org.openrndr.shape.Segment2D
fun main() = application {
configure {
width = 720
height = 720
}
program {
val c = Circle(drawer.bounds.center, 50.0).contour
val rc = c.rectified()
val normals = List(200) {
val t = it / 200.0
val p = rc.position(t)
val n = rc.normal(t)
Segment2D(p, p + n * 200.0)
}
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.segments(normals)
}
}
}