diff options
author | David Thompson <dthompson2@worcester.edu> | 2022-12-27 12:11:46 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2022-12-28 12:18:33 -0500 |
commit | 6b422033981c2547da73d82301826f9d1bf3661e (patch) | |
tree | 884310a2b2e87eba02bfb55c5588bc43ba307c3d | |
parent | de9fe35b94afe0225d721a7c5f29b7b34b125581 (diff) |
node-2d: Short circuit move-by if dx/dy are both 0.
-rw-r--r-- | catbird/node-2d.scm | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/catbird/node-2d.scm b/catbird/node-2d.scm index 41f82db..34a7417 100644 --- a/catbird/node-2d.scm +++ b/catbird/node-2d.scm @@ -487,19 +487,23 @@ (move-to node x y duration smoothstep)) (define-method (move-by (node <node-2d>) dx dy) - (let ((p (position node))) - (move-to node (+ (vec2-x p) dx) (+ (vec2-y p) dy)))) + ;; No-op if the node wouldn't be moved at all. + (unless (and (= dx 0.0) (= dy 0.0)) + (let ((p (position node))) + (move-to node (+ (vec2-x p) dx) (+ (vec2-y p) dy))))) (define-method (move-by (node <node-2d>) dx dy duration ease) - (let* ((p (position node)) - (start-x (vec2-x p)) - (start-y (vec2-y p))) - (tween duration 0.0 1.0 - (lambda (n) - (move-to node - (+ start-x (* dx n)) - (+ start-y (* dy n)))) - #:ease ease))) + ;; No-op if the node wouldn't be moved at all. + (unless (and (= dx 0.0) (= dy 0.0)) + (let* ((p (position node)) + (start-x (vec2-x p)) + (start-y (vec2-y p))) + (tween duration 0.0 1.0 + (lambda (n) + (move-to node + (+ start-x (* dx n)) + (+ start-y (* dy n)))) + #:ease ease)))) (define-method (move-by (node <node-2d>) dx dy duration) (move-by node dx dy duration smoothstep)) |