Fix segment param naming on path type helpers

This commit is contained in:
Andrey Antukh 2025-04-08 22:07:25 +02:00
parent 753823c0b3
commit db73c2eea0
2 changed files with 38 additions and 38 deletions

View file

@ -128,19 +128,19 @@
(get params :y)))))) (get params :y))))))
(defn command->line (defn command->line
([cmd] ([segment]
(command->line cmd (:prev cmd))) (command->line segment (:prev segment)))
([cmd prev] ([segment prev]
[prev (command->point cmd)])) [prev (command->point segment)]))
(defn command->bezier (defn command->bezier
([cmd] ([segment]
(command->bezier cmd (:prev cmd))) (command->bezier segment (:prev segment)))
([cmd prev] ([segment prev]
[prev [prev
(command->point cmd) (command->point segment)
(gpt/point (-> cmd :params :c1x) (-> cmd :params :c1y)) (gpt/point (-> segment :params :c1x) (-> segment :params :c1y))
(gpt/point (-> cmd :params :c2x) (-> cmd :params :c2y))])) (gpt/point (-> segment :params :c2x) (-> segment :params :c2y))]))
(declare curve-extremities) (declare curve-extremities)
(declare curve-values) (declare curve-values)
@ -447,16 +447,16 @@
(defn split-line-to (defn split-line-to
"Given a point and a line-to command will create a two new line-to commands "Given a point and a line-to command will create a two new line-to commands
that will split the original line into two given a value between 0-1" that will split the original line into two given a value between 0-1"
[from-p cmd t-val] [from-p segment t-val]
(let [to-p (command->point cmd) (let [to-p (command->point segment)
sp (gpt/lerp from-p to-p t-val)] sp (gpt/lerp from-p to-p t-val)]
[(make-line-to sp) cmd])) [(make-line-to sp) segment]))
(defn split-curve-to (defn split-curve-to
"Given the point and a curve-to command will split the curve into two new "Given the point and a curve-to command will split the curve into two new
curve-to commands given a value between 0-1" curve-to commands given a value between 0-1"
[from-p cmd t-val] [from-p segment t-val]
(let [params (:params cmd) (let [params (:params segment)
end (gpt/point (:x params) (:y params)) end (gpt/point (:x params) (:y params))
h1 (gpt/point (:c1x params) (:c1y params)) h1 (gpt/point (:c1x params) (:c1y params))
h2 (gpt/point (:c2x params) (:c2y params)) h2 (gpt/point (:c2x params) (:c2y params))
@ -484,11 +484,11 @@
"Splits a line into several lines given the points in `values` "Splits a line into several lines given the points in `values`
for example (split-line-to-ranges p c [0 0.25 0.5 0.75 1] will split for example (split-line-to-ranges p c [0 0.25 0.5 0.75 1] will split
the line into 4 lines" the line into 4 lines"
[from-p cmd values] [from-p segment values]
(let [values (->> values (filter #(and (> % 0) (< % 1))))] (let [values (->> values (filter #(and (> % 0) (< % 1))))]
(if (empty? values) (if (empty? values)
[cmd] [segment]
(let [to-p (command->point cmd) (let [to-p (command->point segment)
values-set (->> (conj values 1) (into (sorted-set)))] values-set (->> (conj values 1) (into (sorted-set)))]
(->> values-set (->> values-set
(mapv (fn [val] (mapv (fn [val]
@ -500,13 +500,13 @@
"Splits a curve into several curves given the points in `values` "Splits a curve into several curves given the points in `values`
for example (split-curve-to-ranges p c [0 0.25 0.5 0.75 1] will split for example (split-curve-to-ranges p c [0 0.25 0.5 0.75 1] will split
the curve into 4 curves that draw the same curve" the curve into 4 curves that draw the same curve"
[from-p cmd values] [from-p segment values]
(let [values (->> values (filter #(and (> % 0) (< % 1))))] (let [values (->> values (filter #(and (> % 0) (< % 1))))]
(if (empty? values) (if (empty? values)
[cmd] [segment]
(let [to-p (command->point cmd) (let [to-p (command->point segment)
params (:params cmd) params (:params segment)
h1 (gpt/point (:c1x params) (:c1y params)) h1 (gpt/point (:c1x params) (:c1y params))
h2 (gpt/point (:c2x params) (:c2y params)) h2 (gpt/point (:c2x params) (:c2y params))
@ -812,10 +812,10 @@
(defn is-point-in-border? (defn is-point-in-border?
[point content] [point content]
(letfn [(inside-border? [cmd] (letfn [(inside-border? [segment]
(case (:command cmd) (case (:command segment)
:line-to (segment-has-point? point (command->line cmd)) :line-to (segment-has-point? point (command->line segment))
:curve-to (curve-has-point? point (command->bezier cmd)) :curve-to (curve-has-point? point (command->bezier segment))
#_:else false))] #_:else false))]
(some inside-border? content))) (some inside-border? content)))

View file

@ -135,15 +135,15 @@
;;content-b-split (->> content-b-split #_(filter #(path.bool/contains-segment? % content-a sr-a content-a-geom))) ;;content-b-split (->> content-b-split #_(filter #(path.bool/contains-segment? % content-a sr-a content-a-geom)))
] ]
[:* [:*
(for [[i cmd] (d/enumerate content-a-split)] (for [[i segment] (d/enumerate content-a-split)]
(let [p1 (:prev cmd) (let [p1 (:prev segment)
p2 (path.helpers/command->point cmd) p2 (path.helpers/segment->point segment)
hp (case (:command cmd) hp (case (:command segment)
:line-to (-> (path.helpers/command->line cmd) :line-to (-> (path.helpers/command->line segment)
(path.helpers/line-values 0.5)) (path.helpers/line-values 0.5))
:curve-to (-> (path.helpers/command->bezier cmd) :curve-to (-> (path.helpers/command->bezier segment)
(path.helpers/curve-values 0.5)) (path.helpers/curve-values 0.5))
nil)] nil)]
[:* [:*
@ -154,15 +154,15 @@
(when hp (when hp
[:circle {:data-i i :key (dm/str "c13-" i) :cx (:x hp) :cy (:y hp) :r radius :fill "orange"}])])) [:circle {:data-i i :key (dm/str "c13-" i) :cx (:x hp) :cy (:y hp) :r radius :fill "orange"}])]))
(for [[i cmd] (d/enumerate content-b-split)] (for [[i segment] (d/enumerate content-b-split)]
(let [p1 (:prev cmd) (let [p1 (:prev segment)
p2 (path.helpers/command->point cmd) p2 (path.helpers/segment->point segment)
hp (case (:command cmd) hp (case (:command segment)
:line-to (-> (path.helpers/command->line cmd) :line-to (-> (path.helpers/command->line segment)
(path.helpers/line-values 0.5)) (path.helpers/line-values 0.5))
:curve-to (-> (path.helpers/command->bezier cmd) :curve-to (-> (path.helpers/command->bezier segment)
(path.helpers/curve-values 0.5)) (path.helpers/curve-values 0.5))
nil)] nil)]
[:* [:*