shore.geometry.keys
Persistent entity identity: fingerprints and matching (ADR 0003).
OCCT shapes carry no identity that survives re-reading an edited CAD file, and EntityRef indices are only valid for one load. An EntityKey is a geometric fingerprint of an entity, normalised by the model's bounding box so that a uniform rescale leaves it unchanged:
kindandgeom_type(Plane,Cylinder,BSplineSurface,Line,Circle, ...) must match exactly;centroid,measure(area, length, 0 for a point) andextent(bounding-box size) are compared numerically.
match_keys re-finds stored keys in a geometry by a global one-to-one assignment per (kind, type) group and reports each key as same (unchanged within tol_same), changed (matched, but moved or resized, as after a parametric edit) or lost (no candidate within tol_match).
EntityKey dataclass
EntityKey(
kind: EntityKind,
geom_type: str,
centroid: tuple[float, float, float],
measure: float,
extent: tuple[float, float, float],
name: str | None = None,
)Geometric fingerprint of one entity, normalised by the model bbox.
Coordinates are (x - bbox_min) / diag; measure is area / diag**2 (surface), length / diag (curve), 0 (point, body uses area).
EntityKey.to_json method
to_json() -> dict[str, Any]EntityKey.from_json classmethod
from_json(data: dict[str, Any], *, source: str = '<key>') -> EntityKeyEntityKey.distance method
distance(other: EntityKey) -> floatDissimilarity in normalised units; inf across kinds or types.
make_key function
make_key(
kind: EntityKind,
geom_type: str,
centroid: np.ndarray,
measure: float,
bbox: np.ndarray,
model_bounds: np.ndarray,
name: str | None = None,
) -> EntityKeyNormalise raw entity properties into an EntityKey.
bbox and model_bounds are (2, 3) [min, max] boxes; measure is raw area / length (0 for points).
KeyMatch dataclass
KeyMatch(key: EntityKey, ref: EntityRef | None, status: MatchStatus, cost: float)Where a stored key landed in a geometry.
MatchReport dataclass
MatchReport(matches: list[KeyMatch] = field(default_factory=list))Outcome of match_keys: one KeyMatch per stored key, in order.
MatchReport.count method
count(status: MatchStatus) -> intMatchReport.all_matched property
all_matched: boolMatchReport.summary method
summary() -> strmatch_keys function
match_keys(
keys: list[EntityKey],
geometry: Geometry,
*,
tol_same: float = 1e-09,
tol_match: float = 0.25,
) -> MatchReportRe-find keys in geometry by one-to-one assignment.
Keys are grouped by (kind, geom_type); within a group the assignment minimises the total EntityKey.distance. A pairing with cost above tol_match is rejected (lost); one at or below tol_same is same; anything in between is changed. Names, when both sides have one, must agree.