-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #525 from baaahs/grid-swap-and-stagger
Grid swap and stagger
- Loading branch information
Showing
35 changed files
with
557 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/commonMain/kotlin/baaahs/show/migration/scene/AllSceneMigrations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package baaahs.show.migration.scene | ||
|
||
import baaahs.show.DataMigrator | ||
|
||
val AllSceneMigrations: List<DataMigrator.Migration> = listOf( | ||
V1_GridDirectionBackwards | ||
) |
38 changes: 38 additions & 0 deletions
38
src/commonMain/kotlin/baaahs/show/migration/scene/V1_GridDirectionBackwards.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package baaahs.show.migration.scene | ||
|
||
import baaahs.show.DataMigrator | ||
import baaahs.show.migration.* | ||
import kotlinx.serialization.json.* | ||
|
||
/** | ||
* Grid directions were backwards. | ||
*/ | ||
@Suppress("ClassName") | ||
object V1_GridDirectionBackwards : DataMigrator.Migration(1) { | ||
override fun migrate(from: JsonObject): JsonObject { | ||
return from.edit { | ||
replaceJsonObj("model") { model -> | ||
model.jsonObject.edit { | ||
mapObjsInArray("entities") { entity -> | ||
entity.apply { | ||
if (this.type == "Grid") { | ||
// Grid's direction was backwards | ||
val wrongDirection = this["direction"]?.jsonPrimitive?.contentOrNull | ||
?: "ColumnsThenRows" | ||
when(wrongDirection) { | ||
"RowsThenColumns" -> this["direction"] = JsonPrimitive("ColumnsThenRows") | ||
"ColumnsThenRows" -> this.remove("direction") | ||
else -> error("Unknown direction \"$wrongDirection\".") | ||
} | ||
|
||
// Grid's zigzag might as well default to true. | ||
val oldZigZag = this.remove("zigZag")?.jsonPrimitive?.booleanOrNull ?: false | ||
if (!oldZigZag) this["zigZag"] = JsonPrimitive(false) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package baaahs.model | ||
|
||
import baaahs.describe | ||
import baaahs.geom.Vector3F | ||
import baaahs.gl.override | ||
import baaahs.model.PolyLine.Segment | ||
import ch.tutteli.atrium.api.fluent.en_GB.containsExactly | ||
import ch.tutteli.atrium.api.verbs.expect | ||
import org.spekframework.spek2.Spek | ||
|
||
object GridSpec : Spek({ | ||
describe<Grid> { | ||
val grid by value { | ||
Grid( | ||
"grid", | ||
columns = 4, rows = 5, columnGap = 1f, rowGap = 1f, | ||
direction = GridData.Direction.RowsThenColumns, | ||
zigZag = true | ||
) | ||
} | ||
|
||
it("calculates segments") { | ||
expect(grid.segments).containsExactly( | ||
Segment(Vector3F(0.0, 0.0, 0.0), Vector3F(3.0, 0.0, 0.0), 4), | ||
Segment(Vector3F(3.0, 1.0, 0.0), Vector3F(0.0, 1.0, 0.0), 4), | ||
Segment(Vector3F(0.0, 2.0, 0.0), Vector3F(3.0, 2.0, 0.0), 4), | ||
Segment(Vector3F(3.0, 3.0, 0.0), Vector3F(0.0, 3.0, 0.0), 4), | ||
Segment(Vector3F(0.0, 4.0, 0.0), Vector3F(3.0, 4.0, 0.0), 4) | ||
) | ||
} | ||
|
||
context("with stagger") { | ||
override(grid) { | ||
Grid( | ||
"grid", | ||
columns = 4, rows = 5, columnGap = 1f, rowGap = 1f, | ||
direction = GridData.Direction.RowsThenColumns, | ||
zigZag = true, stagger = 2 | ||
) | ||
} | ||
|
||
it("calculates segments with stagger") { | ||
expect(grid.segments).containsExactly( | ||
Segment(Vector3F(0.0, 0.0, 0.0), Vector3F(3.0, 0.0, 0.0), 4), | ||
Segment(Vector3F(3.5, 1.0, 0.0), Vector3F(0.5, 1.0, 0.0), 4), | ||
Segment(Vector3F(0.0, 2.0, 0.0), Vector3F(3.0, 2.0, 0.0), 4), | ||
Segment(Vector3F(3.5, 3.0, 0.0), Vector3F(0.5, 3.0, 0.0), 4), | ||
Segment(Vector3F(0.0, 4.0, 0.0), Vector3F(3.0, 4.0, 0.0), 4) | ||
) | ||
} | ||
} | ||
} | ||
}) |
Oops, something went wrong.