💄 Add minor cosmetic improvements to geom shape pixel precision code

This commit is contained in:
Andrey Antukh 2023-06-20 11:41:10 +02:00
parent 0e513f950a
commit 4d3064ba6d

View file

@ -8,6 +8,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.rect :as grc] [app.common.geom.rect :as grc]
[app.common.geom.shapes.common :as gco] [app.common.geom.shapes.common :as gco]
@ -23,20 +24,24 @@
curr-width (gpo/width-points points) curr-width (gpo/width-points points)
curr-height (gpo/height-points points) curr-height (gpo/height-points points)
[_ transform transform-inverse] (gtr/calculate-geometry points) center (gco/points->center points)
selrect (gtr/calculate-selrect points center)
transform (gtr/calculate-transform points center selrect)
transform-inverse (when (some? transform) (gmt/inverse transform))
path? (cph/path-shape? shape) path? (cph/path-shape? shape)
vertical-line? (and path? (<= curr-width 0.01)) vertical-line? (and path? (<= curr-width 0.01))
horizontal-line? (and path? (<= curr-height 0.01)) horizontal-line? (and path? (<= curr-height 0.01))
target-width (if vertical-line? curr-width (max 1 (mth/round curr-width precision))) target-width (if vertical-line? curr-width (mth/max 1 (mth/round curr-width precision)))
target-height (if horizontal-line? curr-height (max 1 (mth/round curr-height precision))) target-height (if horizontal-line? curr-height (mth/max 1 (mth/round curr-height precision)))
ratio-width (/ target-width curr-width) ratio-width (/ target-width curr-width)
ratio-height (/ target-height curr-height) ratio-height (/ target-height curr-height)
scalev (gpt/point ratio-width ratio-height)] scalev (gpt/point ratio-width ratio-height)]
(-> modifiers
(ctm/resize scalev origin transform transform-inverse {:precise? true})))) (ctm/resize modifiers scalev origin transform transform-inverse {:precise? true})))
(defn position-pixel-precision (defn position-pixel-precision
[modifiers _ points precision ignore-axis] [modifiers _ points precision ignore-axis]