mirror of
https://github.com/penpot/penpot.git
synced 2025-01-26 00:19:07 -05:00
🐛 Fixes distance alignment
This commit is contained in:
parent
3bb4fcb28f
commit
55c92da286
2 changed files with 22 additions and 16 deletions
|
@ -159,9 +159,10 @@
|
||||||
|
|
||||||
(defn closest-distance-snap
|
(defn closest-distance-snap
|
||||||
[page-id shapes objects movev]
|
[page-id shapes objects movev]
|
||||||
(->> (rx/of shapes)
|
(let [frame-id (snap-frame-id shapes)
|
||||||
(rx/map #(vector (->> % first :frame-id (get objects))
|
frame (get objects frame-id)
|
||||||
(-> % gsh/selection-rect (gsh/move movev))))
|
selrect (->> shapes (map #(gsh/move % movev)) gsh/selection-rect)]
|
||||||
|
(->> (rx/of (vector frame selrect))
|
||||||
(rx/merge-map
|
(rx/merge-map
|
||||||
(fn [[frame selrect]]
|
(fn [[frame selrect]]
|
||||||
(let [areas (->> (gsh/selrect->areas (or (:selrect frame)
|
(let [areas (->> (gsh/selrect->areas (or (:selrect frame)
|
||||||
|
@ -169,7 +170,7 @@
|
||||||
(d/mapm #(select-shapes-area page-id shapes objects %2)))
|
(d/mapm #(select-shapes-area page-id shapes objects %2)))
|
||||||
snap-x (search-snap-distance selrect :x (:left areas) (:right areas))
|
snap-x (search-snap-distance selrect :x (:left areas) (:right areas))
|
||||||
snap-y (search-snap-distance selrect :y (:top areas) (:bottom areas))]
|
snap-y (search-snap-distance selrect :y (:top areas) (:bottom areas))]
|
||||||
(rx/combine-latest snap->vector snap-y snap-x))))))
|
(rx/combine-latest snap->vector snap-y snap-x)))))))
|
||||||
|
|
||||||
(defn closest-snap-point
|
(defn closest-snap-point
|
||||||
[page-id shapes layout point]
|
[page-id shapes layout point]
|
||||||
|
|
|
@ -176,7 +176,7 @@
|
||||||
check-in-set
|
check-in-set
|
||||||
(fn [value number-set]
|
(fn [value number-set]
|
||||||
(->> number-set
|
(->> number-set
|
||||||
(some #(<= (mth/abs (- value %)) 0.5))))
|
(some #(<= (mth/abs (- value %)) 1))))
|
||||||
|
|
||||||
;; Left/Top shapes and right/bottom shapes (depends on `coord` parameter
|
;; Left/Top shapes and right/bottom shapes (depends on `coord` parameter
|
||||||
[lt-shapes gt-shapes] @to-measure
|
[lt-shapes gt-shapes] @to-measure
|
||||||
|
@ -185,7 +185,6 @@
|
||||||
lt-distances (->> lt-shapes (map distance-to-selrect) (filter pos?) (into #{}))
|
lt-distances (->> lt-shapes (map distance-to-selrect) (filter pos?) (into #{}))
|
||||||
gt-distances (->> gt-shapes (map distance-to-selrect) (filter pos?) (into #{}))
|
gt-distances (->> gt-shapes (map distance-to-selrect) (filter pos?) (into #{}))
|
||||||
|
|
||||||
|
|
||||||
;; We'll show the distances that match a distance from the selrect
|
;; We'll show the distances that match a distance from the selrect
|
||||||
show-candidate? #(check-in-set % (set/union lt-distances gt-distances))
|
show-candidate? #(check-in-set % (set/union lt-distances gt-distances))
|
||||||
|
|
||||||
|
@ -193,11 +192,17 @@
|
||||||
distance-coincidences (concat (get-shapes-match show-candidate? lt-shapes)
|
distance-coincidences (concat (get-shapes-match show-candidate? lt-shapes)
|
||||||
(get-shapes-match show-candidate? gt-shapes))
|
(get-shapes-match show-candidate? gt-shapes))
|
||||||
|
|
||||||
|
|
||||||
;; Show the distances that either match one of the distances from the selrect
|
;; Show the distances that either match one of the distances from the selrect
|
||||||
;; or are from the selrect and go to a shape on the left and to the right
|
;; or are from the selrect and go to a shape on the left and to the right
|
||||||
show-distance? #(check-in-set % (into #{} (concat
|
show-distance?
|
||||||
(map first distance-coincidences)
|
(fn [dist]
|
||||||
(set/intersection lt-distances gt-distances))))
|
(let [distances-to-show
|
||||||
|
(->> (d/concat (mapv first distance-coincidences)
|
||||||
|
(filterv #(check-in-set % lt-distances) gt-distances)
|
||||||
|
(filterv #(check-in-set % gt-distances) lt-distances))
|
||||||
|
(into #{}))]
|
||||||
|
(check-in-set dist distances-to-show)))
|
||||||
|
|
||||||
;; These are the segments whose distance will be displayed
|
;; These are the segments whose distance will be displayed
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue