♻️ Refactor selrec generation

This commit is contained in:
alonso.torres 2022-03-08 15:37:41 +01:00
parent ed9400912c
commit 0f54e85b36
18 changed files with 187 additions and 186 deletions

View file

@ -406,15 +406,24 @@
[v default] [v default]
(if (some? v) v default)) (if (some? v) v default))
(defn num?
"Checks if a value `val` is a number but not an Infinite or NaN"
([val]
(and (number? val)
(mth/finite? val)
(not (mth/nan? val))))
([val & vals]
(and (num? val)
(->> vals (every? num?)))))
(defn check-num (defn check-num
"Function that checks if a number is nil or nan. Will return 0 when not "Function that checks if a number is nil or nan. Will return 0 when not
valid and the number otherwise." valid and the number otherwise."
([v] ([v]
(check-num v 0)) (check-num v 0))
([v default] ([v default]
(if (or (not v) (if (num? v) v default)))
(not (mth/finite? v))
(mth/nan? v)) default v)))
(defn any-key? [element & rest] (defn any-key? [element & rest]
(some #(contains? element %) rest)) (some #(contains? element %) rest))

View file

@ -21,6 +21,11 @@
(def conjv (fnil conj [])) (def conjv (fnil conj []))
(def conjs (fnil conj #{})) (def conjs (fnil conj #{}))
(defn- raise
[err-str]
#?(:clj (throw (Exception. err-str))
:cljs (throw (js/Error. err-str))))
(defn- commit-change (defn- commit-change
([file change] ([file change]
(commit-change file change nil)) (commit-change file change nil))
@ -75,10 +80,12 @@
(commit-change file change {:add-container? true :fail-on-spec? fail-on-spec?}))) (commit-change file change {:add-container? true :fail-on-spec? fail-on-spec?})))
(defn setup-rect-selrect [obj] (defn setup-rect-selrect [{:keys [x y width height transform] :as obj}]
(let [rect (select-keys obj [:x :y :width :height]) (when-not (d/num? x y width height)
(raise "Coords not valid for object"))
(let [rect (gsh/make-rect x y width height)
center (gsh/center-rect rect) center (gsh/center-rect rect)
transform (:transform obj (gmt/matrix))
selrect (gsh/rect->selrect rect) selrect (gsh/rect->selrect rect)
points (-> (gsh/rect->points rect) points (-> (gsh/rect->points rect)
@ -89,17 +96,13 @@
(assoc :points points)))) (assoc :points points))))
(defn- setup-path-selrect (defn- setup-path-selrect
[obj] [{:keys [content center transform transform-inverse] :as obj}]
(let [content (:content obj)
center (:center obj)
transform-inverse (when (or (empty? content) (nil? center))
(->> (:transform-inverse obj (gmt/matrix)) (raise "Path not valid"))
(gmt/transform-in center))
transform (let [transform (gmt/transform-in center transform)
(->> (:transform obj (gmt/matrix)) transform-inverse (gmt/transform-in center transform-inverse)
(gmt/transform-in center))
content' (gsh/transform-content content transform-inverse) content' (gsh/transform-content content transform-inverse)
selrect (gsh/content->selrect content') selrect (gsh/content->selrect content')
@ -310,21 +313,30 @@
children (->> bool :shapes (mapv #(lookup-shape file %))) children (->> bool :shapes (mapv #(lookup-shape file %)))
file file
(let [objects (lookup-objects file) (cond
bool' (gsh/update-bool-selrect bool children objects)] (empty? children)
(commit-change (commit-change
file file
{:type :mod-obj {:type :del-obj
:id bool-id :id bool-id}
:operations {:add-container? true})
[{:type :set :attr :selrect :val (:selrect bool')}
{:type :set :attr :points :val (:points bool')}
{:type :set :attr :x :val (-> bool' :selrect :x)}
{:type :set :attr :y :val (-> bool' :selrect :y)}
{:type :set :attr :width :val (-> bool' :selrect :width)}
{:type :set :attr :height :val (-> bool' :selrect :height)}]}
{:add-container? true}))] :else
(let [objects (lookup-objects file)
bool' (gsh/update-bool-selrect bool children objects)]
(commit-change
file
{:type :mod-obj
:id bool-id
:operations
[{:type :set :attr :selrect :val (:selrect bool')}
{:type :set :attr :points :val (:points bool')}
{:type :set :attr :x :val (-> bool' :selrect :x)}
{:type :set :attr :y :val (-> bool' :selrect :y)}
{:type :set :attr :width :val (-> bool' :selrect :width)}
{:type :set :attr :height :val (-> bool' :selrect :height)}]}
{:add-container? true})))]
(-> file (-> file
(update :parent-stack pop)))) (update :parent-stack pop))))

View file

@ -187,7 +187,7 @@
(defmethod pp/simple-dispatch Matrix [obj] (pr obj)) (defmethod pp/simple-dispatch Matrix [obj] (pr obj))
(defn transform-in [pt mtx] (defn transform-in [pt mtx]
(if (some? pt) (if (and (some? pt) (some? mtx))
(-> (matrix) (-> (matrix)
(translate pt) (translate pt)
(multiply mtx) (multiply mtx)

View file

@ -141,15 +141,17 @@
(dm/export gco/center-selrect) (dm/export gco/center-selrect)
(dm/export gco/center-rect) (dm/export gco/center-rect)
(dm/export gco/center-points) (dm/export gco/center-points)
(dm/export gco/make-centered-rect)
(dm/export gco/transform-points) (dm/export gco/transform-points)
(dm/export gpr/make-rect)
(dm/export gpr/rect->selrect) (dm/export gpr/rect->selrect)
(dm/export gpr/rect->points) (dm/export gpr/rect->points)
(dm/export gpr/points->selrect) (dm/export gpr/points->selrect)
(dm/export gpr/points->rect) (dm/export gpr/points->rect)
(dm/export gpr/center->rect) (dm/export gpr/center->rect)
(dm/export gpr/center->selrect)
(dm/export gpr/join-rects) (dm/export gpr/join-rects)
(dm/export gpr/join-selrects)
(dm/export gpr/contains-selrect?) (dm/export gpr/contains-selrect?)
(dm/export gtr/move) (dm/export gtr/move)

View file

@ -6,29 +6,24 @@
(ns app.common.geom.shapes.common (ns app.common.geom.shapes.common
(:require (:require
[app.common.data :as d]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt])) [app.common.geom.point :as gpt]))
(defn center-rect (defn center-rect
[{:keys [x y width height]}] [{:keys [x y width height]}]
(when (and (mth/finite? x) (when (d/num? x y width height)
(mth/finite? y)
(mth/finite? width)
(mth/finite? height))
(gpt/point (+ x (/ width 2.0)) (gpt/point (+ x (/ width 2.0))
(+ y (/ height 2.0))))) (+ y (/ height 2.0)))))
(defn center-selrect (defn center-selrect
"Calculate the center of the shape." "Calculate the center of the selrect."
[selrect] [selrect]
(center-rect selrect)) (center-rect selrect))
(def map-x-xf (comp (map :x) (remove nil?)))
(def map-y-xf (comp (map :y) (remove nil?)))
(defn center-points [points] (defn center-points [points]
(let [ptx (into [] map-x-xf points) (let [ptx (into [] (keep :x) points)
pty (into [] map-y-xf points) pty (into [] (keep :y) points)
minx (reduce min ##Inf ptx) minx (reduce min ##Inf ptx)
miny (reduce min ##Inf pty) miny (reduce min ##Inf pty)
maxx (reduce max ##-Inf ptx) maxx (reduce max ##-Inf ptx)
@ -41,35 +36,12 @@
[shape] [shape]
(center-rect (:selrect shape))) (center-rect (:selrect shape)))
(defn make-centered-rect
"Creates a rect given a center and a width and height"
[center width height]
{:x (- (:x center) (/ width 2.0))
:y (- (:y center) (/ height 2.0))
:width width
:height height})
(defn make-centered-selrect
"Creates a rect given a center and a width and height"
[center width height]
(let [x1 (- (:x center) (/ width 2.0))
y1 (- (:y center) (/ height 2.0))
x2 (+ x1 width)
y2 (+ y1 height)]
{:x x1
:y y1
:x1 x1
:x2 x2
:y1 y1
:y2 y2
:width width
:height height}))
(defn transform-points (defn transform-points
([points matrix] ([points matrix]
(transform-points points nil matrix)) (transform-points points nil matrix))
([points center matrix] ([points center matrix]
(if (some? matrix) (if (and (d/not-empty? points) (some? matrix))
(let [prev (if center (gmt/translate-matrix center) (gmt/matrix)) (let [prev (if center (gmt/translate-matrix center) (gmt/matrix))
post (if center (gmt/translate-matrix (gpt/negate center)) (gmt/matrix)) post (if center (gmt/translate-matrix (gpt/negate center)) (gmt/matrix))

View file

@ -362,13 +362,8 @@
extremities (mapcat calc-extremities extremities (mapcat calc-extremities
content content
(concat [nil] content)) (concat [nil] content))]
(gpr/points->selrect extremities)))
selrect (gpr/points->selrect extremities)]
(-> selrect
(update :width #(if (mth/almost-zero? %) 1 %))
(update :height #(if (mth/almost-zero? %) 1 %)))))
(defn move-content [content move-vec] (defn move-content [content move-vec]
(let [dx (:x move-vec) (let [dx (:x move-vec)
@ -393,23 +388,26 @@
(defn transform-content (defn transform-content
[content transform] [content transform]
(let [set-tr (fn [params px py] (if (some? transform)
(let [tr-point (-> (gpt/point (get params px) (get params py)) (let [set-tr
(gpt/transform transform))] (fn [params px py]
(assoc params (let [tr-point (-> (gpt/point (get params px) (get params py))
px (:x tr-point) (gpt/transform transform))]
py (:y tr-point)))) (assoc params
px (:x tr-point)
py (:y tr-point))))
transform-params transform-params
(fn [{:keys [x c1x c2x] :as params}] (fn [{:keys [x c1x c2x] :as params}]
(cond-> params (cond-> params
(some? x) (set-tr :x :y) (some? x) (set-tr :x :y)
(some? c1x) (set-tr :c1x :c1y) (some? c1x) (set-tr :c1x :c1y)
(some? c2x) (set-tr :c2x :c2y)))] (some? c2x) (set-tr :c2x :c2y)))]
(into [] (into []
(map #(update % :params transform-params)) (map #(update % :params transform-params))
content))) content))
content))
(defn segments->content (defn segments->content
([segments] ([segments]

View file

@ -6,80 +6,101 @@
(ns app.common.geom.shapes.rect (ns app.common.geom.shapes.rect
(:require (:require
[app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.math :as mth])) [app.common.math :as mth]))
(defn make-rect
[x y width height]
(when (d/num? x y width height)
(let [width (max width 0.01)
height (max height 0.01)]
{:x x
:y y
:width width
:height height})))
(defn make-selrect
[x y width height]
(when (d/num? x y width height)
(let [width (max width 0.01)
height (max height 0.01)]
{:x x
:y y
:x1 x
:y1 y
:x2 (+ x width)
:y2 (+ y height)
:width width
:height height})))
(defn rect->points [{:keys [x y width height]}] (defn rect->points [{:keys [x y width height]}]
;; (assert (number? x)) (when (d/num? x y)
;; (assert (number? y)) (let [width (max width 0.01)
;; (assert (and (number? width) (> width 0))) height (max height 0.01)]
;; (assert (and (number? height) (> height 0))) [(gpt/point x y)
[(gpt/point x y) (gpt/point (+ x width) y)
(gpt/point (+ x width) y) (gpt/point (+ x width) (+ y height))
(gpt/point (+ x width) (+ y height)) (gpt/point x (+ y height))])))
(gpt/point x (+ y height))])
(defn rect->lines [{:keys [x y width height]}] (defn rect->lines [{:keys [x y width height]}]
[[(gpt/point x y) (gpt/point (+ x width) y)] (when (d/num? x y)
[(gpt/point (+ x width) y) (gpt/point (+ x width) (+ y height))] (let [width (max width 0.01)
[(gpt/point (+ x width) (+ y height)) (gpt/point x (+ y height))] height (max height 0.01)]
[(gpt/point x (+ y height)) (gpt/point x y)]]) [[(gpt/point x y) (gpt/point (+ x width) y)]
[(gpt/point (+ x width) y) (gpt/point (+ x width) (+ y height))]
[(gpt/point (+ x width) (+ y height)) (gpt/point x (+ y height))]
[(gpt/point x (+ y height)) (gpt/point x y)]])))
(defn points->rect (defn points->rect
[points] [points]
(let [minx (transduce gco/map-x-xf min ##Inf points) (when (d/not-empty? points)
miny (transduce gco/map-y-xf min ##Inf points) (let [minx (transduce (keep :x) min ##Inf points)
maxx (transduce gco/map-x-xf max ##-Inf points) miny (transduce (keep :y) min ##Inf points)
maxy (transduce gco/map-y-xf max ##-Inf points)] maxx (transduce (keep :x) max ##-Inf points)
{:x minx maxy (transduce (keep :y) max ##-Inf points)]
:y miny (when (d/num? minx miny maxx maxy)
:width (- maxx minx) (make-rect minx miny (- maxx minx) (- maxy miny))))))
:height (- maxy miny)}))
(defn points->selrect [points] (defn points->selrect [points]
(let [{:keys [x y width height] :as rect} (points->rect points)] (when-let [rect (points->rect points)]
(assoc rect (let [{:keys [x y width height]} rect]
:x1 x (make-selrect x y width height))))
:x2 (+ x width)
:y1 y
:y2 (+ y height))))
(defn rect->selrect [rect] (defn rect->selrect [rect]
(-> rect rect->points points->selrect)) (-> rect rect->points points->selrect))
(defn join-rects [rects] (defn join-rects [rects]
(let [minx (transduce (comp (map :x) (remove nil?)) min ##Inf rects) (when (d/not-empty? rects)
miny (transduce (comp (map :y) (remove nil?)) min ##Inf rects) (let [minx (transduce (keep :x) min ##Inf rects)
maxx (transduce (comp (map #(+ (:x %) (:width %))) (remove nil?)) max ##-Inf rects) miny (transduce (keep :y) min ##Inf rects)
maxy (transduce (comp (map #(+ (:y %) (:height %))) (remove nil?)) max ##-Inf rects)] maxx (transduce (keep #(when (and (:x %) (:width %)) (+ (:x %) (:width %)))) max ##-Inf rects)
{:x minx maxy (transduce (keep #(when (and (:y %) (:height %))(+ (:y %) (:height %)))) max ##-Inf rects)]
:y miny (when (d/num? minx miny maxx maxy)
:width (- maxx minx) (make-rect minx miny (- maxx minx) (- maxy miny))))))
:height (- maxy miny)}))
(defn join-selrects [selrects] (defn join-selrects [selrects]
(let [minx (transduce (comp (map :x1) (remove nil?)) min ##Inf selrects) (when (d/not-empty? selrects)
miny (transduce (comp (map :y1) (remove nil?)) min ##Inf selrects) (let [minx (transduce (keep :x1) min ##Inf selrects)
maxx (transduce (comp (map :x2) (remove nil?)) max ##-Inf selrects) miny (transduce (keep :y1) min ##Inf selrects)
maxy (transduce (comp (map :y2) (remove nil?)) max ##-Inf selrects)] maxx (transduce (keep :x2) max ##-Inf selrects)
{:x minx maxy (transduce (keep :y2) max ##-Inf selrects)]
:y miny (when (d/num? minx miny maxx maxy)
:x1 minx (make-selrect minx miny (- maxx minx) (- maxy miny))))))
:y1 miny
:x2 maxx
:y2 maxy
:width (- maxx minx)
:height (- maxy miny)}))
(defn center->rect [center width height] (defn center->rect [{:keys [x y]} width height]
(assert (gpt/point center)) (when (d/num? x y width height)
(assert (and (number? width) (> width 0))) (make-rect (- x (/ width 2))
(assert (and (number? height) (> height 0))) (- y (/ height 2))
width
height)))
{:x (- (:x center) (/ width 2)) (defn center->selrect [{:keys [x y]} width height]
:y (- (:y center) (/ height 2)) (when (d/num? x y width height)
:width width (make-selrect (- x (/ width 2))
:height height}) (- y (/ height 2))
width
height)))
(defn s= (defn s=
[a b] [a b]

View file

@ -251,7 +251,7 @@
;; to have this width, height, x, y ;; to have this width, height, x, y
new-width (max 0.01 (:width points-temp-dim)) new-width (max 0.01 (:width points-temp-dim))
new-height (max 0.01 (:height points-temp-dim)) new-height (max 0.01 (:height points-temp-dim))
selrect (gco/make-centered-selrect center new-width new-height) selrect (gpr/center->selrect center new-width new-height)
rect-points (gpr/rect->points selrect) rect-points (gpr/rect->points selrect)
[matrix matrix-inverse] (calculate-adjust-matrix points-temp rect-points flip-x flip-y)] [matrix matrix-inverse] (calculate-adjust-matrix points-temp rect-points flip-x flip-y)]

View file

@ -395,8 +395,8 @@
srect (gsh/selection-rect shapes) srect (gsh/selection-rect shapes)
local (assoc local :vport size :zoom 1)] local (assoc local :vport size :zoom 1)]
(cond (cond
(or (not (mth/finite? (:width srect))) (or (not (d/num? (:width srect)))
(not (mth/finite? (:height srect)))) (not (d/num? (:height srect))))
(assoc local :vbox (assoc size :x 0 :y 0)) (assoc local :vbox (assoc size :x 0 :y 0))
(or (> (:width srect) width) (or (> (:width srect) width)

View file

@ -32,9 +32,7 @@
(defonce default-image {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0}) (defonce default-image {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0})
(defn- assert-valid-num [attr num] (defn- assert-valid-num [attr num]
(when (or (nil? num) (when (or (not (d/num? num))
(mth/nan? num)
(not (mth/finite? num))
(>= num max-safe-int ) (>= num max-safe-int )
(<= num min-safe-int)) (<= num min-safe-int))
(ex/raise (str (d/name attr) " attribute invalid: " num))) (ex/raise (str (d/name attr) " attribute invalid: " num)))
@ -229,14 +227,9 @@
(let [points (-> (gsh/rect->points rect-data) (let [points (-> (gsh/rect->points rect-data)
(gsh/transform-points transform)) (gsh/transform-points transform))
center (gsh/center-points points) center (gsh/center-points points)
rect-shape (gsh/center->rect center (:width rect-data) (:height rect-data))
rect-shape (-> (gsh/make-centered-rect center (:width rect-data) (:height rect-data)) selrect (gsh/rect->selrect rect-shape)
(update :width max 1)
(update :height max 1))
selrect (gsh/rect->selrect rect-shape)
rect-points (gsh/rect->points rect-shape) rect-points (gsh/rect->points rect-shape)
[shape-transform shape-transform-inv rotation] [shape-transform shape-transform-inv rotation]

View file

@ -181,9 +181,12 @@
:ignore-tree ignore-tree :ignore-tree ignore-tree
;; Attributes that can change in the transform. This way we don't have to check ;; Attributes that can change in the transform. This way we don't have to check
;; all the attributes ;; all the attributes
:attrs [:selrect :points :attrs [:selrect
:x :y :points
:width :height :x
:y
:width
:height
:content :content
:transform :transform
:transform-inverse :transform-inverse

View file

@ -59,15 +59,14 @@
(defn- calculate-dimensions (defn- calculate-dimensions
[{:keys [objects] :as data} vport] [{:keys [objects] :as data} vport]
(let [shapes (cph/get-immediate-children objects) (let [shapes (cph/get-immediate-children objects)
to-finite (fn [val fallback] (if (not (mth/finite? val)) fallback val))
rect (cond->> (gsh/selection-rect shapes) rect (cond->> (gsh/selection-rect shapes)
(some? vport) (some? vport)
(gal/adjust-to-viewport vport))] (gal/adjust-to-viewport vport))]
(-> rect (-> rect
(update :x to-finite 0) (update :x mth/finite 0)
(update :y to-finite 0) (update :y mth/finite 0)
(update :width to-finite 100000) (update :width mth/finite 100000)
(update :height to-finite 100000)))) (update :height mth/finite 100000))))
(declare shape-wrapper-factory) (declare shape-wrapper-factory)

View file

@ -195,7 +195,7 @@
snap-list (d/concat-vec lt-snap gt-snap between-snap) snap-list (d/concat-vec lt-snap gt-snap between-snap)
min-snap (reduce best-snap ##Inf snap-list)] min-snap (reduce best-snap ##Inf snap-list)]
(if (mth/finite? min-snap) [0 min-snap] nil))) (if (d/num? min-snap) [0 min-snap] nil)))
(defn search-snap-distance [selrect coord shapes-lt shapes-gt zoom] (defn search-snap-distance [selrect coord shapes-lt shapes-gt zoom]
(->> (rx/combine-latest shapes-lt shapes-gt) (->> (rx/combine-latest shapes-lt shapes-gt)

View file

@ -28,10 +28,6 @@
min-val (get params :min) min-val (get params :min)
max-val (get params :max) max-val (get params :max)
num? (fn [val] (and (number? val)
(not (mth/nan? val))
(mth/finite? val)))
emit-blur? (mf/use-ref nil) emit-blur? (mf/use-ref nil)
font-size-wrapper-ref (mf/use-ref) font-size-wrapper-ref (mf/use-ref)
@ -103,8 +99,8 @@
new-value (+ value increment) new-value (+ value increment)
new-value (cond new-value (cond
(and (num? min-val) (< new-value min-val)) min-val (and (d/num? min-val) (< new-value min-val)) min-val
(and (num? max-val) (> new-value max-val)) max-val (and (d/num? max-val) (> new-value max-val)) max-val
:else new-value)] :else new-value)]
(set-value new-value))))))) (set-value new-value)))))))

View file

@ -6,9 +6,9 @@
(ns app.main.ui.components.numeric-input (ns app.main.ui.components.numeric-input
(:require (:require
[app.main.ui.formats :as fmt]
[app.common.data :as d] [app.common.data :as d]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.ui.formats :as fmt]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.globals :as globals] [app.util.globals :as globals]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
@ -18,11 +18,6 @@
[rumext.alpha :as mf]) [rumext.alpha :as mf])
(:import goog.events.EventType)) (:import goog.events.EventType))
(defn num? [val]
(and (number? val)
(not (mth/nan? val))
(mth/finite? val)))
(mf/defc numeric-input (mf/defc numeric-input
{::mf/wrap-props false {::mf/wrap-props false
::mf/forward-ref true} ::mf/forward-ref true}
@ -81,15 +76,15 @@
(let [input-node (mf/ref-val ref) (let [input-node (mf/ref-val ref)
new-value (-> (dom/get-value input-node) new-value (-> (dom/get-value input-node)
(sm/expr-eval value))] (sm/expr-eval value))]
(when (num? new-value) (when (d/num? new-value)
(-> new-value (-> new-value
(cljs.core/max us/min-safe-int) (cljs.core/max us/min-safe-int)
(cljs.core/min us/max-safe-int) (cljs.core/min us/max-safe-int)
(cond-> (cond->
(num? min-val) (d/num? min-val)
(cljs.core/max min-val) (cljs.core/max min-val)
(num? max-val) (d/num? max-val)
(cljs.core/min max-val))))))) (cljs.core/min max-val)))))))
update-input update-input
@ -120,18 +115,18 @@
new-value (+ current-value increment) new-value (+ current-value increment)
new-value (cond new-value (cond
(and wrap-value? (num? max-val) (num? min-val) (and wrap-value? (d/num? max-val min-val)
(> new-value max-val) up?) (> new-value max-val) up?)
(-> new-value (- max-val) (+ min-val) (- step-val)) (-> new-value (- max-val) (+ min-val) (- step-val))
(and wrap-value? (num? min-val) (num? max-val) (and wrap-value? (d/num? max-val min-val)
(< new-value min-val) down?) (< new-value min-val) down?)
(-> new-value (- min-val) (+ max-val) (+ step-val)) (-> new-value (- min-val) (+ max-val) (+ step-val))
(and (num? min-val) (< new-value min-val)) (and (d/num? min-val) (< new-value min-val))
min-val min-val
(and (num? max-val) (> new-value max-val)) (and (d/num? max-val) (> new-value max-val))
max-val max-val
:else new-value)] :else new-value)]

View file

@ -7,6 +7,7 @@
(ns app.main.ui.workspace.viewport.gradients (ns app.main.ui.workspace.viewport.gradients
"Gradients handlers and renders" "Gradients handlers and renders"
(:require (:require
[app.common.data :as d]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
@ -300,7 +301,7 @@
(let [scale-factor-y (/ gradient-length (/ height 2)) (let [scale-factor-y (/ gradient-length (/ height 2))
norm-dist (/ (gpt/distance point from-p) norm-dist (/ (gpt/distance point from-p)
(* (/ width 2) scale-factor-y))] (* (/ width 2) scale-factor-y))]
(when (and norm-dist (mth/finite? norm-dist)) (when (and norm-dist (d/num? norm-dist))
(change! {:width norm-dist})))))] (change! {:width norm-dist})))))]
(when (and gradient (when (and gradient

View file

@ -7,7 +7,6 @@
(ns app.main.ui.workspace.viewport.scroll-bars (ns app.main.ui.workspace.viewport.scroll-bars
(:require (:require
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.rect :as gpr]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.store :as st] [app.main.store :as st]
@ -169,7 +168,7 @@
:y2 (+ vbox-y (:height vbox)) :y2 (+ vbox-y (:height vbox))
:width (:width vbox) :width (:width vbox)
:height (:height vbox)} :height (:height vbox)}
containing-rect (gpr/join-selrects [base-objects-rect vbox-rect]) containing-rect (gsh/join-selrects [base-objects-rect vbox-rect])
height-factor (/ (:height containing-rect) vbox-height) height-factor (/ (:height containing-rect) vbox-height)
width-factor (/ (:width containing-rect) vbox-width)] width-factor (/ (:width containing-rect) vbox-width)]
(mf/set-ref-val! start-ref start-pt) (mf/set-ref-val! start-ref start-pt)

View file

@ -6,6 +6,7 @@
(ns app.util.geom.grid (ns app.util.geom.grid
(:require (:require
[app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.math :as mth])) [app.common.math :as mth]))
@ -39,7 +40,7 @@
gutter (if (= :stretch type) gutter (if (= :stretch type)
(let [gutter (/ (- width (* width' size) (* margin 2)) (dec size))] (let [gutter (/ (- width (* width' size) (* margin 2)) (dec size))]
(if (mth/finite? gutter) gutter 0)) (if (d/num? gutter) gutter 0))
gutter) gutter)
next-v (fn [cur-val] next-v (fn [cur-val]