Skip to content

Commit

Permalink
[orx-shapes] Fix RectifiedPath.kt for closed contours; Closes #334
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed May 14, 2024
1 parent 4db8f28 commit cebc217
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions orx-shapes/src/jvmDemo/kotlin/rectify/DemoRectifiedContour04.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit cebc217

Please sign in to comment.