From 86ae5f70def53485aeb17f8604d403261ae14af7 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Wed, 22 May 2024 12:17:23 +0200 Subject: [PATCH] [orx-shapes] Fix bug in RectifiedPath for closed paths --- .../src/commonMain/kotlin/rectify/RectifiedPath.kt | 2 +- .../src/commonTest/kotlin/TestRectifiedContour.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt index c7b2ec58..a971bd30 100644 --- a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt +++ b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt @@ -17,7 +17,7 @@ abstract class RectifiedPath>( 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 { diff --git a/orx-shapes/src/commonTest/kotlin/TestRectifiedContour.kt b/orx-shapes/src/commonTest/kotlin/TestRectifiedContour.kt index d0290361..b4e81c97 100644 --- a/orx-shapes/src/commonTest/kotlin/TestRectifiedContour.kt +++ b/orx-shapes/src/commonTest/kotlin/TestRectifiedContour.kt @@ -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) @@ -15,6 +24,5 @@ class TestRectifiedContour { val ri = r.inverseRectify(rt) assertTrue(abs(ri-0.125) < 1E-5) - } } \ No newline at end of file