diff --git a/orx-shapes/src/commonMain/kotlin/blend/ContourBlend.kt b/orx-shapes/src/commonMain/kotlin/blend/ContourBlend.kt index 1dc96b23..99af32b3 100644 --- a/orx-shapes/src/commonMain/kotlin/blend/ContourBlend.kt +++ b/orx-shapes/src/commonMain/kotlin/blend/ContourBlend.kt @@ -28,8 +28,8 @@ fun ContourBlend(a: ShapeContour, b: ShapeContour): ContourBlend { val rb = b.rectified() val sa = ra.splitForBlend(rb) val sb = rb.splitForBlend(ra) - require(sa.path.segments.size == sb.path.segments.size) { - "preprocessing for contours failed to produce equal number of segments. ${sa.path.segments.size}, ${sb.path.segments.size}" + require(sa.originalPath.segments.size == sb.originalPath.segments.size) { + "preprocessing for contours failed to produce equal number of segments. ${sa.originalPath.segments.size}, ${sb.originalPath.segments.size}" } return ContourBlend(sa, sb) } \ No newline at end of file diff --git a/orx-shapes/src/commonMain/kotlin/blend/Path3DBlend.kt b/orx-shapes/src/commonMain/kotlin/blend/Path3DBlend.kt index c541d8dc..2efb36c8 100644 --- a/orx-shapes/src/commonMain/kotlin/blend/Path3DBlend.kt +++ b/orx-shapes/src/commonMain/kotlin/blend/Path3DBlend.kt @@ -1,10 +1,8 @@ package org.openrndr.extra.shapes.blend -import org.openrndr.extra.shapes.rectify.RectifiedContour import org.openrndr.extra.shapes.rectify.RectifiedPath3D import org.openrndr.extra.shapes.rectify.rectified import org.openrndr.shape.Path3D -import org.openrndr.shape.ShapeContour /** * ContourBlend holds two rectified contours with an equal amount of segments @@ -30,8 +28,8 @@ fun Path3DBlend(a: Path3D, b: Path3D): Path3DBlend { val rb = b.rectified() val sa = ra.splitForBlend(rb) val sb = rb.splitForBlend(ra) - require(sa.path.segments.size == sb.path.segments.size) { - "preprocessing for contours failed to produce equal number of segments. ${sa.path.segments.size}, ${sb.path.segments.size}" + require(sa.originalPath.segments.size == sb.originalPath.segments.size) { + "preprocessing for contours failed to produce equal number of segments. ${sa.originalPath.segments.size}, ${sb.originalPath.segments.size}" } return Path3DBlend(sa, sb) } \ No newline at end of file diff --git a/orx-shapes/src/commonMain/kotlin/blend/RectifiedContourExtensions.kt b/orx-shapes/src/commonMain/kotlin/blend/RectifiedContourExtensions.kt index fc59a1e0..9f0feb69 100644 --- a/orx-shapes/src/commonMain/kotlin/blend/RectifiedContourExtensions.kt +++ b/orx-shapes/src/commonMain/kotlin/blend/RectifiedContourExtensions.kt @@ -10,21 +10,21 @@ import org.openrndr.shape.ShapeContour * Split for blending with [other] */ fun RectifiedContour.splitForBlend(other: RectifiedContour): RectifiedContour { - val ts = (0 until other.path.segments.size + 1).map { it.toDouble() / other.path.segments.size } + val ts = (0 until other.originalPath.segments.size + 1).map { it.toDouble() / other.originalPath.segments.size } val rts = ts.map { other.inverseRectify(it) } - return ShapeContour.fromContours(splitAt(rts), path.closed && other.path.closed).rectified() + return ShapeContour.fromContours(splitAt(rts), originalPath.closed && other.originalPath.closed).rectified() } fun RectifiedContour.mix(other: RectifiedContour, blendFunction: (Double) -> Double): ShapeContour { - val n = this.path.segments.size.toDouble() - val segs = (this.path.segments zip other.path.segments).mapIndexed { index, it -> + val n = this.originalPath.segments.size.toDouble() + val segs = (this.originalPath.segments zip other.originalPath.segments).mapIndexed { index, it -> val t0 = inverseRectify(index / n) val t1 = inverseRectify((index + 1 / 3.0) / n) val t2 = inverseRectify((index + 2 / 3.0) / n) val t3 = inverseRectify((index + 1) / n) (it.first as Segment2D).mix(it.second as Segment2D, blendFunction(t0), blendFunction(t1), blendFunction(t2), blendFunction(t3)) } - return ShapeContour.fromSegments(segs, path.closed && other.path.closed) + return ShapeContour.fromSegments(segs, originalPath.closed && other.originalPath.closed) } diff --git a/orx-shapes/src/commonMain/kotlin/blend/RectifiedPath3DExtensions.kt b/orx-shapes/src/commonMain/kotlin/blend/RectifiedPath3DExtensions.kt index 92723c9b..2c68a409 100644 --- a/orx-shapes/src/commonMain/kotlin/blend/RectifiedPath3DExtensions.kt +++ b/orx-shapes/src/commonMain/kotlin/blend/RectifiedPath3DExtensions.kt @@ -10,21 +10,21 @@ import org.openrndr.shape.Segment3D * Split for blending with [other] */ fun RectifiedPath3D.splitForBlend(other: RectifiedPath3D): RectifiedPath3D { - val ts = (0 until other.path.segments.size + 1).map { it.toDouble() / other.path.segments.size } + val ts = (0 until other.originalPath.segments.size + 1).map { it.toDouble() / other.originalPath.segments.size } val rts = ts.map { other.inverseRectify(it) } - return Path3D.fromPaths(splitAt(rts), path.closed && other.path.closed).rectified() + return Path3D.fromPaths(splitAt(rts), originalPath.closed && other.originalPath.closed).rectified() } fun RectifiedPath3D.mix(other: RectifiedPath3D, blendFunction: (Double) -> Double): Path3D { - val n = this.path.segments.size.toDouble() - val segs = (this.path.segments zip other.path.segments).mapIndexed { index, it -> + val n = this.originalPath.segments.size.toDouble() + val segs = (this.originalPath.segments zip other.originalPath.segments).mapIndexed { index, it -> val t0 = inverseRectify(index / n) val t1 = inverseRectify((index + 1 / 3.0) / n) val t2 = inverseRectify((index + 2 / 3.0) / n) val t3 = inverseRectify((index + 1) / n) (it.first as Segment3D).mix(it.second as Segment3D, blendFunction(t0), blendFunction(t1), blendFunction(t2), blendFunction(t3)) } - return Path3D.fromSegments(segs, path.closed && other.path.closed) + return Path3D.fromSegments(segs, originalPath.closed && other.originalPath.closed) } diff --git a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedContour.kt b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedContour.kt index 9d28f424..0afa6f16 100644 --- a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedContour.kt +++ b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedContour.kt @@ -8,41 +8,41 @@ import kotlin.math.floor class RectifiedContour(contour: ShapeContour, distanceTolerance: Double = 0.5, lengthScale: Double = 1.0) : RectifiedPath(contour, distanceTolerance, lengthScale) { fun velocity(t: Double): Vector2 { - return if (path.empty) { + return if (originalPath.empty) { Vector2.ZERO } else { - val (segment, st) = path.segment(rectify(safe(t))) - path.segments[segment].direction(st) + val (segment, st) = originalPath.segment(rectify(safe(t))) + originalPath.segments[segment].direction(st) } } fun normal(t: Double): Vector2 { - return if (path.empty) { + return if (originalPath.empty) { Vector2.UNIT_Y } else { - (path as ShapeContour).normal(rectify(safe(t))) + (originalPath as ShapeContour).normal(rectify(safe(t))) } } fun pose(t: Double): Matrix44 { - path as ShapeContour - return if (path.empty) { + originalPath as ShapeContour + return if (originalPath.empty) { Matrix44.IDENTITY } else { - path.pose(rectify(safe(t))) + originalPath.pose(rectify(safe(t))) } } override fun sub(t0: Double, t1: Double): ShapeContour { - path as ShapeContour - if (path.empty) { + originalPath as ShapeContour + if (originalPath.empty) { return ShapeContour.EMPTY } - return if (path.closed) { - path.sub(rectify(t0.mod(1.0)) + floor(t0), rectify(t1.mod(1.0)) + floor(t1)) + return if (originalPath.closed) { + originalPath.sub(rectify(t0.mod(1.0)) + floor(t0), rectify(t1.mod(1.0)) + floor(t1)) } else { - path.sub(rectify(t0), rectify(t1)) + originalPath.sub(rectify(t0), rectify(t1)) } } @@ -51,5 +51,5 @@ class RectifiedContour(contour: ShapeContour, distanceTolerance: Double = 0.5, l return super.splitAt(ascendingTs, weldEpsilon) as List } - val contour: ShapeContour get() = path as ShapeContour + val contour: ShapeContour get() = originalPath as ShapeContour } diff --git a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt index d69c8c08..2dfa0ea4 100644 --- a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt +++ b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath.kt @@ -1,6 +1,5 @@ package org.openrndr.extra.shapes.rectify -import org.openrndr.extra.shapes.utilities.splitAt import org.openrndr.extra.shapes.utilities.splitAtBase import org.openrndr.math.EuclideanVector import org.openrndr.math.clamp @@ -11,12 +10,12 @@ import org.openrndr.shape.ShapeContour * RectifiedContour provides an approximately uniform parameterization for [ShapeContour] */ abstract class RectifiedPath>( - open val path: Path, + val originalPath: Path, distanceTolerance: Double = 0.5, lengthScale: Double = 1.0 ) { val points = - path.equidistantPositionsWithT((path.length * lengthScale).toInt().coerceAtLeast(2), distanceTolerance) + originalPath.equidistantPositionsWithT((originalPath.length * lengthScale).toInt().coerceAtLeast(2), distanceTolerance) val intervals by lazy { points.zipWithNext().map { @@ -25,7 +24,7 @@ abstract class RectifiedPath>( } internal fun safe(t: Double): Double { - return if (path.closed) { + return if (originalPath.closed) { t.mod(1.0) } else { t.clamp(0.0, 1.0) @@ -33,10 +32,10 @@ abstract class RectifiedPath>( } /** - * computes a rectified t-value for [path] + * computes a rectified t-value for [originalPath] */ fun rectify(t: Double): Double { - if (path.empty) { + if (originalPath.empty) { return 0.0 } else { if (t <= 0.0) { @@ -56,7 +55,7 @@ abstract class RectifiedPath>( } fun inverseRectify(t: Double): Double { - if (path.empty) { + if (originalPath.empty) { return 0.0 } else { if (t <= 0.0) { @@ -85,18 +84,18 @@ abstract class RectifiedPath>( } fun position(t: Double): T { - return if (path.empty) { - path.infinity + return if (originalPath.empty) { + originalPath.infinity } else { - path.position(rectify(safe(t))) + originalPath.position(rectify(safe(t))) } } fun direction(t: Double): T { - return if (path.empty) { - path.infinity + return if (originalPath.empty) { + originalPath.infinity } else { - path.direction(rectify(safe(t))) + originalPath.direction(rectify(safe(t))) } } @@ -107,6 +106,6 @@ abstract class RectifiedPath>( * @since orx 0.4.4 */ open fun splitAt(ascendingTs: List, weldEpsilon: Double = 1E-6): List> { - return path.splitAtBase(ascendingTs.map { rectify(it) }, weldEpsilon) + return originalPath.splitAtBase(ascendingTs.map { rectify(it) }, weldEpsilon) } } \ No newline at end of file diff --git a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath3D.kt b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath3D.kt index 883e5a31..ac0e1c02 100644 --- a/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath3D.kt +++ b/orx-shapes/src/commonMain/kotlin/rectify/RectifiedPath3D.kt @@ -7,7 +7,7 @@ import kotlin.math.floor class RectifiedPath3D(contour: Path3D, distanceTolerance: Double = 0.5, lengthScale: Double = 1.0) : RectifiedPath(contour, distanceTolerance, lengthScale) { - override val path: Path3D = super.path as Path3D + val path: Path3D get() = originalPath as Path3D override fun sub(t0: Double, t1: Double): Path3D { if (path.empty) { diff --git a/orx-shapes/src/jvmDemo/kotlin/frames/DemoFrames01.kt b/orx-shapes/src/jvmDemo/kotlin/frames/DemoFrames01.kt index 6f832f43..27838baf 100644 --- a/orx-shapes/src/jvmDemo/kotlin/frames/DemoFrames01.kt +++ b/orx-shapes/src/jvmDemo/kotlin/frames/DemoFrames01.kt @@ -1,5 +1,6 @@ package frames +import org.openrndr.WindowMultisample import org.openrndr.application import org.openrndr.color.ColorRGBa import org.openrndr.draw.DrawPrimitive @@ -19,6 +20,7 @@ fun main() { configure { width = 720 height = 720 + multisample = WindowMultisample.SampleCount(4) } program { val random = Random(0)