From d5ccb704b2177a86439ded078a674dc287b2a5bf Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 4 Jul 2025 14:33:38 +0200 Subject: [PATCH] :bug: Fix unexpected exception on creating bool shapes --- common/src/app/common/types/path.cljc | 17 +--- common/src/app/common/types/path/helpers.cljc | 5 +- .../common_tests/types/path_data_test.cljc | 87 +++++++++++++++++++ 3 files changed, 92 insertions(+), 17 deletions(-) diff --git a/common/src/app/common/types/path.cljc b/common/src/app/common/types/path.cljc index 017a8df15d..bcfc69fbcb 100644 --- a/common/src/app/common/types/path.cljc +++ b/common/src/app/common/types/path.cljc @@ -209,25 +209,16 @@ :code :invalid-path-content :hint (str "unable to calculate bool content for shape " (:id shape)) :shapes (:shapes shape) - :content (mapv str contents) + :type (:bool-type shape) + :content (vec contents) :cause cause))))) (defn calc-bool-content "Calculate the boolean content from shape and objects. Returns a packed PathData instance" [shape objects] - (ex/try! - (-> (calc-bool-content* shape objects) - (impl/path-data)) - - :on-exception - (fn [cause] - (ex/raise :type :internal - :code :invalid-path-content - :hint (str "unable to create bool content for shape " (:id shape)) - :content (str (:content shape)) - :shape-id (:id shape) - :cause cause)))) + (-> (calc-bool-content* shape objects) + (impl/path-data))) (defn update-bool-shape "Calculates the selrect+points for the boolean shape" diff --git a/common/src/app/common/types/path/helpers.cljc b/common/src/app/common/types/path/helpers.cljc index 389b6cf8e1..1f1218efd9 100644 --- a/common/src/app/common/types/path/helpers.cljc +++ b/common/src/app/common/types/path/helpers.cljc @@ -27,13 +27,11 @@ (defn make-move-to [to] {:command :move-to - :relative false :params {:x (:x to) :y (:y to)}}) (defn make-line-to [to] {:command :line-to - :relative false :params {:x (:x to) :y (:y to)}}) @@ -65,7 +63,6 @@ (defn make-curve-to [to h1 h2] {:command :curve-to - :relative false :params (make-curve-params to h1 h2)}) (defn prefix->coords [prefix] @@ -98,7 +95,7 @@ (defn segment->point ([segment] (segment->point segment :x)) ([segment coord] - (when-let [params (get segment :params)] + (when-let [params (not-empty (get segment :params))] (case coord :c1 (gpt/point (get params :c1x) (get params :c1y)) diff --git a/common/test/common_tests/types/path_data_test.cljc b/common/test/common_tests/types/path_data_test.cljc index aef996608a..b371b17ef8 100644 --- a/common/test/common_tests/types/path_data_test.cljc +++ b/common/test/common_tests/types/path_data_test.cljc @@ -14,6 +14,7 @@ [app.common.pprint :as pp] [app.common.transit :as trans] [app.common.types.path :as path] + [app.common.types.path.bool :as path.bool] [app.common.types.path.helpers :as path.helpers] [app.common.types.path.impl :as path.impl] [app.common.types.path.segment :as path.segment] @@ -414,3 +415,89 @@ result1 (get-handlers sample-content-large) result2 (path.segment/get-handlers content)] (t/is (= result1 result2)))) + + +(def contents-for-bool + [[{:command :move-to, :params {:x 1682.9000244140625, :y 48.0}} + {:command :line-to, :params {:x 1682.9000244140625, :y 44.0}} + {:command :curve-to, :params {:x 1683.9000244140625, :y 43.0, :c1x 1682.9000244140625, :c1y 43.400001525878906, :c2x 1683.300048828125, :c2y 43.0}} + {:command :line-to, :params {:x 1687.9000244140625, :y 43.0}} + {:command :curve-to, :params {:x 1688.9000244140625, :y 44.0, :c1x 1688.5, :c1y 43.0, :c2x 1688.9000244140625, :c2y 43.400001525878906}} + {:command :line-to, :params {:x 1688.9000244140625, :y 48.0}} + {:command :curve-to, :params {:x 1687.9000244140625, :y 49.0, :c1x 1688.9000244140625, :c1y 48.599998474121094, :c2x 1688.5, :c2y 49.0}} + {:command :line-to, :params {:x 1683.9000244140625, :y 49.0}} + {:command :curve-to, :params {:x 1682.9000244140625, :y 48.0, :c1x 1683.300048828125, :c1y 49.0, :c2x 1682.9000244140625, :c2y 48.599998474121094}} + {:command :close-path, :params {}} + {:command :close-path, :params {}} + {:command :move-to, :params {:x 1684.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1684.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1686.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1686.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1684.9000244140625, :y 45.0}} + {:command :close-path, :params {}} + {:command :close-path, :params {}}] + + [{:command :move-to, :params {:x 1672.9000244140625, :y 48.0}} + {:command :line-to, :params {:x 1672.9000244140625, :y 44.0}} + {:command :curve-to, :params {:x 1673.9000244140625, :y 43.0, :c1x 1672.9000244140625, :c1y 43.400001525878906, :c2x 1673.300048828125, :c2y 43.0}} + {:command :line-to, :params {:x 1677.9000244140625, :y 43.0}} + {:command :curve-to, :params {:x 1678.9000244140625, :y 44.0, :c1x 1678.5, :c1y 43.0, :c2x 1678.9000244140625, :c2y 43.400001525878906}} + {:command :line-to, :params {:x 1678.9000244140625, :y 48.0}} + {:command :curve-to, :params {:x 1677.9000244140625, :y 49.0, :c1x 1678.9000244140625, :c1y 48.599998474121094, :c2x 1678.5, :c2y 49.0}} + {:command :line-to, :params {:x 1673.9000244140625, :y 49.0}} + {:command :curve-to, :params {:x 1672.9000244140625, :y 48.0, :c1x 1673.300048828125, :c1y 49.0, :c2x 1672.9000244140625, :c2y 48.599998474121094}} + {:command :close-path, :params {}} + {:command :close-path, :params {}} + {:command :move-to, :params {:x 1674.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1674.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1676.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1676.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1674.9000244140625, :y 45.0}} + {:command :close-path, :params {}} + {:command :close-path, :params {}}]]) + +(def bool-result + [{:command :move-to, :params {:x 1682.9000244140625, :y 48.0}} + {:command :line-to, :params {:x 1682.9000244140625, :y 44.0}} + {:command :curve-to, + :params + {:x 1683.9000244140625, :y 43.0, :c1x 1682.9000244140625, :c1y 43.400001525878906, :c2x 1683.300048828125, :c2y 43.0}} + {:command :line-to, :params {:x 1687.9000244140625, :y 43.0}} + {:command :curve-to, + :params {:x 1688.9000244140625, :y 44.0, :c1x 1688.5, :c1y 43.0, :c2x 1688.9000244140625, :c2y 43.400001525878906}} + {:command :line-to, :params {:x 1688.9000244140625, :y 48.0}} + {:command :curve-to, + :params {:x 1687.9000244140625, :y 49.0, :c1x 1688.9000244140625, :c1y 48.599998474121094, :c2x 1688.5, :c2y 49.0}} + {:command :line-to, :params {:x 1683.9000244140625, :y 49.0}} + {:command :curve-to, + :params + {:x 1682.9000244140625, :y 48.0, :c1x 1683.300048828125, :c1y 49.0, :c2x 1682.9000244140625, :c2y 48.599998474121094}} + {:command :move-to, :params {:x 1684.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1684.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1686.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1686.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1684.9000244140625, :y 45.0}} + {:command :move-to, :params {:x 1672.9000244140625, :y 48.0}} + {:command :line-to, :params {:x 1672.9000244140625, :y 44.0}} + {:command :curve-to, + :params + {:x 1673.9000244140625, :y 43.0, :c1x 1672.9000244140625, :c1y 43.400001525878906, :c2x 1673.300048828125, :c2y 43.0}} + {:command :line-to, :params {:x 1677.9000244140625, :y 43.0}} + {:command :curve-to, + :params {:x 1678.9000244140625, :y 44.0, :c1x 1678.5, :c1y 43.0, :c2x 1678.9000244140625, :c2y 43.400001525878906}} + {:command :line-to, :params {:x 1678.9000244140625, :y 48.0}} + {:command :curve-to, + :params {:x 1677.9000244140625, :y 49.0, :c1x 1678.9000244140625, :c1y 48.599998474121094, :c2x 1678.5, :c2y 49.0}} + {:command :line-to, :params {:x 1673.9000244140625, :y 49.0}} + {:command :curve-to, + :params + {:x 1672.9000244140625, :y 48.0, :c1x 1673.300048828125, :c1y 49.0, :c2x 1672.9000244140625, :c2y 48.599998474121094}} + {:command :move-to, :params {:x 1674.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1674.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1676.9000244140625, :y 47.0}} + {:command :line-to, :params {:x 1676.9000244140625, :y 45.0}} + {:command :line-to, :params {:x 1674.9000244140625, :y 45.0}}]) + +(t/deftest calculate-bool-content + (let [result (path.bool/calculate-content :union contents-for-bool)] + (t/is (= result bool-result))))