Skip to content

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:

  • kind and geom_type (Plane, Cylinder, BSplineSurface, Line, Circle, ...) must match exactly;
  • centroid, measure (area, length, 0 for a point) and extent (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 ​

python
EntityKey(
    kind: EntityKind,
    geom_type: str,
    centroid: tuple[float, float, float],
    measure: float,
    extent: tuple[float, float, float],
    name: str | None = None,
)

source

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 ​

python
to_json() -> dict[str, Any]

source

EntityKey.from_json classmethod ​

python
from_json(data: dict[str, Any], *, source: str = '<key>') -> EntityKey

source

EntityKey.distance method ​

python
distance(other: EntityKey) -> float

source

Dissimilarity in normalised units; inf across kinds or types.

make_key function ​

python
make_key(
    kind: EntityKind,
    geom_type: str,
    centroid: np.ndarray,
    measure: float,
    bbox: np.ndarray,
    model_bounds: np.ndarray,
    name: str | None = None,
) -> EntityKey

source

Normalise 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 ​

python
KeyMatch(key: EntityKey, ref: EntityRef | None, status: MatchStatus, cost: float)

source

Where a stored key landed in a geometry.

MatchReport dataclass ​

python
MatchReport(matches: list[KeyMatch] = field(default_factory=list))

source

Outcome of match_keys: one KeyMatch per stored key, in order.

MatchReport.count method ​

python
count(status: MatchStatus) -> int

source

MatchReport.all_matched property ​

python
all_matched: bool

source

MatchReport.summary method ​

python
summary() -> str

source

match_keys function ​

python
match_keys(
    keys: list[EntityKey],
    geometry: Geometry,
    *,
    tol_same: float = 1e-09,
    tol_match: float = 0.25,
) -> MatchReport

source

Re-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.

Released under the MIT License.