Skip to content

Commit 12dadbc

Browse files
authored
feature: More grid position generator API (#10)
- Makes GridPositionGenerator implement Iterable - Adds a utility constructor to create a GridBoxGenerator from 4 ints
1 parent efce601 commit 12dadbc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

interfaces/src/main/kotlin/com/noxcrew/interfaces/grid/GridBoxGenerator.kt

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public data class GridBoxGenerator(
99
private val max: GridPoint
1010
) : GridPositionGenerator {
1111

12+
public constructor(x1: Int, y1: Int, x2: Int, y2: Int) : this(GridPoint(x1, y1), GridPoint(x2, y2))
13+
14+
override fun iterator(): Iterator<GridPoint> =
15+
(min..max).iterator()
16+
1217
override fun generate(): List<GridPoint> =
1318
(min..max).toList()
1419
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.noxcrew.interfaces.grid
22

33
/** Generates a set of [GridPoint]'s. */
4-
public fun interface GridPositionGenerator {
4+
public fun interface GridPositionGenerator : Iterable<GridPoint> {
55

66
/** Returns a list of [GridPoint]'s. */
77
public fun generate(): List<GridPoint>
8+
9+
override fun iterator(): Iterator<GridPoint> {
10+
return generate().iterator()
11+
}
812
}

0 commit comments

Comments
 (0)