first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from simplecadapi import make_box_rsolid, make_line_redge, make_rectangle_rface, extrude_rsolid
|
||||
from simplecadapi.core import Edge, Face, Solid, Vertex, Wire
|
||||
|
||||
|
||||
def test_core_public_shapes_do_not_expose_cq_accessors():
|
||||
box = make_box_rsolid(1, 2, 3)
|
||||
face = box.get_faces(0)
|
||||
edge = face.get_outer_wire().get_edges(0)
|
||||
vertex = edge.get_start_vertex()
|
||||
wire = face.get_outer_wire()
|
||||
|
||||
for shape in (box, face, edge, vertex, wire):
|
||||
assert hasattr(shape, "wrapped")
|
||||
for forbidden in ("cq_solid", "cq_face", "cq_edge", "cq_vertex", "cq_wire"):
|
||||
assert not hasattr(shape, forbidden), f"{type(shape).__name__} exposes {forbidden}"
|
||||
|
||||
|
||||
def test_ocp_native_basic_properties():
|
||||
line = make_line_redge((0, 0, 0), (3, 4, 0))
|
||||
assert isinstance(line, Edge)
|
||||
assert line.get_length() == pytest.approx(5.0)
|
||||
assert line.get_start_vertex().get_coordinates() == pytest.approx((0, 0, 0))
|
||||
assert line.get_end_vertex().get_coordinates() == pytest.approx((3, 4, 0))
|
||||
|
||||
box = make_box_rsolid(1, 2, 3)
|
||||
assert isinstance(box, Solid)
|
||||
assert box.get_volume() == pytest.approx(6.0)
|
||||
assert len(box.get_faces()) == 6
|
||||
|
||||
|
||||
def test_ocp_native_face_wire_topology_and_extrude():
|
||||
face = make_rectangle_rface(2, 3)
|
||||
assert isinstance(face, Face)
|
||||
assert face.get_area() == pytest.approx(6.0)
|
||||
assert isinstance(face.get_outer_wire(), Wire)
|
||||
assert face.get_outer_wire().is_closed()
|
||||
|
||||
solid = extrude_rsolid(face, (0, 0, 1), 4)
|
||||
assert solid.get_volume() == pytest.approx(24.0)
|
||||
|
||||
|
||||
def test_runtime_source_has_no_cadquery_imports_in_runtime_package():
|
||||
runtime_files = [p for p in Path("src/simplecadapi").rglob("*.py") if "auto_tools" not in p.parts]
|
||||
forbidden = ("import cadquery", "from cadquery", "cadquery.occ_impl", ".cq_solid", ".cq_face", ".cq_edge", ".cq_wire", ".cq_vertex")
|
||||
for path in runtime_files:
|
||||
text = path.read_text()
|
||||
for token in forbidden:
|
||||
assert token not in text, f"{path} contains forbidden CadQuery token {token!r}"
|
||||
@@ -0,0 +1,61 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
import simplecadapi as scad
|
||||
|
||||
|
||||
def _box_edge_occurrences():
|
||||
box = scad.make_box_rsolid(1.0, 1.0, 1.0)
|
||||
occurrences = []
|
||||
for face in box.get_faces():
|
||||
occurrences.extend(face.get_outer_wire().get_edges())
|
||||
return box, occurrences
|
||||
|
||||
|
||||
def test_box_edge_occurrences_share_canonical_topo_ids():
|
||||
_, occurrences = _box_edge_occurrences()
|
||||
|
||||
assert len(occurrences) == 24
|
||||
assert len({edge.topo_id for edge in occurrences}) == 12
|
||||
|
||||
|
||||
def test_shared_edge_occurrences_share_tags_and_metadata():
|
||||
_, occurrences = _box_edge_occurrences()
|
||||
groups = defaultdict(list)
|
||||
for edge in occurrences:
|
||||
groups[edge.topo_id].append(edge)
|
||||
|
||||
shared = next(group for group in groups.values() if len(group) >= 2)
|
||||
edge_a, edge_b = shared[0], shared[1]
|
||||
|
||||
scad.apply_tag(edge_a, "shared.edge")
|
||||
edge_a.set_metadata("name", "same-topological-edge")
|
||||
|
||||
assert "shared.edge" in scad.list_tags(edge_b)
|
||||
assert edge_b.get_metadata("name") == "same-topological-edge"
|
||||
|
||||
|
||||
def test_solid_get_edges_returns_unique_topological_edges():
|
||||
box, _ = _box_edge_occurrences()
|
||||
|
||||
edges = box.get_edges()
|
||||
|
||||
assert len(edges) == 12
|
||||
assert len({edge.topo_id for edge in edges}) == 12
|
||||
|
||||
|
||||
def test_edge_incident_faces_and_face_adjacency_are_available():
|
||||
box, _ = _box_edge_occurrences()
|
||||
|
||||
edge = box.get_edges(0)
|
||||
incident_faces = edge.get_incident_faces()
|
||||
|
||||
assert len(incident_faces) == 2
|
||||
assert len({face.topo_id for face in incident_faces}) == 2
|
||||
|
||||
face = box.get_faces(0)
|
||||
adjacent_faces = face.get_adjacent_faces()
|
||||
|
||||
assert len(adjacent_faces) == 4
|
||||
assert face.topo_id not in {adjacent.topo_id for adjacent in adjacent_faces}
|
||||
Reference in New Issue
Block a user