mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
🐛 Add better nil handling in interpolate-gradient when offset exceeds stops
When no gradient stop satisfies (<= offset (:offset %)), d/index-of-pred returns nil. The previous code called (dec nil) in the start binding before the nil check, throwing a NullPointerException/ClassCastException. Guard the start binding with a cond that handles nil before attempting dec. Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
7b0ea5968d
commit
08ca561667
@ -720,8 +720,10 @@
|
|||||||
|
|
||||||
(defn- offset-spread
|
(defn- offset-spread
|
||||||
[from to num]
|
[from to num]
|
||||||
(->> (range 0 num)
|
(if (<= num 1)
|
||||||
(map #(mth/precision (+ from (* (/ (- to from) (dec num)) %)) 2))))
|
[from]
|
||||||
|
(->> (range 0 num)
|
||||||
|
(map #(mth/precision (+ from (* (/ (- to from) (dec num)) %)) 2)))))
|
||||||
|
|
||||||
(defn uniform-spread?
|
(defn uniform-spread?
|
||||||
"Checks if the gradient stops are spread uniformly"
|
"Checks if the gradient stops are spread uniformly"
|
||||||
@ -750,6 +752,9 @@
|
|||||||
(defn interpolate-gradient
|
(defn interpolate-gradient
|
||||||
[stops offset]
|
[stops offset]
|
||||||
(let [idx (d/index-of-pred stops #(<= offset (:offset %)))
|
(let [idx (d/index-of-pred stops #(<= offset (:offset %)))
|
||||||
start (if (= idx 0) (first stops) (get stops (dec idx)))
|
start (cond
|
||||||
|
(nil? idx) (last stops)
|
||||||
|
(= idx 0) (first stops)
|
||||||
|
:else (get stops (dec idx)))
|
||||||
end (if (nil? idx) (last stops) (get stops idx))]
|
end (if (nil? idx) (last stops) (get stops idx))]
|
||||||
(interpolate-color start end offset)))
|
(interpolate-color start end offset)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user