Skip to content

Commit a8bba4b

Browse files
leifericfclaude
andcommitted
Fix keyword color support in compile/lower and distribution edge cases
- compile.clj node->fill-descriptor: handle keyword fills (:red) in addition to vector fills, fixing crash when keywords meet effects - lower.clj inherit-fill: same keyword support for inherited fills - prob.clj Pareto sampling: add 10000-iteration guard to prevent infinite loop when :max <= :min - prob.clj triangular distribution: return min when min == max instead of dividing by zero Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ab7011d commit a8bba4b

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/eido/engine/compile.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
(nil? fill) nil
338338
(and (map? fill) (#{:hatch :stipple} (:fill/type fill))) fill
339339
(and (map? fill) (= :pattern (:fill/type fill))) fill
340-
(vector? fill) {:fill/type :fill/solid :color fill}
340+
(or (vector? fill) (keyword? fill)) {:fill/type :fill/solid :color fill}
341341
(:gradient/type fill) (merge {:fill/type :fill/gradient} fill)
342342
(:color fill) {:fill/type :fill/solid :color (:color fill)}
343343
:else fill))

src/eido/gen/prob.clj

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,25 @@
136136
mx (:max spec)]
137137
(if mx
138138
(let [mx (double mx)]
139-
(loop []
140-
(let [v (* mn (Math/pow (- 1.0 (.nextDouble rng))
141-
(/ -1.0 alpha)))]
142-
(if (<= v mx) v (recur)))))
139+
(loop [tries 0]
140+
(if (>= tries 10000)
141+
mn
142+
(let [v (* mn (Math/pow (- 1.0 (.nextDouble rng))
143+
(/ -1.0 alpha)))]
144+
(if (<= v mx) v (recur (inc tries)))))))
143145
(* mn (Math/pow (- 1.0 (.nextDouble rng))
144146
(/ -1.0 alpha)))))
145147
:triangular (let [rng (make-rng seed)
146148
mn (double (:min spec))
147149
mx (double (:max spec))
148-
mode (double (:mode spec))
149-
u (.nextDouble rng)
150-
fc (/ (- mode mn) (- mx mn))]
151-
(if (< u fc)
152-
(+ mn (Math/sqrt (* u (- mx mn) (- mode mn))))
153-
(- mx (Math/sqrt (* (- 1.0 u) (- mx mn) (- mx mode))))))
150+
mode (double (:mode spec))]
151+
(if (== mn mx)
152+
mn
153+
(let [u (.nextDouble rng)
154+
fc (/ (- mode mn) (- mx mn))]
155+
(if (< u fc)
156+
(+ mn (Math/sqrt (* u (- mx mn) (- mode mn))))
157+
(- mx (Math/sqrt (* (- 1.0 u) (- mx mn) (- mx mode))))))))
154158
:eased (let [rng (make-rng seed)
155159
easing (:easing spec)
156160
lo (double (get spec :lo 0))

src/eido/ir/lower.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@
271271
(let [fill (:style/fill ctx-style)]
272272
(assoc item :item/fill
273273
(cond
274-
(vector? fill) {:fill/type :fill/solid :color fill}
274+
(or (vector? fill)
275+
(keyword? fill)) {:fill/type :fill/solid :color fill}
275276
(:gradient/type fill) (merge {:fill/type :fill/gradient} fill)
276277
(:color fill) {:fill/type :fill/solid :color (:color fill)}
277278
:else fill)))

0 commit comments

Comments
 (0)