-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_line_interpolation.py
More file actions
27 lines (21 loc) · 996 Bytes
/
test_line_interpolation.py
File metadata and controls
27 lines (21 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from opticalc.utils import line_interpolate
# Test case 1: Simple line through (0,0) and (1,1)
(X1, X2), (Y1, Y2) = line_interpolate(0, 0, 1, 1, 0.5, 2)
print("Line through (0,0) and (1,1):")
print(f"X=0.5 -> Y={Y1}, X=2 -> Y={Y2}")
# Test case 2: Line with negative slope
(X1, X2), (Y1, Y2) = line_interpolate(0, 10, 5, 0, 2, 3)
print("\nLine through (0,10) and (5,0):")
print(f"X=2 -> Y={Y1}, X=3 -> Y={Y2}")
# Test case 3: Horizontal line
(X1, X2), (Y1, Y2) = line_interpolate(1, 5, 4, 5, 2, 10)
print("\nHorizontal line through (1,5) and (4,5):")
print(f"X=2 -> Y={Y1}, X=10 -> Y={Y2}")
# Test case 4: Line with fractional coordinates
(X1, X2), (Y1, Y2) = line_interpolate(1.5, 2.3, 3.7, 6.1, 2.0, 4.0)
print("\nLine through (1.5,2.3) and (3.7,6.1):")
print(f"X=2.0 -> Y={Y1:.2f}, X=4.0 -> Y={Y2:.2f}")
# Test case 5:
(X1, X2), (Y1, Y2) = line_interpolate(1.0, 1.0, 3.0, 2.0, 0.0, 5.0)
print("\nLine through (1.0,1.0) and (3.0,2.0):")
print(f"X=0.0 -> Y={Y1:.2f}, X=5.0 -> Y={Y2:.2f}")