Skip to content

Commit

Permalink
[orx-shapes] Add linear operator and contour conversion to bezierpatch
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Oct 24, 2020
1 parent 16b7f0e commit b41ba5f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions orx-shapes/src/main/kotlin/BezierPatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ class BezierPatch(val points: List<List<Vector2>>) {
val f0 = List(4) { MutableList(3) { Vector2.ZERO } }
for (j in 0 until 4) {
for (i in 0 until 3) {
f0[j][i] = points[j][i+1] - points[j][i]
f0[j][i] = points[j][i + 1] - points[j][i]
}
}

val f1 = List(3) { MutableList(3) { Vector2.ZERO } }
for (j in 0 until 3) {
for (i in 0 until 3) {
f1[j][i] = f0[j+1][i] - f0[j][i]
f1[j][i] = f0[j + 1][i] - f0[j][i]
}
}

Expand Down Expand Up @@ -138,8 +138,26 @@ class BezierPatch(val points: List<List<Vector2>>) {

return bezierPatch(d0, d1, d2, d3).transposed
}

val contour: ShapeContour = ShapeContour(
listOf(
Segment(points[0][0], points[0][1], points[0][2], points[0][3]),
Segment(points[0][3], points[1][3], points[2][3], points[3][3]),
Segment(points[3][3], points[3][2], points[3][1], points[3][0]),
Segment(points[3][0], points[2][0], points[1][0], points[0][0]),
), true)

operator fun times(scale: Double) = BezierPatch(points.map { j -> j.map { i -> i * scale } })
operator fun div(scale: Double) = BezierPatch(points.map { j -> j.map { i -> i / scale } })
operator fun plus(right: BezierPatch) =
BezierPatch(List(4) { j -> List(4) { i -> points[j][i] + right.points[j][i] } })

operator fun minus(right: BezierPatch) =
BezierPatch(List(4) { j -> List(4) { i -> points[j][i] - right.points[j][i] } })

}


/**
* Create a cubic bezier patch from 4 segments. The control points of the segments are used in row-wise fashion
*/
Expand Down

0 comments on commit b41ba5f

Please sign in to comment.