[orx-shapes] Adapt to changes made to Segment.control
This commit is contained in:
@@ -54,7 +54,7 @@ data class ContourEdge(
|
|||||||
*/
|
*/
|
||||||
fun toLinear(): ContourEdge {
|
fun toLinear(): ContourEdge {
|
||||||
return if (contour.segments[segmentIndex].type != SegmentType.LINEAR) {
|
return if (contour.segments[segmentIndex].type != SegmentType.LINEAR) {
|
||||||
val newSegment = contour.segments[segmentIndex].copy(control = emptyArray())
|
val newSegment = contour.segments[segmentIndex].copy(control = emptyList())
|
||||||
val newSegments = contour.segments
|
val newSegments = contour.segments
|
||||||
.update(segmentIndex to newSegment)
|
.update(segmentIndex to newSegment)
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ data class ContourEdge(
|
|||||||
val segment = contour.segments[segmentIndex]
|
val segment = contour.segments[segmentIndex]
|
||||||
val newSegment = segment.copy(
|
val newSegment = segment.copy(
|
||||||
start = segment.start.transformedBy(transform),
|
start = segment.start.transformedBy(transform),
|
||||||
control = segment.control.map { it.transformedBy(transform) }.toTypedArray<Vector2>(),
|
control = segment.control.map { it.transformedBy(transform) },
|
||||||
end = segment.end.transformedBy(transform)
|
end = segment.end.transformedBy(transform)
|
||||||
)
|
)
|
||||||
val segmentInIndex = if (contour.closed) (segmentIndex - 1).mod(contour.segments.size) else segmentIndex - 1
|
val segmentInIndex = if (contour.closed) (segmentIndex - 1).mod(contour.segments.size) else segmentIndex - 1
|
||||||
@@ -228,26 +228,27 @@ data class ContourEdge(
|
|||||||
val newSegments = contour.segments.map { it }.toMutableList()
|
val newSegments = contour.segments.map { it }.toMutableList()
|
||||||
|
|
||||||
if (refIn != null) {
|
if (refIn != null) {
|
||||||
val control = if (refIn.linear || !updateTangents) {
|
var control = if (refIn.linear || !updateTangents) {
|
||||||
refIn.control
|
refIn.control
|
||||||
} else {
|
} else {
|
||||||
refIn.cubic.control
|
refIn.cubic.control
|
||||||
}
|
}
|
||||||
if (control.isNotEmpty()) {
|
if (control.isNotEmpty()) {
|
||||||
control[1] = control[1].transformedBy(transform)
|
control = listOf(control[0], control[1].transformedBy(transform))
|
||||||
}
|
}
|
||||||
newSegments[segmentInIndex] = refIn.copy(end = segment.start.transformedBy(transform))
|
newSegments[segmentInIndex] = refIn.copy(control = control, end = segment.start.transformedBy(transform))
|
||||||
}
|
}
|
||||||
if (refOut != null) {
|
if (refOut != null) {
|
||||||
val control = if (refOut.linear || !updateTangents) {
|
var control = if (refOut.linear || !updateTangents) {
|
||||||
refOut.control
|
refOut.control
|
||||||
} else {
|
} else {
|
||||||
refOut.cubic.control
|
refOut.cubic.control
|
||||||
}
|
}
|
||||||
if (control.isNotEmpty()) {
|
if (control.isNotEmpty()) {
|
||||||
control[0] = control[0].transformedBy(transform)
|
control = listOf(control[0].transformedBy(transform), control[1])
|
||||||
|
|
||||||
}
|
}
|
||||||
newSegments[segmentOutIndex] = refOut.copy(start = segment.end.transformedBy(transform))
|
newSegments[segmentOutIndex] = refOut.copy(start = segment.end.transformedBy(transform), control = control)
|
||||||
}
|
}
|
||||||
|
|
||||||
newSegments[segmentIndex] = newSegment
|
newSegments[segmentIndex] = newSegment
|
||||||
|
|||||||
@@ -101,14 +101,14 @@ data class ContourVertex(
|
|||||||
contour.segments.getOrNull(segmentIndex - 1)
|
contour.segments.getOrNull(segmentIndex - 1)
|
||||||
newSegments[segmentIndex] = run {
|
newSegments[segmentIndex] = run {
|
||||||
val cubicSegment = refOut.cubic
|
val cubicSegment = refOut.cubic
|
||||||
val newControls = arrayOf((transformOut * cubicSegment.control[0].xy01).xy, cubicSegment.control[1])
|
val newControls = listOf((transformOut * cubicSegment.control[0].xy01).xy, cubicSegment.control[1])
|
||||||
refOut.copy(control = newControls)
|
refOut.copy(control = newControls)
|
||||||
}
|
}
|
||||||
val segmentIndexIn = (segmentIndex - 1).mod(contour.segments.size)
|
val segmentIndexIn = (segmentIndex - 1).mod(contour.segments.size)
|
||||||
if (refIn != null) {
|
if (refIn != null) {
|
||||||
newSegments[segmentIndexIn] = run {
|
newSegments[segmentIndexIn] = run {
|
||||||
val cubicSegment = refIn.cubic
|
val cubicSegment = refIn.cubic
|
||||||
val newControls = arrayOf(cubicSegment.control[0], (transformIn * cubicSegment.control[1].xy01).xy)
|
val newControls = listOf(cubicSegment.control[0], (transformIn * cubicSegment.control[1].xy01).xy)
|
||||||
refIn.copy(control = newControls)
|
refIn.copy(control = newControls)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ data class ContourVertex(
|
|||||||
if (contour.closed || segmentIndex< contour.segments.size) {
|
if (contour.closed || segmentIndex< contour.segments.size) {
|
||||||
newSegments[segmentIndex] = if (updateTangents && !refOut.linear) {
|
newSegments[segmentIndex] = if (updateTangents && !refOut.linear) {
|
||||||
val cubicSegment = refOut.cubic
|
val cubicSegment = refOut.cubic
|
||||||
val newControls = arrayOf(transform(cubicSegment.control[0]), cubicSegment.control[1])
|
val newControls = listOf(transform(cubicSegment.control[0]), cubicSegment.control[1])
|
||||||
refOut.copy(start = newPosition, control = newControls)
|
refOut.copy(start = newPosition, control = newControls)
|
||||||
} else {
|
} else {
|
||||||
newSegments[segmentIndex].copy(start = newPosition)
|
newSegments[segmentIndex].copy(start = newPosition)
|
||||||
@@ -174,7 +174,7 @@ data class ContourVertex(
|
|||||||
} else {
|
} else {
|
||||||
newSegments[segmentIndex-1] = if (updateTangents && !refOut.linear) {
|
newSegments[segmentIndex-1] = if (updateTangents && !refOut.linear) {
|
||||||
val cubicSegment = refOut.cubic
|
val cubicSegment = refOut.cubic
|
||||||
val newControls = arrayOf(cubicSegment.control[0], transform(cubicSegment.control[1]))
|
val newControls = listOf(cubicSegment.control[0], transform(cubicSegment.control[1]))
|
||||||
refOut.copy(end = newPosition, control = newControls)
|
refOut.copy(end = newPosition, control = newControls)
|
||||||
} else {
|
} else {
|
||||||
newSegments[segmentIndex-1].copy(end = newPosition)
|
newSegments[segmentIndex-1].copy(end = newPosition)
|
||||||
@@ -186,7 +186,7 @@ data class ContourVertex(
|
|||||||
newSegments[segmentIndexIn] =
|
newSegments[segmentIndexIn] =
|
||||||
if (updateTangents && !refIn.linear) {
|
if (updateTangents && !refIn.linear) {
|
||||||
val cubicSegment = refIn.cubic
|
val cubicSegment = refIn.cubic
|
||||||
val newControls = arrayOf(cubicSegment.control[0], transform(cubicSegment.control[1]))
|
val newControls = listOf(cubicSegment.control[0], transform(cubicSegment.control[1]))
|
||||||
newSegments[segmentIndexIn].copy(control = newControls, end = newPosition)
|
newSegments[segmentIndexIn].copy(control = newControls, end = newPosition)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|||||||
@@ -101,13 +101,13 @@ fun Segment.scale(polarity: YPolarity, scale: (Double) -> Double): Segment {
|
|||||||
val nd = d.normalized * s
|
val nd = d.normalized * s
|
||||||
it + rc * nd
|
it + rc * nd
|
||||||
}
|
}
|
||||||
return copy(newStart, newControls.toTypedArray(), newEnd)
|
return copy(newStart, newControls, newEnd)
|
||||||
} else {
|
} else {
|
||||||
val newControls = control.mapIndexed { index, it ->
|
val newControls = control.mapIndexed { index, it ->
|
||||||
val rc = scale((index + 1.0) / 3.0)
|
val rc = scale((index + 1.0) / 3.0)
|
||||||
it + rc * normal((index + 1.0), polarity)
|
it + rc * normal((index + 1.0), polarity)
|
||||||
}
|
}
|
||||||
return copy(newStart, newControls.toTypedArray(), newEnd)
|
return copy(newStart, newControls, newEnd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user