summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-10-15 18:39:33 -0400
committerDavid Thompson <dthompson2@worcester.edu>2020-10-15 18:43:01 -0400
commit3a908c50ccb9975dda8d6a0fd97e9963c3052454 (patch)
tree8b3ca90ff05c62007e48403f861a3f07e75e914b
parented6fb016d91b924fd8459c9115fae0cf86883db9 (diff)
math: rect: Move functional procedures after the imperative ones.
The functional procedures weren't working because of a quirk with Guile's handling of the top level.
-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
;;;