diff options
author | David Thompson <dthompson2@worcester.edu> | 2017-01-24 19:50:59 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2017-01-24 19:50:59 -0500 |
commit | 0bf6c483e32b2bdca0cebc40ed9e57001bfefbb4 (patch) | |
tree | 86648539a475aa4f360d916e5f73ca2b7127dcee | |
parent | a2c960ad76832b15cbdc5e618c05dacb85986ddf (diff) |
math: vector: Fix vec2-copy and vec2-copy!
* chickadee/math/vector.scm: Reorder procedure definitions to overcome
inlining issues.
-rw-r--r-- | chickadee/math/vector.scm | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/chickadee/math/vector.scm b/chickadee/math/vector.scm index b34d5a2..6920cf5 100644 --- a/chickadee/math/vector.scm +++ b/chickadee/math/vector.scm @@ -24,8 +24,8 @@ vec2/polar vec2? vec2->pointer - copy-vec2 - copy-vec2! + vec2-copy + vec2-copy! vec2-x vec2-y vec2-magnitude @@ -75,19 +75,6 @@ polar coordinate (R, THETA)." (vec2 (* r (cos theta)) (* r (sin theta)))) -(define (vec2-copy! source-vec2 target-vec2) - "Copy TARGET-VEC2 to SOURCE-VEC2." - (bytevector-copy! (unwrap-vec2 source-vec2) - 0 - (unwrap-vec2 target-vec2) - 0 - 16)) - -(define (vec2-copy vec2) - "Return a new vec2 that is a copy of VEC2." - (with-new-vec2 new - (vec2-copy! vec2 new))) - (define-inlinable (vec2-x v) "Return the x coordinate of the vec2 V." (vec2-ref v 0)) @@ -96,6 +83,24 @@ polar coordinate (R, THETA)." "Return the y coordinate of the vec2 V." (vec2-ref v 1)) +(define-inlinable (set-vec2-x! v x) + "Set the x coordinate of the vec2 V to X." + (vec2-set! v 0 x)) + +(define-inlinable (set-vec2-y! v y) + "Set the y coordinate of the vec2 V to Y." + (vec2-set! v 1 y)) + +(define (vec2-copy! source-vec2 target-vec2) + "Copy TARGET-VEC2 to SOURCE-VEC2." + (set-vec2-x! target-vec2 (vec2-x source-vec2)) + (set-vec2-y! target-vec2 (vec2-y source-vec2))) + +(define (vec2-copy vec2) + "Return a new vec2 that is a copy of VEC2." + (with-new-vec2 new + (vec2-copy! vec2 new))) + (define-inlinable (vec2-magnitude v) "Return the magnitude of the vec2 V." (sqrt (+ (square (vec2-x v)) (square (vec2-y v))))) @@ -111,14 +116,6 @@ polar coordinate (R, THETA)." (vec2-copy! v new) (vec2-normalize! new))) -(define-inlinable (set-vec2-x! v x) - "Set the x coordinate of the vec2 V to X." - (vec2-set! v 0 x)) - -(define-inlinable (set-vec2-y! v y) - "Set the y coordinate of the vec2 V to Y." - (vec2-set! v 1 y)) - (define-inlinable (vec2-normalize! v) "Normalize the vec2 V in-place." (unless (and (zero? (vec2-x v)) (zero? (vec2-y v))) |