import numpy as np from shapely.geometry import Polygon from leonida.buildings import building_polygons, regularize from leonida.classify import CLASSES def test_rough_rectangle_snaps_to_rectangle(): poly = Polygon([(0, 0), (10.4, 0.3), (10.1, 20.2), (-0.2, 19.8)]) out = regularize(poly) assert len(out.exterior.coords) == 5 # geschlossenes Rechteck assert abs(out.area - 205) < 25 def test_l_shape_is_kept_not_boxed(): poly = Polygon([(0, 0), (30, 0), (30, 10), (10, 10), (10, 30), (0, 30)]) out = regularize(poly) assert out.area < 0.8 * out.minimum_rotated_rectangle.area def test_tiny_polygon_is_dropped(): assert regularize(Polygon([(0, 0), (2, 0), (2, 2), (0, 2)])) is None def test_two_buildings_are_separated(): labels = np.full((60, 60), CLASSES["stadt"], dtype=np.uint8) labels[10:25, 10:25] = CLASSES["gebaeude"] labels[35:50, 35:50] = CLASSES["gebaeude"] assert len(building_polygons(labels)) == 2