[orx-shapes] Fix RectifiedPath.kt for closed contours; Closes #334
This commit is contained in:
@@ -14,9 +14,11 @@ abstract class RectifiedPath<T : EuclideanVector<T>>(
|
|||||||
distanceTolerance: Double = 0.5,
|
distanceTolerance: Double = 0.5,
|
||||||
lengthScale: Double = 1.0
|
lengthScale: Double = 1.0
|
||||||
) {
|
) {
|
||||||
val points =
|
val candidatePoints =
|
||||||
originalPath.equidistantPositionsWithT((originalPath.length * lengthScale).toInt().coerceAtLeast(2), distanceTolerance)
|
originalPath.equidistantPositionsWithT((originalPath.length * lengthScale).toInt().coerceAtLeast(2), distanceTolerance)
|
||||||
|
|
||||||
|
val points = if (originalPath.closed) candidatePoints + candidatePoints.first() else candidatePoints
|
||||||
|
|
||||||
val intervals by lazy {
|
val intervals by lazy {
|
||||||
points.zipWithNext().map {
|
points.zipWithNext().map {
|
||||||
Pair(it.first.second, it.second.second)
|
Pair(it.first.second, it.second.second)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user