Skip to content

Commit

Permalink
Sanitize Size/Point.random values
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 12, 2024
1 parent ab36f72 commit ba1d3d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions indigo/indigo/src/main/scala/indigo/shared/datatypes/Point.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,16 @@ object Point:
)

def random(dice: Dice, max: Int): Point =
Point(dice.rollFromZero(max), dice.rollFromZero(max))
Point(
if max <= 0 then 0 else dice.rollFromZero(max),
if max <= 0 then 0 else dice.rollFromZero(max)
)

def random(dice: Dice, max: Point): Point =
Point(dice.rollFromZero(max.x), dice.rollFromZero(max.y))
Point(
if max.x <= 0 then 0 else dice.rollFromZero(max.x),
if max.y <= 0 then 0 else dice.rollFromZero(max.y)
)

def random(dice: Dice, min: Int, max: Int): Point =
Point(dice.rollFromZero(max - min) + min, dice.rollFromZero(max - min) + min)
Expand Down
10 changes: 8 additions & 2 deletions indigo/indigo/src/main/scala/indigo/shared/datatypes/Size.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,16 @@ object Size:
)

def random(dice: Dice, max: Int): Size =
Size(dice.rollFromZero(max), dice.rollFromZero(max))
Size(
if max <= 0 then 0 else dice.rollFromZero(max),
if max <= 0 then 0 else dice.rollFromZero(max)
)

def random(dice: Dice, max: Size): Size =
Size(dice.rollFromZero(max.width), dice.rollFromZero(max.height))
Size(
if max.width <= 0 then 0 else dice.rollFromZero(max.width),
if max.height <= 0 then 0 else dice.rollFromZero(max.height)
)

def random(dice: Dice, min: Int, max: Int): Size =
Size(dice.rollFromZero(max - min) + min, dice.rollFromZero(max - min) + min)
Expand Down

0 comments on commit ba1d3d7

Please sign in to comment.