@mytec: feat: Phase 3.0 Architecture Refactor ✅
Major refactoring of RFCP backend: - Modular propagation models (8 models) - SharedMemoryManager for terrain data - ProcessPoolExecutor parallel processing - WebSocket progress streaming - Building filtering pipeline (351k → 15k) - 82 unit tests Performance: Standard preset 38s → 5s (7.6x speedup) Known issue: Detailed preset timeout (fix in 3.1.0)
This commit is contained in:
77
backend/tests/test_geometry/test_intersection.py
Normal file
77
backend/tests/test_geometry/test_intersection.py
Normal file
@@ -0,0 +1,77 @@
|
||||
"""
|
||||
Unit tests for line-segment intersection calculations.
|
||||
|
||||
These require NumPy, so use __main__ block with conditional import.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
|
||||
import numpy as np
|
||||
from app.geometry.intersection import line_segments_intersect_batch
|
||||
|
||||
|
||||
class TestLineSegmentIntersect:
|
||||
def test_crossing_lines(self):
|
||||
"""Two crossing segments should intersect."""
|
||||
# Line from (0,0)→(1,1) and (0,1)→(1,0)
|
||||
result = line_segments_intersect_batch(
|
||||
p1=np.array([0.0, 0.0]),
|
||||
p2=np.array([1.0, 1.0]),
|
||||
seg_starts=np.array([[0.0, 1.0]]),
|
||||
seg_ends=np.array([[1.0, 0.0]]),
|
||||
)
|
||||
assert result[0] == True
|
||||
|
||||
def test_parallel_lines(self):
|
||||
"""Parallel lines should not intersect."""
|
||||
result = line_segments_intersect_batch(
|
||||
p1=np.array([0.0, 0.0]),
|
||||
p2=np.array([1.0, 0.0]),
|
||||
seg_starts=np.array([[0.0, 1.0]]),
|
||||
seg_ends=np.array([[1.0, 1.0]]),
|
||||
)
|
||||
assert result[0] == False
|
||||
|
||||
def test_non_crossing(self):
|
||||
"""Segments that don't reach each other."""
|
||||
result = line_segments_intersect_batch(
|
||||
p1=np.array([0.0, 0.0]),
|
||||
p2=np.array([0.5, 0.5]),
|
||||
seg_starts=np.array([[0.8, 0.0]]),
|
||||
seg_ends=np.array([[0.8, 1.0]]),
|
||||
)
|
||||
assert result[0] == False
|
||||
|
||||
def test_multiple_segments(self):
|
||||
"""Batch test with multiple segments."""
|
||||
result = line_segments_intersect_batch(
|
||||
p1=np.array([0.0, 0.0]),
|
||||
p2=np.array([1.0, 1.0]),
|
||||
seg_starts=np.array([
|
||||
[0.0, 1.0], # crosses
|
||||
[2.0, 0.0], # doesn't cross
|
||||
[0.5, 0.0], # crosses
|
||||
]),
|
||||
seg_ends=np.array([
|
||||
[1.0, 0.0], # crosses
|
||||
[2.0, 1.0], # doesn't cross
|
||||
[0.5, 1.0], # crosses
|
||||
]),
|
||||
)
|
||||
assert result[0] == True
|
||||
assert result[1] == False
|
||||
assert result[2] == True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
instance = TestLineSegmentIntersect()
|
||||
for method_name in [m for m in dir(instance) if m.startswith("test_")]:
|
||||
try:
|
||||
getattr(instance, method_name)()
|
||||
print(f" PASS {method_name}")
|
||||
except Exception as e:
|
||||
print(f" FAIL {method_name}: {e}")
|
||||
print("\nAll tests completed.")
|
||||
Reference in New Issue
Block a user