Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
self-hosted-runner:
labels:
- rhino8
96 changes: 96 additions & 0 deletions .github/brep-interchange/analytic_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""Independent dimensions and invariants for the analytic solid fixtures."""

from collections import Counter
from collections import defaultdict
from math import hypot
from math import isclose
from math import pi

from interchange_validation import validate

CENTER = (1.0, -2.0, 0.5)
XAXIS = (0.6, 0.8, 0.0)
YAXIS = (-0.48, 0.36, 0.8)
ZAXIS = (0.64, -0.48, 0.6)
RADIUS = 2.0
HEIGHT = 3.0
MAJOR_RADIUS = 4.0
MINOR_RADIUS = 1.0

# Surface types, canonical edge count, shared seam count, singular trim count.
ANALYTIC_FIXTURES = {
"sphere": (("sphere",), 1, 1, 2),
"cylinder": (("cylinder", "plane", "plane"), 3, 1, 0),
"cone": (("cone", "plane"), 2, 1, 1),
"torus": (("torus",), 2, 2, 0),
}


def point(x=0.0, y=0.0, z=0.0):
return tuple(center + x * axis_x + y * axis_y + z * axis_z for center, axis_x, axis_y, axis_z in zip(CENTER, XAXIS, YAXIS, ZAXIS))


def signature(name, data):
validate(data)
if data["kind"] != "solid" or data["units"] != "mm":
raise ValueError(f"{name} must be an analytic solid measured in millimetres.")
component = data["components"][0]
faces = component["faces"]
shells = component["shells"]
if len(shells) != 1 or shells[0]["role"] != "outer" or sorted(shells[0]["faces"]) != list(range(len(faces))):
raise ValueError(f"{name} must have one exterior shell.")

surfaces = tuple(sorted(face["surface"]["type"] for face in faces))
edge_uses = defaultdict(list)
singular_trims = 0
for face_index, face in enumerate(faces):
if len(face["loops"]) != 1 or face["loops"][0]["role"] != "outer":
raise ValueError(f"Unexpected boundary loops on {name}.")
for trim in face["loops"][0]["trims"]:
if trim["edge"] is None:
singular_trims += 1
else:
edge_uses[trim["edge"]].append((face_index, trim["reversed"]))
seams = sum(len(uses) == 2 and uses[0][0] == uses[1][0] and uses[0][1] != uses[1][1] for uses in edge_uses.values())
observed = (surfaces, len(component["edges"]), seams, singular_trims)
if observed != ANALYTIC_FIXTURES[name]:
raise ValueError(f"{name} has unexpected analytic topology {observed}.")

circular_edges = sum(edge["curve"]["type"] in {"circle", "arc"} for edge in component["edges"])
if circular_edges != {"sphere": 1, "cylinder": 2, "cone": 1, "torus": 2}[name]:
raise ValueError(f"{name} lost the analytic representation of a circular edge.")
return observed


def measure(name, adapter, native, data):
expected = {
"sphere": (4 * pi * RADIUS**2, 4 * pi * RADIUS**3 / 3),
"cylinder": (2 * pi * RADIUS * (RADIUS + HEIGHT), pi * RADIUS**2 * HEIGHT),
"cone": (pi * RADIUS * (RADIUS + hypot(RADIUS, HEIGHT)), pi * RADIUS**2 * HEIGHT / 3),
"torus": (4 * pi**2 * MAJOR_RADIUS * MINOR_RADIUS, 2 * pi**2 * MAJOR_RADIUS * MINOR_RADIUS**2),
}
inside = {
"sphere": point(),
"cylinder": point(z=HEIGHT / 2),
"cone": point(z=HEIGHT / 2),
"torus": point(x=MAJOR_RADIUS),
}
report = adapter.measure(native)
if not report["valid"]:
raise ValueError(f"Invalid native {name}.")
for quantity, reference in zip(("area", "volume"), expected[name]):
if not isclose(report[quantity], reference, rel_tol=1e-6):
raise ValueError(f"{name} {quantity} {report[quantity]} differs from {reference}.")
points = (inside[name], point(x=MAJOR_RADIUS + RADIUS))
if name == "torus":
points += (point(),)
containment = adapter.classify_points(native, points)
if containment != [True] + [False] * (len(points) - 1):
raise ValueError(f"{name} changed native point containment.")

native_surfaces = adapter.analytic_surface_types(native)
surfaces, edges, seams, singular = signature(name, data)
if Counter(native_surfaces) != Counter(surfaces):
raise ValueError(f"{name} native support surfaces {native_surfaces} disagree with the wire record.")
report.update(surface_types=sorted(native_surfaces), edges=edges, shared_seams=seams, singular_trims=singular, containment=containment)
return report
Loading
Loading