Example #1
0
def test_nearest_on_square_distance():
    kd = color_kd._build([
        (Color(50, 50, 50), 255),
        (Color(50, 51, 50), 254),
    ])
    assert color_kd.nearest(Color(0, 0, 0), kd) == 255
    assert color_kd.nearest(Color(52, 52, 52), kd) == 254
Example #2
0
 def init_color(self, color: Color) -> None:
     if curses.can_change_color():
         n = min(self.colors.values(), default=256) - 1
         self.colors[color] = n
         curses.init_color(n, *_color_to_curses(color))
     elif curses.COLORS >= 256:
         self.colors[color] = color_kd.nearest(color, color_kd.make_256())
     else:
         self.colors[color] = -1
Example #3
0
def test_smoke_kd_256():
    kd_256 = color_kd.make_256()
    assert color_kd.nearest(Color(0, 0, 0), kd_256) == 16
    assert color_kd.nearest(Color(0x1e, 0x77, 0xd3), kd_256) == 32
Example #4
0
def test_nearest_one_node():
    kd = color_kd._build([(Color(100, 100, 100), 99)])
    assert color_kd.nearest(Color(0, 0, 0), kd) == 99
Example #5
0
def test_nearest_trivial():
    assert color_kd.nearest(Color(0, 0, 0), None) == 0