diff options
-rw-r--r-- | sly/math/rect.scm | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/sly/math/rect.scm b/sly/math/rect.scm index d822891..4e57ea6 100644 --- a/sly/math/rect.scm +++ b/sly/math/rect.scm @@ -52,6 +52,7 @@ rect-inflate rect-union rect-clip + rect-clamp rect-within? rect-intersects? rect-contains?)) @@ -183,6 +184,12 @@ not overlap, a rect of size 0 is returned." (y2 (min (rect-bottom rect1) (rect-bottom rect2)))) (make-rect x1 y1 (max (- x2 x1) 0) (max (- y2 y1) 0)))) +(define rect-clamp + (match-lambda* + ((($ <rect> rx ry width height) ($ <vector2> x y)) + (vector2 (clamp rx (+ rx width) x) + (clamp ry (+ ry height) y))))) + (define (rect-within? rect1 rect2) "Return #t if RECT2 is completely within RECT1." (and (>= (rect-left rect2) (rect-left rect1)) |