[orx-shapes] Improve contour adjuster framework

This commit is contained in:
Edwin Jakobs
2024-01-22 15:22:20 +01:00
parent 0e8ca543ab
commit 44824e3d21
23 changed files with 498 additions and 15 deletions

View File

@@ -58,6 +58,7 @@ fun Segment.withTunniPoint(tunniPoint: Vector2): Segment {
* @since orx 0.4.5
*/
fun Segment.withTunniLine(pointOnLine: Vector2): Segment {
println("hoi! $pointOnLine")
val ls = LineSegment(pointOnLine, pointOnLine + this.cubic.control[0] - this.cubic.control[1])
val ac0 = LineSegment(start, this.cubic.control[0])
val bc1 = LineSegment(end, this.cubic.control[1])
@@ -66,6 +67,10 @@ fun Segment.withTunniLine(pointOnLine: Vector2): Segment {
val cp1 = intersection(ls, bc1, Double.POSITIVE_INFINITY)
return if (cp0 != Vector2.INFINITY && cp1 != Vector2.INFINITY) {
println("$cp0 $cp1")
copy(start, listOf(cp0, cp1), end)
} else this
} else {
println("${cp0} ${cp1}")
this
}
}

View File

@@ -44,7 +44,7 @@ fun ContourEdge.withTunniLine(pointOnLine: Vector2): ContourEdge {
if (contour.empty) {
return withoutAdjustments()
} else {
val segment = contour.segments[segmentIndex].withTunniPoint(pointOnLine)
val segment = contour.segments[segmentIndex].withTunniLine(pointOnLine)
val newSegments = contour.segments.map { it }.toMutableList()
newSegments[segmentIndex] = segment
return ContourEdge(ShapeContour.fromSegments(newSegments, contour.closed), segmentIndex)