Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
40 lines
2.2 KiB
Python
40 lines
2.2 KiB
Python
import unittest
|
|
import numpy as np
|
|
from shapely.geometry import LineString
|
|
from plan_boundaries import split_observed_boundary
|
|
from frontage_chains import join_planes
|
|
from paint_templates import fit_symbol
|
|
|
|
class ObservedBoundaryTests(unittest.TestCase):
|
|
def test_visible_unclassified_branch_is_not_a_closed_road_end(self):
|
|
p=np.array([[0,0],[0,1],[0,2],[1,2],[2,2],[2,1],[2,0],[1,0]],float)
|
|
chains=split_observed_boundary(p,[1,1,1,0,1,1,1,0],np.ones(8,bool))
|
|
self.assertEqual(len(chains),2)
|
|
self.assertTrue(all(not x.closed and x.start_reason=='semantic-frontier' and x.end_reason=='semantic-frontier' for x in chains))
|
|
self.assertTrue(all(LineString(x.points).length==2 for x in chains))
|
|
def test_scan_limit_does_not_close_street(self):
|
|
p=np.array([[0,0],[0,1],[0,2],[1,2],[2,2],[2,1],[2,0],[1,0]],float)
|
|
chains=split_observed_boundary(p,[1]*8,[1,1,1,0,1,1,1,0])
|
|
self.assertEqual(len(chains),2);self.assertTrue(all(x.end_reason=='coverage-frontier' for x in chains))
|
|
def test_observed_island_keeps_physical_loop(self):
|
|
p=[[0,0],[1,0],[1,1],[0,1]];r=split_observed_boundary(p,[1]*4,[1]*4)
|
|
self.assertEqual(len(r),1);self.assertTrue(r[0].closed);np.testing.assert_array_equal(r[0].points[0],r[0].points[-1])
|
|
def test_invalid_alignment_rejected(self):
|
|
with self.assertRaises(ValueError):split_observed_boundary([[0,0],[1,0]],[1],[1,1])
|
|
|
|
class FrontageTests(unittest.TestCase):
|
|
def test_collinear_planes_join_without_building_back(self):
|
|
r=join_planes([LineString([(0,0),(4,0)]),LineString([(4.4,.06),(9,.06)]),LineString([(9,0),(9,3)])])
|
|
self.assertEqual(len(r),2);self.assertTrue(all(len(p)==2 for p,_ in r))
|
|
def test_large_gap_and_real_corner_survive(self):
|
|
r=join_planes([LineString([(0,0),(4,0)]),LineString([(8,0),(12,0)]),LineString([(12,0),(12,4)])])
|
|
self.assertEqual(len(r),3)
|
|
def test_join_cannot_cross_another_facade(self):
|
|
r=join_planes([LineString([(0,0),(4,0)]),LineString([(5,0),(9,0)]),LineString([(4.5,-2),(4.5,2)])])
|
|
self.assertEqual(len(r),3)
|
|
class PaintTests(unittest.TestCase):
|
|
def test_narrow_lane_dash_cannot_become_arrow(self):
|
|
from shapely.geometry import box
|
|
self.assertIsNone(fit_symbol(box(0,0,.15,4)))
|
|
if __name__=='__main__':unittest.main()
|