Skip to content

Commit

Permalink
feature: More grid position generator API (#10)
Browse files Browse the repository at this point in the history
- Makes GridPositionGenerator implement Iterable
- Adds a utility constructor to create a GridBoxGenerator from 4 ints
  • Loading branch information
kezz committed Aug 14, 2024
1 parent efce601 commit 12dadbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public data class GridBoxGenerator(
private val max: GridPoint
) : GridPositionGenerator {

public constructor(x1: Int, y1: Int, x2: Int, y2: Int) : this(GridPoint(x1, y1), GridPoint(x2, y2))

override fun iterator(): Iterator<GridPoint> =
(min..max).iterator()

override fun generate(): List<GridPoint> =
(min..max).toList()
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.noxcrew.interfaces.grid

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

/** Returns a list of [GridPoint]'s. */
public fun generate(): List<GridPoint>

override fun iterator(): Iterator<GridPoint> {
return generate().iterator()
}
}

0 comments on commit 12dadbc

Please sign in to comment.