Files

35 lines
1.9 KiB
Python

import unittest,sys,math
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'src'))
from bridge_drawing_extractor.geometry import scene,leader_endpoint
from bridge_drawing_extractor.semantic import bearings
class GeometryTests(unittest.TestCase):
def test_block_rotation_scale_and_definition_exclusion(self):
raw={'OBJECTS':[
dict(object='BLOCK_HEADER',handle=[1],name='*Model_Space',entities=[[3]]),
dict(object='BLOCK_HEADER',handle=[2],name='label',base_pt=[1,0],entities=[[4],[5]]),
dict(entity='INSERT',handle=[3],block_header=[2],ins_pt=[100,200],scale=[2,2,2],rotation=math.pi/2),
dict(entity='TEXT',handle=[4],ins_pt=[2,0],text_value='P1',height=1),
dict(entity='LINE',handle=[5],start=[1,0],end=[2,0]) ]}
texts,segments,warnings=scene(raw)
self.assertEqual(len(texts),1);self.assertAlmostEqual(texts[0]['x'],100);self.assertAlmostEqual(texts[0]['y'],202)
self.assertEqual(texts[0]['height'],2);self.assertEqual(segments[0]['a'],[100,200]);self.assertFalse(warnings)
def test_leader_and_grid_ambiguity(self):
text=dict(x=2,y=1,height=1)
lines=[dict(h=1,a=[0,0],b=[8,0]),dict(h=2,a=[8,0],b=[8,-5])]
self.assertEqual(leader_endpoint(text,lines)[0],[8,-5])
lines.append(dict(h=3,a=[8,0],b=[12,0]))
self.assertIsNone(leader_endpoint(text,lines))
def test_table_borders_connect_misaligned_row(self):
def e(x,y,t):return dict(h=int(x+y),x=x,y=y,t=t)
texts=[e(100,30,'P1(전)'),e(0,0,'구분'),e(100,0,'X좌표'),e(200,0,'Y좌표'),e(0,-20,'1'),e(100,-20,'1000'),e(200,-17,'2000')]
lines=[dict(h=1,a=[-10,-10],b=[240,-10]),dict(h=2,a=[-10,-30],b=[240,-30])]
self.assertFalse(bearings(texts)[0])
rows,_=bearings(texts,lines)
self.assertEqual((rows[0]['x'],rows[0]['y']),(1000,2000))
if __name__=='__main__':unittest.main()