Skip to content

Commit

Permalink
Fixed PurpleKingdomGames#640: Rectangle + BB have resizeBy
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 26, 2023
1 parent a3f6bcd commit 7c65d7e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ final case class Rectangle(position: Point, size: Size) derives CanEqual:
this.copy(size = newSize)
def resize(x: Int, y: Int): Rectangle =
resize(Size(x, y))
def resize(value: Int): Rectangle =
resize(Size(value))

def resizeBy(amount: Size): Rectangle =
this.copy(size = size + amount)
def resizeBy(x: Int, y: Int): Rectangle =
resizeBy(Size(x, y))
def resizeBy(amount: Int): Rectangle =
resizeBy(Size(amount))

def withPosition(point: Point): Rectangle =
moveTo(point)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ final case class BoundingBox(position: Vertex, size: Vertex) derives CanEqual:
this.copy(size = newSize)
def resize(newSize: Vector2): BoundingBox =
resize(Vertex.fromVector2(newSize))
def resize(x: Double, y: Double): BoundingBox =
resize(Vertex(x, y))
def resize(value: Double): BoundingBox =
resize(Vertex(value))

def resizeBy(amount: Vertex): BoundingBox =
this.copy(size = size + amount)
def resizeBy(amount: Vector2): BoundingBox =
resizeBy(Vertex.fromVector2(amount))
def resizeBy(x: Int, y: Int): BoundingBox =
resizeBy(Vertex(x, y))
def resizeBy(amount: Int): BoundingBox =
resizeBy(Vertex(amount))

@deprecated("Please use `toIncircle`, or alternatively `toCircumcircle`.")
def toCircle: Circle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,16 @@ class RectangleTests extends munit.FunSuite {
assert(a.top == -20)
assert(a.bottom == 20)
}

test("resize") {
assertEquals(Rectangle(10, 10, 10, 10).resize(Size(20, 20)), Rectangle(10, 10, 20, 20))
assertEquals(Rectangle(10, 10, 10, 10).resize(20, 20), Rectangle(10, 10, 20, 20))
assertEquals(Rectangle(10, 10, 10, 10).resize(20), Rectangle(10, 10, 20, 20))
}

test("resizeBy") {
assertEquals(Rectangle(10, 10, 10, 10).resizeBy(Size(20, 20)), Rectangle(10, 10, 30, 30))
assertEquals(Rectangle(10, 10, 10, 10).resizeBy(20, 20), Rectangle(10, 10, 30, 30))
assertEquals(Rectangle(10, 10, 10, 10).resizeBy(20), Rectangle(10, 10, 30, 30))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,18 @@ class BoundingBoxTests extends munit.FunSuite {

}

test("resize") {
assertEquals(BoundingBox(10, 10, 10, 10).resize(Vertex(20, 20)), BoundingBox(10, 10, 20, 20))
assertEquals(BoundingBox(10, 10, 10, 10).resize(Vector2(20, 20)), BoundingBox(10, 10, 20, 20))
assertEquals(BoundingBox(10, 10, 10, 10).resize(20, 20), BoundingBox(10, 10, 20, 20))
assertEquals(BoundingBox(10, 10, 10, 10).resize(20), BoundingBox(10, 10, 20, 20))
}

test("resizeBy") {
assertEquals(BoundingBox(10, 10, 10, 10).resizeBy(Vertex(20, 20)), BoundingBox(10, 10, 30, 30))
assertEquals(BoundingBox(10, 10, 10, 10).resizeBy(Vector2(20, 20)), BoundingBox(10, 10, 30, 30))
assertEquals(BoundingBox(10, 10, 10, 10).resizeBy(20, 20), BoundingBox(10, 10, 30, 30))
assertEquals(BoundingBox(10, 10, 10, 10).resizeBy(20), BoundingBox(10, 10, 30, 30))
}

}

0 comments on commit 7c65d7e

Please sign in to comment.