Skip to content

Commit

Permalink
[orx-shapes] Fix bug in RectifiedPath for closed paths
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed May 22, 2024
1 parent d2e6d00 commit 86ae5f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class RectifiedPath<T : EuclideanVector<T>>(
val candidatePoints =
originalPath.equidistantPositionsWithT((originalPath.length * lengthScale).toInt().coerceAtLeast(2), distanceTolerance)

val points = if (originalPath.closed) candidatePoints + candidatePoints.first() else candidatePoints
val points = if (originalPath.closed) candidatePoints + candidatePoints.first().copy(second = 1.0) else candidatePoints

val intervals by lazy {
points.zipWithNext().map {
Expand Down
10 changes: 9 additions & 1 deletion orx-shapes/src/commonTest/kotlin/TestRectifiedContour.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ import org.openrndr.shape.Circle
import org.openrndr.shape.Ellipse
import kotlin.math.abs
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class TestRectifiedContour {

@Test
fun testEquidistantPointsWithT() {
val c = Circle(200.0, 200.0, 100.0).contour
val ep = (c.equidistantPositionsWithT(c.length.toInt()))
assertEquals(0.0, (ep[0].second))
}


@Test
fun testInverse() {
val c = Ellipse(40.0, 40.0, 40.0, 80.0).contour.sub(0.0, 0.333)
Expand All @@ -15,6 +24,5 @@ class TestRectifiedContour {
val ri = r.inverseRectify(rt)

assertTrue(abs(ri-0.125) < 1E-5)

}
}

0 comments on commit 86ae5f7

Please sign in to comment.