Skip to content

Commit 714bc24

Browse files
author
Jonas Treub
committed
Improve color equality
1 parent bfaf154 commit 714bc24

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

framer/Color.coffee

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,12 @@ class exports.Color extends BaseClass
303303
colorA = new Color(colorA)
304304
colorB = new Color(colorB)
305305

306-
return false if Math.round(colorA.r) isnt Math.round(colorB.r)
307-
return false if Math.round(colorA.g) isnt Math.round(colorB.g)
308-
return false if Math.round(colorA.b) isnt Math.round(colorB.b)
309-
return false if Math.round(colorA.a) isnt Math.round(colorB.a)
306+
tolerance = 1
307+
alphaTolerance = 0.01
308+
return false if Math.abs(colorA.r - colorB.r) >= tolerance
309+
return false if Math.abs(colorA.g - colorB.g) >= tolerance
310+
return false if Math.abs(colorA.b - colorB.b) >= tolerance
311+
return false if Math.abs(colorA.a - colorB.a) >= alphaTolerance
310312
return true
311313

312314
@rgbToHsl: (a, b, c) ->

0 commit comments

Comments
 (0)