@@ -39,36 +39,55 @@ def test_display_frame_creates_window_and_updates(headless_display_env):
3939 env .tk .update .assert_called_once_with ()
4040
4141
42- def test_display_draws_only_points_above_cutoff (headless_display_env , monkeypatch ):
42+ def test_display_draws_only_points_above_cutoff_with_clamping (
43+ headless_display_env , monkeypatch
44+ ):
4345 env = headless_display_env
4446 display_mod = env .mod
4547 disp = display_mod .Display (radius = 3 , pcutoff = 0.5 )
48+ r = disp .radius
4649
47- # Patch colormap so color sampling is deterministic and always long enough
50+ # Fake colors
4851 class FakeCC :
49- bmy = [(1 , 0 , 0 ), (0 , 1 , 0 ), (0 , 0 , 1 ), ( 1 , 1 , 0 ) ]
52+ bmy = [(1 , 0 , 0 ), (0 , 1 , 0 ), (0 , 0 , 1 )]
5053
5154 monkeypatch .setattr (display_mod , "cc" , FakeCC )
5255
53- frame = np .zeros ((100 , 100 , 3 ), dtype = np .uint8 )
56+ frame = np .zeros ((50 , 50 , 3 ), dtype = np .uint8 )
57+ h , w = frame .shape [:2 ]
58+
5459 pose = np .array (
5560 [
5661 [
57- [10 , 10 , 0.9 ], # draw
58- [20 , 20 , 0.49 ], # don't draw
59- [30 , 30 , 0.5001 ], # draw (> pcutoff)
62+ [- 1 , - 1 , 0.9 ], # top-left offscreen
63+ [48 , 48 , 0.9 ], # bottom-right edge
64+ [25 , 25 , 0.4 ], # below cutoff
6065 ]
6166 ],
6267 dtype = float ,
6368 )
6469
65- draw = MagicMock (name = "DrawInstance" )
70+ draw = MagicMock ()
6671 monkeypatch .setattr (display_mod .ImageDraw , "Draw" , MagicMock (return_value = draw ))
6772
6873 disp .display_frame (frame , pose )
6974
70- # Two points above cutoff => two ellipse calls
7175 assert draw .ellipse .call_count == 2
76+ calls = draw .ellipse .call_args_list
77+
78+ def expected_coords (x , y ):
79+ return [
80+ max (0 , x - r ),
81+ max (0 , y - r ),
82+ min (w , x + r ),
83+ min (h , y + r ),
84+ ]
85+
86+ # First point
87+ assert calls [0 ].args [0 ] == expected_coords (- 1 , - 1 )
88+
89+ # Second point
90+ assert calls [1 ].args [0 ] == expected_coords (48 , 48 )
7291
7392
7493def test_destroy_calls_window_destroy (headless_display_env ):
0 commit comments