From 565046aaa696c42f7a567879743912f2dd175730 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 1 Dec 2021 09:36:05 +0100 Subject: [PATCH] :zap: Memoize transform-shape --- .../app/common/geom/shapes/transforms.cljc | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 3c84bd4574..70391996da 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -391,7 +391,7 @@ {:rotation angle :displacement displacement})) -(defn merge-modifiers +(defn merge-modifiers* [objects modifiers] (let [set-modifier @@ -401,6 +401,8 @@ (->> modifiers (reduce set-modifier objects)))) +(def merge-modifiers (memoize merge-modifiers*)) + (defn- modifiers->transform [center modifiers] (let [ds-modifier (:displacement modifiers (gmt/matrix)) @@ -491,25 +493,30 @@ %))) shape)) +(defn -transform-shape + [shape {:keys [round-coords?] + :or {round-coords? true}}] + (if (and (contains? shape :modifiers) (empty-modifiers? (:modifiers shape))) + (dissoc shape :modifiers) + (let [shape (apply-displacement shape) + center (gco/center-shape shape) + modifiers (:modifiers shape)] + (if (and (not (empty-modifiers? modifiers)) center) + (let [transform (modifiers->transform center modifiers)] + (-> shape + (set-flip modifiers) + (apply-transform transform round-coords?) + (apply-text-resize modifiers) + (dissoc :modifiers))) + shape)))) + +(def transform-shape* (memoize -transform-shape)) + (defn transform-shape ([shape] - (transform-shape shape nil)) - - ([shape {:keys [round-coords?] - :or {round-coords? true}}] - (if (and (contains? shape :modifiers) (empty-modifiers? (:modifiers shape))) - (dissoc shape :modifiers) - (let [shape (apply-displacement shape) - center (gco/center-shape shape) - modifiers (:modifiers shape)] - (if (and (not (empty-modifiers? modifiers)) center) - (let [transform (modifiers->transform center modifiers)] - (-> shape - (set-flip modifiers) - (apply-transform transform round-coords?) - (apply-text-resize modifiers) - (dissoc :modifiers))) - shape))))) + (transform-shape* shape nil)) + ([shape options] + (transform-shape* shape options))) (defn calc-transformed-parent-rect [{:keys [selrect] :as shape} {:keys [displacement resize-transform-inverse resize-vector resize-origin resize-vector-2 resize-origin-2]}]