mirror of
https://git.k-space.ee/arti/vt1200.git
synced 2026-11-01 12:14:56 +02:00
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import numpy as np
|
|
|
|
from pipeline.vectorize import rdp, rasterize, trace, vectorize_frame
|
|
|
|
|
|
def test_rdp_drops_collinear_point():
|
|
pts = [(0, 0), (1, 0), (2, 0)]
|
|
assert rdp(pts, 0.5) == [(0, 0), (2, 0)]
|
|
|
|
|
|
def test_rasterize_square():
|
|
poly = [[(1, 1), (4, 1), (4, 4), (1, 4), (1, 1)]]
|
|
out = rasterize([poly], 6, 6)
|
|
assert out[2, 2]
|
|
assert not out[0, 0]
|
|
|
|
|
|
def test_rasterize_square_with_hole():
|
|
outer = [(1, 1), (5, 1), (5, 5), (1, 5), (1, 1)]
|
|
hole = [(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]
|
|
out = rasterize([[outer, hole]], 7, 7)
|
|
assert out[3, 1]
|
|
assert not out[3, 3]
|
|
|
|
|
|
def test_trace_preserves_vertical_position():
|
|
mask = np.zeros((32, 32), dtype=bool)
|
|
mask[2:6, 4:12] = True
|
|
out = vectorize_frame(mask, {"rdp_epsilon": 1.0, "min_segment": 2})
|
|
assert out[3, 5]
|
|
assert not out[28, 5]
|
|
|
|
|
|
def test_trace_simple_shape_and_roundtrip():
|
|
mask = np.zeros((16, 16), dtype=bool)
|
|
mask[4:12, 4:12] = True
|
|
polys = trace(mask, {"rdp_epsilon": 1.0, "min_segment": 2})
|
|
assert len(polys) >= 1
|
|
roundtrip = rasterize(polys, 16, 16)
|
|
assert roundtrip[6, 6]
|
|
assert not roundtrip[0, 0]
|