mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
Refactor and extend swept shape tests; adjust comments and import structure
Improves formatting and readability in `test_sweeps.py`, adjusts imports and comments, and adds assertions for geometry validation in `simple_sweep_1.ifc` and `simple_sweep_2.ifc` tests. Updates code comments in `IfcFixedReferenceSweptAreaSolid`.
This commit is contained in:
@@ -121,7 +121,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcFixedReferenceSweptAreaSolid
|
|||||||
}
|
}
|
||||||
// TODO: Implement handling for non-alignment curves using sweep_along_curve
|
// TODO: Implement handling for non-alignment curves using sweep_along_curve
|
||||||
auto sweep = taxonomy::make<taxonomy::sweep_along_curve>(
|
auto sweep = taxonomy::make<taxonomy::sweep_along_curve>(
|
||||||
matrix, // matrix4::ptr - no transformation needed
|
matrix, // matrix4::ptr - no transformation needed
|
||||||
profile, // face::ptr - the profile to sweep
|
profile, // face::ptr - the profile to sweep
|
||||||
dir // item::ptr curve - the directrix curve
|
dir // item::ptr curve - the directrix curve
|
||||||
);
|
);
|
||||||
|
|||||||
+15
-3
@@ -3,7 +3,6 @@ from typing import List, Sequence, Tuple
|
|||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import pytest
|
import pytest
|
||||||
from OCC.Core.BRep import BRep_Tool
|
|
||||||
from OCC.Core.TopoDS import TopoDS_Shape, TopoDS_Compound
|
from OCC.Core.TopoDS import TopoDS_Shape, TopoDS_Compound
|
||||||
|
|
||||||
|
|
||||||
@@ -25,6 +24,7 @@ def _size_from_bbox(mn, mx):
|
|||||||
def _triples(flat: Sequence[float]) -> List[Tuple[float, float, float]]:
|
def _triples(flat: Sequence[float]) -> List[Tuple[float, float, float]]:
|
||||||
return [(float(flat[i]), float(flat[i + 1]), float(flat[i + 2])) for i in range(0, len(flat), 3)]
|
return [(float(flat[i]), float(flat[i + 1]), float(flat[i + 2])) for i in range(0, len(flat), 3)]
|
||||||
|
|
||||||
|
|
||||||
def _is_swept_shape(occ_shape: TopoDS_Shape) -> bool:
|
def _is_swept_shape(occ_shape: TopoDS_Shape) -> bool:
|
||||||
"""Analyze if the given OpenCASCADE shape represents a swept shape using topology exploration."""
|
"""Analyze if the given OpenCASCADE shape represents a swept shape using topology exploration."""
|
||||||
try:
|
try:
|
||||||
@@ -33,7 +33,12 @@ def _is_swept_shape(occ_shape: TopoDS_Shape) -> bool:
|
|||||||
from OCC.Core.BRep_Tool import BRep_Tool
|
from OCC.Core.BRep_Tool import BRep_Tool
|
||||||
from OCC.Core.GeomLProp_SLProps import GeomLProp_SLProps
|
from OCC.Core.GeomLProp_SLProps import GeomLProp_SLProps
|
||||||
from OCC.Core.BRepAdaptor_Surface import BRepAdaptor_Surface
|
from OCC.Core.BRepAdaptor_Surface import BRepAdaptor_Surface
|
||||||
from OCC.Core.GeomAbs import GeomAbs_Cylinder, GeomAbs_Plane, GeomAbs_SurfaceOfExtrusion, GeomAbs_SurfaceOfRevolution
|
from OCC.Core.GeomAbs import (
|
||||||
|
GeomAbs_Cylinder,
|
||||||
|
GeomAbs_Plane,
|
||||||
|
GeomAbs_SurfaceOfExtrusion,
|
||||||
|
GeomAbs_SurfaceOfRevolution,
|
||||||
|
)
|
||||||
from OCC.Core.gp import gp_Vec
|
from OCC.Core.gp import gp_Vec
|
||||||
import math
|
import math
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@@ -150,7 +155,7 @@ def load_ifc_occ_shape(ifc_path: str) -> TopoDS_Shape:
|
|||||||
|
|
||||||
# Extract the OpenCASCADE TopoDS_Shape from the result
|
# Extract the OpenCASCADE TopoDS_Shape from the result
|
||||||
# The create_shape function returns an object with an occ_shape attribute when using opencascade
|
# The create_shape function returns an object with an occ_shape attribute when using opencascade
|
||||||
if hasattr(shape_result, 'geometry') and shape_result.geometry:
|
if hasattr(shape_result, "geometry") and shape_result.geometry:
|
||||||
occ_shape = shape_result.geometry
|
occ_shape = shape_result.geometry
|
||||||
if isinstance(occ_shape, TopoDS_Compound):
|
if isinstance(occ_shape, TopoDS_Compound):
|
||||||
json_data = occ_shape.DumpJson()
|
json_data = occ_shape.DumpJson()
|
||||||
@@ -194,15 +199,21 @@ def load_ifc_mesh_bbox(ifc_path: str):
|
|||||||
mn, mx = _bbox_from_vertices(verts)
|
mn, mx = _bbox_from_vertices(verts)
|
||||||
return mn, mx, _size_from_bbox(mn, mx)
|
return mn, mx, _size_from_bbox(mn, mx)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_dir():
|
def test_dir():
|
||||||
return pathlib.Path(__file__).parent.resolve().absolute()
|
return pathlib.Path(__file__).parent.resolve().absolute()
|
||||||
|
|
||||||
|
|
||||||
def test_simple_sweep_1(test_dir):
|
def test_simple_sweep_1(test_dir):
|
||||||
ifc_file_path = test_dir / "input_temp/simple_sweep_1.ifc"
|
ifc_file_path = test_dir / "input_temp/simple_sweep_1.ifc"
|
||||||
ifc_mn, ifc_mx, ifc_sz = load_ifc_mesh_bbox(ifc_file_path)
|
ifc_mn, ifc_mx, ifc_sz = load_ifc_mesh_bbox(ifc_file_path)
|
||||||
occ_shape = load_ifc_occ_shape(ifc_file_path)
|
occ_shape = load_ifc_occ_shape(ifc_file_path)
|
||||||
assert occ_shape is not None
|
assert occ_shape is not None
|
||||||
assert ifc_sz == pytest.approx((1.1, 0.1, 0.89578254))
|
assert ifc_sz == pytest.approx((1.1, 0.1, 0.89578254))
|
||||||
|
assert ifc_mn == pytest.approx((-1.0, -1.3877787807814457e-17, 0.0))
|
||||||
|
assert ifc_mx == pytest.approx((0.10000000000000002, 0.1, 0.8957825463853046))
|
||||||
|
|
||||||
|
|
||||||
def test_simple_sweep_2(test_dir):
|
def test_simple_sweep_2(test_dir):
|
||||||
ifc_file_path = test_dir / "input_temp/simple_sweep_2.ifc"
|
ifc_file_path = test_dir / "input_temp/simple_sweep_2.ifc"
|
||||||
@@ -213,6 +224,7 @@ def test_simple_sweep_2(test_dir):
|
|||||||
assert ifc_mn == pytest.approx((-100.1, -50.0, 197.9041507477363))
|
assert ifc_mn == pytest.approx((-100.1, -50.0, 197.9041507477363))
|
||||||
assert ifc_mx == pytest.approx((-98.29999932008509, -49.075638124333224, 200.0))
|
assert ifc_mx == pytest.approx((-98.29999932008509, -49.075638124333224, 200.0))
|
||||||
|
|
||||||
|
|
||||||
def test_pipe_12d(test_dir):
|
def test_pipe_12d(test_dir):
|
||||||
ifc_file_path = test_dir / "input_temp/pipe.ifc"
|
ifc_file_path = test_dir / "input_temp/pipe.ifc"
|
||||||
ifc_mn, ifc_mx, ifc_sz = load_ifc_mesh_bbox(ifc_file_path)
|
ifc_mn, ifc_mx, ifc_sz = load_ifc_mesh_bbox(ifc_file_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user