diff --git a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt index 2dfa0ea4..c7b2ec58 100644 --- a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt +++ b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt @@ -14,9 +14,11 @@ abstract class RectifiedPath>( 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) diff --git a/orx-shapes/src/jvmDemo/kotlin/rectify/DemoRectifiedContour04.kt b/orx-shapes/src/jvmDemo/kotlin/rectify/DemoRectifiedContour04.kt new file mode 100644 index 00000000..db883063 --- /dev/null +++ b/orx-shapes/src/jvmDemo/kotlin/rectify/DemoRectifiedContour04.kt @@ -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) + } + } +} \ No newline at end of file