Change to use float rect
This commit is contained in:
parent
965e2b06cc
commit
2f21a19443
1 changed files with 26 additions and 9 deletions
|
@ -1393,22 +1393,39 @@ proc scaleMat*(scale: float): Mat4 =
|
||||||
|
|
||||||
|
|
||||||
type Rect* = object
|
type Rect* = object
|
||||||
x*: int
|
x*: float64
|
||||||
y*: int
|
y*: float64
|
||||||
w*: int
|
w*: float64
|
||||||
h*: int
|
h*: float64
|
||||||
|
|
||||||
|
proc rect*(x, y, w, h: float64): Rect =
|
||||||
proc rect*(x, y, w, h:int): Rect =
|
|
||||||
result.x = x
|
result.x = x
|
||||||
result.y = y
|
result.y = y
|
||||||
result.w = w
|
result.w = w
|
||||||
result.h = h
|
result.h = h
|
||||||
|
|
||||||
|
proc rect*(pos, size: Vec2): Rect =
|
||||||
|
result.x = pos.x
|
||||||
|
result.y = pos.y
|
||||||
|
result.w = size.x
|
||||||
|
result.h = size.y
|
||||||
|
|
||||||
|
proc xy*(rect: Rect): Vec2 =
|
||||||
|
## Gets the xy as a vec2
|
||||||
|
vec2(rect.x, rect.y)
|
||||||
|
|
||||||
|
proc wh*(rect: Rect): Vec2 =
|
||||||
|
## Gets the wh as a vec2
|
||||||
|
vec2(rect.w, rect.h)
|
||||||
|
|
||||||
|
proc intersects*(rect: Rect, pos: Vec2): bool =
|
||||||
|
## Checks if point is inside the rectangle
|
||||||
|
(rect.x <= pos.x and pos.x <= rect.x + rect.w) and (
|
||||||
|
rect.y <= pos.y and pos.y <= rect.y + rect.h)
|
||||||
|
|
||||||
proc `$`*(a: Rect): string =
|
proc `$`*(a: Rect): string =
|
||||||
return "(" &
|
return "(" &
|
||||||
$a.x & ", " &
|
$a.x & ", " &
|
||||||
$a.y & "x " &
|
$a.y & ": " &
|
||||||
$a.w & ", " &
|
$a.w & " x " &
|
||||||
$a.h & ")"
|
$a.h & ")"
|
||||||
|
|
Loading…
Reference in a new issue