Skip to content

Commit

Permalink
[orx-shapes] Adapt to changes made to Segment.control
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Jan 14, 2024
1 parent bec51b9 commit 590a2b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
17 changes: 9 additions & 8 deletions orx-shapes/src/commonMain/kotlin/adjust/ContourEdge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ data class ContourEdge(
*/
fun toLinear(): ContourEdge {
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
.update(segmentIndex to newSegment)

Expand Down Expand Up @@ -217,7 +217,7 @@ data class ContourEdge(
val segment = contour.segments[segmentIndex]
val newSegment = segment.copy(
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)
)
val segmentInIndex = if (contour.closed) (segmentIndex - 1).mod(contour.segments.size) else segmentIndex - 1
Expand All @@ -228,26 +228,27 @@ data class ContourEdge(
val newSegments = contour.segments.map { it }.toMutableList()

if (refIn != null) {
val control = if (refIn.linear || !updateTangents) {
var control = if (refIn.linear || !updateTangents) {
refIn.control
} else {
refIn.cubic.control
}
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) {
val control = if (refOut.linear || !updateTangents) {
var control = if (refOut.linear || !updateTangents) {
refOut.control
} else {
refOut.cubic.control
}
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
Expand Down
10 changes: 5 additions & 5 deletions orx-shapes/src/commonMain/kotlin/adjust/ContourVertex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ data class ContourVertex(
contour.segments.getOrNull(segmentIndex - 1)
newSegments[segmentIndex] = run {
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)
}
val segmentIndexIn = (segmentIndex - 1).mod(contour.segments.size)
if (refIn != null) {
newSegments[segmentIndexIn] = run {
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)
}
}
Expand Down Expand Up @@ -166,15 +166,15 @@ data class ContourVertex(
if (contour.closed || segmentIndex< contour.segments.size) {
newSegments[segmentIndex] = if (updateTangents && !refOut.linear) {
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)
} else {
newSegments[segmentIndex].copy(start = newPosition)
}
} else {
newSegments[segmentIndex-1] = if (updateTangents && !refOut.linear) {
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)
} else {
newSegments[segmentIndex-1].copy(end = newPosition)
Expand All @@ -186,7 +186,7 @@ data class ContourVertex(
newSegments[segmentIndexIn] =
if (updateTangents && !refIn.linear) {
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)
} else {

Expand Down
4 changes: 2 additions & 2 deletions orx-shapes/src/commonMain/kotlin/offset/Offset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ fun Segment.scale(polarity: YPolarity, scale: (Double) -> Double): Segment {
val nd = d.normalized * s
it + rc * nd
}
return copy(newStart, newControls.toTypedArray(), newEnd)
return copy(newStart, newControls, newEnd)
} else {
val newControls = control.mapIndexed { index, it ->
val rc = scale((index + 1.0) / 3.0)
it + rc * normal((index + 1.0), polarity)
}
return copy(newStart, newControls.toTypedArray(), newEnd)
return copy(newStart, newControls, newEnd)
}
}

Expand Down

0 comments on commit 590a2b3

Please sign in to comment.