[orx-shapes] Fix bug in RectifiedPath for closed paths
This commit is contained in:
@@ -17,7 +17,7 @@ abstract class RectifiedPath<T : EuclideanVector<T>>(
|
|||||||
val candidatePoints =
|
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 points = if (originalPath.closed) candidatePoints + candidatePoints.first().copy(second = 1.0) else candidatePoints
|
||||||
|
|
||||||
val intervals by lazy {
|
val intervals by lazy {
|
||||||
points.zipWithNext().map {
|
points.zipWithNext().map {
|
||||||
|
|||||||
@@ -3,10 +3,19 @@ import org.openrndr.shape.Circle
|
|||||||
import org.openrndr.shape.Ellipse
|
import org.openrndr.shape.Ellipse
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class TestRectifiedContour {
|
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
|
@Test
|
||||||
fun testInverse() {
|
fun testInverse() {
|
||||||
val c = Ellipse(40.0, 40.0, 40.0, 80.0).contour.sub(0.0, 0.333)
|
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)
|
val ri = r.inverseRectify(rt)
|
||||||
|
|
||||||
assertTrue(abs(ri-0.125) < 1E-5)
|
assertTrue(abs(ri-0.125) < 1E-5)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user