1010- euclidean_distance() computation
1111"""
1212
13+ from __future__ import annotations
14+
1315import percemon
1416import pytest
1517
@@ -19,12 +21,12 @@ class TestRefPointTypeEnum:
1921
2022 def test_ref_point_type_enum (self ) -> None :
2123 """Test RefPointType enum values."""
22- assert hasattr (percemon , ' RefPointType' )
23- assert hasattr (percemon .RefPointType , ' LeftMargin' )
24- assert hasattr (percemon .RefPointType , ' RightMargin' )
25- assert hasattr (percemon .RefPointType , ' TopMargin' )
26- assert hasattr (percemon .RefPointType , ' BottomMargin' )
27- assert hasattr (percemon .RefPointType , ' Center' )
24+ assert hasattr (percemon , " RefPointType" )
25+ assert hasattr (percemon .RefPointType , " LeftMargin" )
26+ assert hasattr (percemon .RefPointType , " RightMargin" )
27+ assert hasattr (percemon .RefPointType , " TopMargin" )
28+ assert hasattr (percemon .RefPointType , " BottomMargin" )
29+ assert hasattr (percemon .RefPointType , " Center" )
2830
2931
3032class TestBoundingBox :
@@ -33,10 +35,10 @@ class TestBoundingBox:
3335 def test_bounding_box_construction (self ) -> None :
3436 """Test BoundingBox default construction."""
3537 bbox = percemon .BoundingBox ()
36- assert hasattr (bbox , ' xmin' )
37- assert hasattr (bbox , ' xmax' )
38- assert hasattr (bbox , ' ymin' )
39- assert hasattr (bbox , ' ymax' )
38+ assert hasattr (bbox , " xmin" )
39+ assert hasattr (bbox , " xmax" )
40+ assert hasattr (bbox , " ymin" )
41+ assert hasattr (bbox , " ymax" )
4042
4143 def test_bounding_box_with_values (self ) -> None :
4244 """Test BoundingBox construction with values."""
@@ -95,9 +97,9 @@ class TestObject:
9597 def test_object_construction (self ) -> None :
9698 """Test Object default construction."""
9799 obj = percemon .Object ()
98- assert hasattr (obj , ' object_class' )
99- assert hasattr (obj , ' probability' )
100- assert hasattr (obj , ' bbox' )
100+ assert hasattr (obj , " object_class" )
101+ assert hasattr (obj , " probability" )
102+ assert hasattr (obj , " bbox" )
101103
102104 def test_object_with_values (self , sample_object ) -> None :
103105 """Test Object with assigned values."""
@@ -147,11 +149,11 @@ class TestFrame:
147149 def test_frame_construction (self ) -> None :
148150 """Test Frame default construction."""
149151 frame = percemon .Frame ()
150- assert hasattr (frame , ' timestamp' )
151- assert hasattr (frame , ' frame_num' )
152- assert hasattr (frame , ' size_x' )
153- assert hasattr (frame , ' size_y' )
154- assert hasattr (frame , ' objects' )
152+ assert hasattr (frame , " timestamp" )
153+ assert hasattr (frame , " frame_num" )
154+ assert hasattr (frame , " size_x" )
155+ assert hasattr (frame , " size_y" )
156+ assert hasattr (frame , " objects" )
155157
156158 def test_frame_properties (self , empty_frame ) -> None :
157159 """Test Frame property assignment."""
@@ -267,8 +269,7 @@ class TestEuclideanDistance:
267269 def test_euclidean_distance_same_point (self , sample_bounding_box ) -> None :
268270 """Test euclidean_distance between same points."""
269271 dist = percemon .euclidean_distance (
270- sample_bounding_box , percemon .RefPointType .Center ,
271- sample_bounding_box , percemon .RefPointType .Center
272+ sample_bounding_box , percemon .RefPointType .Center , sample_bounding_box , percemon .RefPointType .Center
272273 )
273274 assert dist == pytest .approx (0.0 )
274275
@@ -277,10 +278,7 @@ def test_euclidean_distance_different_centers(self) -> None:
277278 bbox1 = percemon .BoundingBox (0.0 , 100.0 , 0.0 , 100.0 )
278279 bbox2 = percemon .BoundingBox (100.0 , 200.0 , 0.0 , 100.0 )
279280
280- dist = percemon .euclidean_distance (
281- bbox1 , percemon .RefPointType .Center ,
282- bbox2 , percemon .RefPointType .Center
283- )
281+ dist = percemon .euclidean_distance (bbox1 , percemon .RefPointType .Center , bbox2 , percemon .RefPointType .Center )
284282 # Centers are at (50, 50) and (150, 50), distance = 100
285283 assert dist == pytest .approx (100.0 )
286284
@@ -289,10 +287,7 @@ def test_euclidean_distance_vertical(self) -> None:
289287 bbox1 = percemon .BoundingBox (0.0 , 100.0 , 0.0 , 100.0 )
290288 bbox2 = percemon .BoundingBox (0.0 , 100.0 , 100.0 , 200.0 )
291289
292- dist = percemon .euclidean_distance (
293- bbox1 , percemon .RefPointType .Center ,
294- bbox2 , percemon .RefPointType .Center
295- )
290+ dist = percemon .euclidean_distance (bbox1 , percemon .RefPointType .Center , bbox2 , percemon .RefPointType .Center )
296291 # Centers are at (50, 50) and (50, 150), distance = 100
297292 assert dist == pytest .approx (100.0 )
298293
@@ -301,10 +296,7 @@ def test_euclidean_distance_diagonal(self) -> None:
301296 bbox1 = percemon .BoundingBox (0.0 , 100.0 , 0.0 , 100.0 )
302297 bbox2 = percemon .BoundingBox (100.0 , 200.0 , 100.0 , 200.0 )
303298
304- dist = percemon .euclidean_distance (
305- bbox1 , percemon .RefPointType .Center ,
306- bbox2 , percemon .RefPointType .Center
307- )
299+ dist = percemon .euclidean_distance (bbox1 , percemon .RefPointType .Center , bbox2 , percemon .RefPointType .Center )
308300 # Centers are at (50, 50) and (150, 150)
309301 # distance = sqrt((100)^2 + (100)^2) = sqrt(20000) ≈ 141.42
310302 assert dist == pytest .approx (141.42 , rel = 1e-2 )
@@ -314,10 +306,7 @@ def test_euclidean_distance_between_edges(self) -> None:
314306 bbox1 = percemon .BoundingBox (0.0 , 100.0 , 0.0 , 100.0 )
315307 bbox2 = percemon .BoundingBox (100.0 , 200.0 , 0.0 , 100.0 )
316308
317- dist = percemon .euclidean_distance (
318- bbox1 , percemon .RefPointType .RightMargin ,
319- bbox2 , percemon .RefPointType .LeftMargin
320- )
309+ dist = percemon .euclidean_distance (bbox1 , percemon .RefPointType .RightMargin , bbox2 , percemon .RefPointType .LeftMargin )
321310 # Right margin of bbox1 at (100, 50)
322311 # Left margin of bbox2 at (100, 50)
323312 # distance = 0
@@ -371,9 +360,6 @@ def test_compute_distance_between_frame_objects(self) -> None:
371360 frame .objects ["obj2" ] = obj2
372361
373362 # Compute distance
374- dist = percemon .euclidean_distance (
375- obj1_bbox , percemon .RefPointType .Center ,
376- obj2_bbox , percemon .RefPointType .Center
377- )
363+ dist = percemon .euclidean_distance (obj1_bbox , percemon .RefPointType .Center , obj2_bbox , percemon .RefPointType .Center )
378364 # Centers at (50, 50) and (350, 50), distance = 300
379365 assert dist == pytest .approx (300.0 )
0 commit comments