-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 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
35 changes: 35 additions & 0 deletions
35
gartwork/src/main/kotlin/dev/oblac/gart/gfx/PointsTrail.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,35 @@ | ||
package dev.oblac.gart.gfx | ||
|
||
import dev.oblac.gart.skia.Point | ||
|
||
/** | ||
* Just a queue of points. | ||
*/ | ||
class PointsTrail(val size: Int) { | ||
private val points = ArrayDeque<Point>(size) | ||
|
||
/** | ||
* Adds a point to the trail. | ||
*/ | ||
fun add(p: Point) { | ||
if (points.size == size) { | ||
points.removeFirst() | ||
} | ||
points.add(p) | ||
} | ||
|
||
/** | ||
* Iterates over the points in the trail. | ||
*/ | ||
fun forEach(action: (Point) -> Unit) { | ||
points.forEach(action) | ||
} | ||
|
||
/** | ||
* Iterates over the points in the trail in reverse order. | ||
*/ | ||
fun forEachReverse(action: (Point) -> Unit) { | ||
points.asReversed().forEach(action) | ||
} | ||
|
||
} |
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
14 changes: 14 additions & 0 deletions
14
gartwork/src/test/kotlin/dev/oblac/gart/gfx/PalettesTest.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,14 @@ | ||
package dev.oblac.gart.gfx | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class PalettesTest { | ||
|
||
@Test | ||
fun testPaletteToGradient() { | ||
val p = Palettes.cool27 | ||
val g = Palettes.gradient(p, 256) | ||
assertEquals(256, g.size) | ||
} | ||
} |