From 6b422033981c2547da73d82301826f9d1bf3661e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 27 Dec 2022 12:11:46 -0500 Subject: node-2d: Short circuit move-by if dx/dy are both 0. --- catbird/node-2d.scm | 26 +++++++++++++++----------- 1 file 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 ) 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 ) 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 ) dx dy duration) (move-by node dx dy duration smoothstep)) -- cgit v1.2.3