Files
IfcOpenShell/src/ifcopenshell-python/test/test_shape_stats.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
1008 B
Python
Raw Normal View History

2026-05-18 19:25:13 +02:00
import csv
import pytest
import ifcopenshell
import ifcopenshell.geom
import ifcopenshell.util.shape
from pathlib import Path
repo_root = Path(__file__).resolve().parent.parent.parent.parent
2026-07-26 18:03:09 +10:00
test_files = repo_root / "test" / "input" / "tests"
2026-05-18 19:25:13 +02:00
settings = ifcopenshell.geom.settings()
2026-07-26 18:03:09 +10:00
testdata = list(csv.reader((test_files / "data.csv").open(newline="")))[1:]
2026-05-18 19:25:13 +02:00
print(testdata)
2026-07-26 18:03:09 +10:00
2026-05-18 19:25:13 +02:00
@pytest.mark.parametrize("fn,area,volume", testdata)
def test_conversion(fn, area, volume):
f = ifcopenshell.open(test_files / fn)
2026-07-26 18:03:09 +10:00
elem = next(inst for inst in f.by_type("IfcElement") if not inst.is_a("IfcOpeningElement"))
for kernel in ("manifold", "opencascade", "cgal"):
2026-05-18 19:25:13 +02:00
shp = ifcopenshell.geom.create_shape(settings, elem, geometry_library=kernel)
if area:
assert pytest.approx(float(area), rel=0.05) == ifcopenshell.util.shape.get_area(shp.geometry)
if volume:
assert pytest.approx(float(volume), rel=0.02) == ifcopenshell.util.shape.get_volume(shp.geometry)