summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee/math/rect.scm117
1 files changed, 61 insertions, 56 deletions
diff --git a/chickadee/math/rect.scm b/chickadee/math/rect.scm
index b4f1ba4..25113ad 100644
--- a/chickadee/math/rect.scm
+++ b/chickadee/math/rect.scm
@@ -172,62 +172,6 @@
"Restrict Y to the portion of the y axis covered by RECT."
(clamp (rect-bottom rect) (rect-top rect) y))
-(define (vec2-clamp-to-rect v rect)
- "Return a new vec2 with the x and y coordinates of the vec2 V
-restricted so that they are within the bounds of RECT."
- (vec2-clamp-to-rect! (vec2-copy v) rect))
-
-(define (rect-clamp rect1 rect2)
- "Return a new rect that adjusts the location of RECT1 so that it is
-completely within RECT2. An exception is thrown in the case that
-RECT1 cannot fit completely within RECT2."
- (with-new-rect new
- (rect-copy! rect1 new)
- (rect-clamp! new rect2)))
-
-(define-inlinable (rect-move rect x y)
- "Return a new rect based on RECT but moved to location (X, Y)."
- (make-rect x y (rect-width rect) (rect-height rect)))
-
-(define-inlinable (rect-move-vec2 rect v)
- "Return a new rect based on RECT but moved to the vec2 V."
- (make-rect (vec2-x v) (vec2-y v) (rect-width rect) (rect-height rect)))
-
-(define-inlinable (rect-move-by rect x y)
- "Return a new rect based on RECT but moved by (X, Y) units relative
-to its current location."
- (with-new-rect new
- (rect-copy! rect new)
- (rect-move-by! new x y)))
-
-(define-inlinable (rect-move-by-vec2 rect v)
- "Return a new rect based on RECT but moved by the vec2 V relative to
-its current location."
- (with-new-rect new
- (rect-copy! rect new)
- (rect-move-by-vec2! new v)))
-
-(define-inlinable (rect-inflate rect width height)
- "Return a new rect based on RECT but grown by WIDTH on the x axis
-and HEIGHT on the y axis while keeping the rect centered around the
-same point."
- (with-new-rect rect
- (rect-inflate! rect width height)))
-
-(define (rect-union rect1 rect2)
- "Return a new rect that completely covers the area of RECT1 and
-RECT2."
- (with-new-rect rect
- (rect-copy! rect2 rect1)
- (rect-union! rect1 rect2)))
-
-(define (rect-clip rect1 rect2)
- "Return a new rectangle that is the overlapping region of RECT1 and
-RECT2. If the rects do not overlap, a rect of size 0 is returned."
- (with-new-rect rect
- (rect-copy! rect2 rect1)
- (rect-clip! rect1 rect2)))
-
;;;
;;; In-place operations
@@ -337,6 +281,67 @@ fit completely within RECT2."
;;;
+;;; Functional operations
+;;;
+
+(define (vec2-clamp-to-rect v rect)
+ "Return a new vec2 with the x and y coordinates of the vec2 V
+restricted so that they are within the bounds of RECT."
+ (vec2-clamp-to-rect! (vec2-copy v) rect))
+
+(define (rect-clamp rect1 rect2)
+ "Return a new rect that adjusts the location of RECT1 so that it is
+completely within RECT2. An exception is thrown in the case that
+RECT1 cannot fit completely within RECT2."
+ (with-new-rect new
+ (rect-copy! rect1 new)
+ (rect-clamp! new rect2)))
+
+(define-inlinable (rect-move rect x y)
+ "Return a new rect based on RECT but moved to location (X, Y)."
+ (make-rect x y (rect-width rect) (rect-height rect)))
+
+(define-inlinable (rect-move-vec2 rect v)
+ "Return a new rect based on RECT but moved to the vec2 V."
+ (make-rect (vec2-x v) (vec2-y v) (rect-width rect) (rect-height rect)))
+
+(define-inlinable (rect-move-by rect x y)
+ "Return a new rect based on RECT but moved by (X, Y) units relative
+to its current location."
+ (with-new-rect new
+ (rect-copy! rect new)
+ (rect-move-by! new x y)))
+
+(define-inlinable (rect-move-by-vec2 rect v)
+ "Return a new rect based on RECT but moved by the vec2 V relative to
+its current location."
+ (with-new-rect new
+ (rect-copy! rect new)
+ (rect-move-by-vec2! new v)))
+
+(define-inlinable (rect-inflate rect width height)
+ "Return a new rect based on RECT but grown by WIDTH on the x axis
+and HEIGHT on the y axis while keeping the rect centered around the
+same point."
+ (with-new-rect rect
+ (rect-inflate! rect width height)))
+
+(define (rect-union rect1 rect2)
+ "Return a new rect that completely covers the area of RECT1 and
+RECT2."
+ (with-new-rect rect
+ (rect-copy! rect2 rect1)
+ (rect-union! rect1 rect2)))
+
+(define (rect-clip rect1 rect2)
+ "Return a new rectangle that is the overlapping region of RECT1 and
+RECT2. If the rects do not overlap, a rect of size 0 is returned."
+ (with-new-rect rect
+ (rect-copy! rect2 rect1)
+ (rect-clip! rect1 rect2)))
+
+
+;;;
;;; Queries
;;;