Skip to content

Commit c3d5c7b

Browse files
committed
Color: rename diff() to distance()
1 parent b68675d commit c3d5c7b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

autoload/vital/__vital__/Color.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ function! s:Color.eq(color) abort
2222
return self.as_rgb() ==# a:color.as_rgb()
2323
endfunction
2424

25-
function! s:Color.diff(color) abort
25+
function! s:Color.distance(color) abort
2626
let [r1, g1, b1] = self.as_rgb()
2727
let [r2, g2, b2] = a:color.as_rgb()
28-
return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)
28+
return sqrt(pow(r1 - r2, 2) + pow(g1 - g2, 2) + pow(b1 - b2, 2))
2929
endfunction
3030

3131
let s:RGB = deepcopy(s:Color)

test/Color.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ function! s:suite.eq() abort
6666
endfor
6767
endfunction
6868

69-
function! s:suite.diff() abort
69+
function! s:suite.distance() abort
7070
for [l, r] in [
7171
\ [s:C.parse('#abcdef'), s:C.parse('hsl(210, 68%, 80%)')],
7272
\ [s:C.parse('#012'), s:C.parse('hsl(210, 100%, 7%)')],
7373
\ [s:C.parse('#deadbe'), s:C.parse('rgb('.0xDE.','.0xAD.','.0xBE.')')],
7474
\]
75-
call s:assert.compare(l.diff(r), '<', 5, l.as_rgb_hex() . ' diff ' . r.as_rgb_hex())
76-
call s:assert.compare(r.diff(l), '<', 5, r.as_rgb_hex() . ' diff ' . l.as_rgb_hex())
75+
call s:assert.compare(l.distance(r), '<', 3, l.as_rgb_hex() . ' distance ' . r.as_rgb_hex())
76+
call s:assert.compare(r.distance(l), '<', 3, r.as_rgb_hex() . ' distance ' . l.as_rgb_hex())
7777
endfor
7878
endfunction

0 commit comments

Comments
 (0)