From 745cf1c79d4f343d27854c0e336d83f871df4e38 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 31 Mar 2023 12:05:59 +0200 Subject: [PATCH] :bug: Fix problem with invalid geometry --- common/src/app/common/geom/point.cljc | 6 ++++-- common/src/app/common/geom/shapes/common.cljc | 15 ++++++++++++++- common/src/app/common/geom/shapes/modifiers.cljc | 5 ++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/geom/point.cljc b/common/src/app/common/geom/point.cljc index d83a46c99..5517bc5a2 100644 --- a/common/src/app/common/geom/point.cljc +++ b/common/src/app/common/geom/point.cljc @@ -318,8 +318,10 @@ (defn unit [p1] (let [p-length (length p1)] - (Point. (/ (dm/get-prop p1 :x) p-length) - (/ (dm/get-prop p1 :y) p-length)))) + (if (mth/almost-zero? p-length) + (Point. 0 0) + (Point. (/ (dm/get-prop p1 :x) p-length) + (/ (dm/get-prop p1 :y) p-length))))) (defn perpendicular [pt] diff --git a/common/src/app/common/geom/shapes/common.cljc b/common/src/app/common/geom/shapes/common.cljc index 710c15e78..a0fcdb4b5 100644 --- a/common/src/app/common/geom/shapes/common.cljc +++ b/common/src/app/common/geom/shapes/common.cljc @@ -9,7 +9,8 @@ [app.common.data :as d] [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] - [app.common.geom.shapes.rect :as gpr])) + [app.common.geom.shapes.rect :as gpr] + [app.common.math :as mth])) (defn center-rect [{:keys [x y width height]}] @@ -71,3 +72,15 @@ [{:keys [x1 y1 x2 y2] :as sr} matrix] (let [[c1 c2] (transform-points [(gpt/point x1 y1) (gpt/point x2 y2)] matrix)] (gpr/corners->selrect c1 c2))) + +(defn invalid-geometry? + [{:keys [points selrect]}] + + (or (mth/nan? (:x selrect)) + (mth/nan? (:y selrect)) + (mth/nan? (:width selrect)) + (mth/nan? (:height selrect)) + (some (fn [p] + (or (mth/nan? (:x p)) + (mth/nan? (:y p)))) + points))) diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index d14f5aaa3..cd94fb11a 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -9,6 +9,7 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.common.geom.point :as gpt] + [app.common.geom.shapes.common :as gco] [app.common.geom.shapes.constraints :as gct] [app.common.geom.shapes.flex-layout :as gcl] [app.common.geom.shapes.pixel-precision :as gpp] @@ -175,6 +176,7 @@ (let [children (->> (cph/get-immediate-children objects (:id parent)) (remove :hidden) + (remove gco/invalid-geometry?) (map apply-modifiers)) layout-data (gcl/calc-layout-data parent children @transformed-parent-bounds) children (into [] (cond-> children (not (:reverse? layout-data)) reverse)) @@ -215,7 +217,8 @@ (ctm/resize-parent (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent))))) children (->> (cph/get-immediate-children objects parent-id) - (remove :hidden)) + (remove :hidden) + (remove gco/invalid-geometry?)) content-bounds (when (and (d/not-empty? children) (or (ctl/auto-height? parent) (ctl/auto-width? parent)))