Update for OPENRNDR segment and path generalizations

This commit is contained in:
Edwin Jakobs
2024-03-19 16:31:45 +01:00
parent 8fe7631570
commit af6d35c59b
37 changed files with 579 additions and 277 deletions

View File

@@ -0,0 +1,37 @@
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
*/
class Path3DBlend(val a: RectifiedPath3D, val b: RectifiedPath3D) {
fun mix(blendFunction: (Double) -> Double): Path3D {
return a.mix(b, blendFunction)
}
fun mix(blend: Double): Path3D {
return a.mix(b) { blend }
}
}
/**
* Create a [ContourBlend] for contours [a] and [b]
*
* Finding the pose that minimizes the error between [a] and [b] is not part of this function's work.
*
*/
fun Path3DBlend(a: Path3D, b: Path3D): Path3DBlend {
val ra = a.rectified()
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}"
}
return Path3DBlend(sa, sb)
}