🐛 Improvements over grid precision

This commit is contained in:
alonso.torres 2020-09-17 18:21:41 +02:00 committed by Andrey Antukh
parent 3a1618451c
commit 9755516178
2 changed files with 17 additions and 15 deletions

View file

@ -63,7 +63,7 @@
:page-id page-id :page-id page-id
:frame-id frame-id :frame-id frame-id
:coord coord :coord coord
:ranges [[value value]]}) :ranges [[(- value 0.5) (+ value 0.5)]]})
(rx/first) (rx/first)
(rx/map (remove-from-snap-points filter-shapes)) (rx/map (remove-from-snap-points filter-shapes))
(rx/map flatten-to-points)))) (rx/map flatten-to-points))))

View file

@ -11,6 +11,7 @@
(:require (:require
[rumext.alpha :as mf] [rumext.alpha :as mf]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.util.geom.grid :as gg])) [app.util.geom.grid :as gg]))
@ -24,19 +25,19 @@
[:* [:*
(for [xs (range size frame-width size)] (for [xs (range size frame-width size)]
[:line {:key (str (:id frame) "-y-" xs) [:line {:key (str (:id frame) "-y-" xs)
:x1 (+ x xs) :x1 (mth/round (+ x xs))
:y1 y :y1 (mth/round y)
:x2 (+ x xs) :x2 (mth/round (+ x xs))
:y2 (+ y frame-height) :y2 (mth/round (+ y frame-height))
:style {:stroke color-value :style {:stroke color-value
:stroke-opacity color-opacity :stroke-opacity color-opacity
:stroke-width (str (/ 1 zoom))}}]) :stroke-width (str (/ 1 zoom))}}])
(for [ys (range size frame-height size)] (for [ys (range size frame-height size)]
[:line {:key (str (:id frame) "-x-" ys) [:line {:key (str (:id frame) "-x-" ys)
:x1 x :x1 (mth/round x)
:y1 (+ y ys) :y1 (mth/round (+ y ys))
:x2 (+ x frame-width) :x2 (mth/round (+ x frame-width))
:y2 (+ y ys) :y2 (mth/round (+ y ys))
:style {:stroke color-value :style {:stroke color-value
:stroke-opacity color-opacity :stroke-opacity color-opacity
:stroke-width (str (/ 1 zoom))}}])]]))) :stroke-width (str (/ 1 zoom))}}])]])))
@ -54,12 +55,13 @@
:fill "transparent"})] :fill "transparent"})]
[:g.grid [:g.grid
(for [{:keys [x y width height]} (gg/grid-areas frame grid)] (for [{:keys [x y width height]} (gg/grid-areas frame grid)]
[:rect {:key (str key "-" x "-" y) (do
:x x [:rect {:key (str key "-" x "-" y)
:y y :x (mth/round x)
:width width :y (mth/round y)
:height height :width (- (mth/round (+ x width)) (mth/round x))
:style style}])])) :height (- (mth/round (+ y height)) (mth/round y))
:style style}]))]))
(mf/defc grid-display-frame [{:keys [frame zoom]}] (mf/defc grid-display-frame [{:keys [frame zoom]}]
(let [grids (:grids frame)] (let [grids (:grids frame)]