Skip to content

Commit

Permalink
Fixed #37: Added syntax rect.toPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 20, 2023
1 parent 565542e commit d8546d2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package roguelikestarterkit

import indigo.shared.collections.Batch
import indigo.shared.datatypes.Point
import indigo.shared.datatypes.Rectangle

object syntax:

extension (r: Rectangle)
def toPoints: Batch[Point] =
Batch.fromIndexedSeq(
(0 until r.height).flatMap { y =>
(0 until r.width).map { x =>
Point(r.x + x, r.y + y)
}
}
)

end syntax

// Terminal

type TerminalEmulator = terminal.TerminalEmulator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package roguelikestarterkit.starterkit

import indigo.*
import roguelikestarterkit.syntax.toPoints

class SyntaxTests extends munit.FunSuite {

test("Can convert a rectangle to a grid of points") {
val actual = Rectangle(0,0,4,3).toPoints

val expected =
Batch(
Point(0, 0),
Point(1, 0),
Point(2, 0),
Point(3, 0),
Point(0, 1),
Point(1, 1),
Point(2, 1),
Point(3, 1),
Point(0, 2),
Point(1, 2),
Point(2, 2),
Point(3, 2),
)

assertEquals(actual, expected)
}

test("Can convert a offset rectangle to a grid of points") {
val actual = Rectangle(10,20,4,3).toPoints

val expected =
Batch(
Point(10 + 0, 20 + 0),
Point(10 + 1, 20 + 0),
Point(10 + 2, 20 + 0),
Point(10 + 3, 20 + 0),
Point(10 + 0, 20 + 1),
Point(10 + 1, 20 + 1),
Point(10 + 2, 20 + 1),
Point(10 + 3, 20 + 1),
Point(10 + 0, 20 + 2),
Point(10 + 1, 20 + 2),
Point(10 + 2, 20 + 2),
Point(10 + 3, 20 + 2),
)

assertEquals(actual, expected)
}

}

0 comments on commit d8546d2

Please sign in to comment.