diff --git a/common/src/app/common/geom/shapes/intersect.cljc b/common/src/app/common/geom/shapes/intersect.cljc index 72d5bf47a..12b64f897 100644 --- a/common/src/app/common/geom/shapes/intersect.cljc +++ b/common/src/app/common/geom/shapes/intersect.cljc @@ -363,10 +363,10 @@ c2 (+ (* a2 (:x c)) (* b2 (:y c))) ;; Cramer's rule - det (- (* a1 b2) (* a2 b1))] + det (- (* a1 b2) (* a2 b1)) + det (if (mth/almost-zero? det) 0.001 det) - ;; If almost zero the lines are parallel - (when (not (mth/almost-zero? det)) - (let [x (/ (- (* b2 c1) (* b1 c2)) det) - y (/ (- (* c2 a1) (* c1 a2)) det)] - (gpt/point x y))))) + x (/ (- (* b2 c1) (* b1 c2)) det) + y (/ (- (* c2 a1) (* c1 a2)) det)] + + (gpt/point x y))) diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 3ced06e11..9734c6179 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -56,14 +56,17 @@ {:layout :grid}) (defn get-layout-initializer - [type] + [type from-frame?] (let [initial-layout-data (if (= type :flex) initial-flex-layout initial-grid-layout)] (fn [shape] (-> shape - (merge shape initial-layout-data))))) + (merge initial-layout-data) + ;; If the original shape is not a frame we set clip content and show-viewer to false + (cond-> (not from-frame?) + (assoc :show-content true :hide-in-viewer true)))))) (defn create-layout-from-id - [ids type] + [ids type from-frame?] (ptk/reify ::create-layout-from-id ptk/WatchEvent (watch [_ state _] @@ -71,7 +74,7 @@ children-ids (into [] (mapcat #(get-in objects [% :shapes])) ids) undo-id (js/Symbol)] (rx/of (dwu/start-undo-transaction undo-id) - (dwc/update-shapes ids (get-layout-initializer type)) + (dwc/update-shapes ids (get-layout-initializer type from-frame?)) (ptk/data-event :layout/update ids) (dwc/update-shapes children-ids #(dissoc % :constraints-h :constraints-v)) (dwu/commit-undo-transaction undo-id)))))) @@ -173,7 +176,7 @@ (dws/create-artboard-from-selection new-shape-id parent-id group-index) (cl/remove-all-fills [new-shape-id] {:color clr/black :opacity 1}) - (create-layout-from-id [new-shape-id] type) + (create-layout-from-id [new-shape-id] type false) (dwc/update-shapes [new-shape-id] (fn [shape] @@ -193,7 +196,7 @@ (dws/create-artboard-from-selection new-shape-id) (cl/remove-all-fills [new-shape-id] {:color clr/black :opacity 1}) - (create-layout-from-id [new-shape-id] type) + (create-layout-from-id [new-shape-id] type false) (dwc/update-shapes [new-shape-id] (fn [shape] @@ -233,7 +236,7 @@ (if (and single? is-frame?) (rx/of (dwu/start-undo-transaction undo-id) - (create-layout-from-id [(first selected)] :flex) + (create-layout-from-id [(first selected)] :flex true) (dwu/commit-undo-transaction undo-id)) (rx/of (dwu/start-undo-transaction undo-id) diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 1bf722ad2..215bdeff8 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -375,7 +375,7 @@ is-flex-container? (and is-frame? (= :flex (:layout (first shapes)))) ids (->> shapes (map :id)) add-flex #(st/emit! (if is-frame? - (dwsl/create-layout-from-id ids :flex) + (dwsl/create-layout-from-id ids :flex true) (dwsl/create-layout-from-selection :flex))) remove-flex #(st/emit! (dwsl/remove-layout ids))]