Shape

class Shape(lines: List[Line], arcs: List[Arc], points: List[Point], *, maximal: bool = False, update_carrier_attrs: bool = False)

A Shape represents a collection of shape elements (see ShapeElement) that can be queried and modified. This is the primary unit of computation within Shape Machine.

Parameters:
  • lines – The Line instances in this shape.

  • arcs – The Arc instances in this shape.

  • points – The Point instances in this shape.

  • maximal – Whether this shape is maximal or not. If False, maximize_and_recalibrate() is called in __init__ to maximize the geometry of the shape.

  • update_carrier_attrs – If True, carrier attribute sets (attributes_set) will be recomputed.

Attributes

all_attributes

all_concentric_carriers

Returns True if all carriers in this shape are concentric.

carriers

A list of all Carrier instances underlying the geometry of this shape.

center

The center of this shape.

convex_hull

elements_by_carrier_id

A mapping of id(carrier) to all ShapeElement instances in this shape that have carrier as their carrier attribute.

point_line_perpendicular_signature

A special ShapeSignature made of registration points (RegistrationPoint) at each point carrier (PointCarrier) and their perpendicular projection onto each line carrier (Line).

signature

This shape's ShapeSignature.

lines

The Line instances in this shape.

arcs

The Arc instances in this shape.

points

The Point instances in this shape.

Methods

centered_at_origin

Returns self - self.center.

crop_to_rectangle

Retrieve the subshape of this shape located within a rectangular region.

difference

Compute the boolean difference between this shape and another.

equivalent_to

Returns true if for each ShapeElement a in this shape, there is an element b in other such that a.equivalent_to(b) returns True and that no other element in this shape is equivalent to b.

filter

filtered_to_attributes

is_embedded_in

Returns True if for each ShapeElement a in this shape, there is an element b in other such that a.is_embedded_in(b) returns True.

maximize_and_recalibrate

Maximizes this shape in place and returns the newly maximized shape.

query

Computes all transformations t (see Transformation) of type query_transformation such that t @ query.shape <= self returns True.

transform

Apply a Transformation to all elements in this shape.

union

Compute the boolean union between this shape and another.

__add__(other: ndarray[3] | Shape) Shape

Shifts a shape by other (if other is a vector) or performs union() (if other is a Shape).

__bool__()

Returns True if this shape is nonempty.

__le__(other: Shape)

Calls is_embedded_in().

__len__()

Returns the number of elements (see ShapeElement) in this shape.

__rmatmul__(transformation: Transformation) T_co

Computes transformable.transform(t) when performing t @ transformable for a Transformation t and TransformableMixin transformable.

__sub__(other: ndarray[3] | Shape) Shape

Shifts a shape by -other (if other is a vector) or performs difference() (if other is a Shape).

centered_at_origin() Shape

Returns self - self.center.

crop_to_rectangle(min_corner: ndarray[3], max_corner: ndarray[3])

Retrieve the subshape of this shape located within a rectangular region.

Parameters:
  • min_corner – The (min-x, min-y) corner of the rectangular region.

  • max_corner – The (max-x, max-y) corner of the rectangular region.

difference(other: Shape, maximize: bool = True) Shape

Compute the boolean difference between this shape and another.

Parameters:
  • other – The other shape.

  • maximize – If True, maximize the resulting shape.

Returns:

The difference of this shape and the other shape.

equivalent_to(other: Shape) bool

Returns true if for each ShapeElement a in this shape, there is an element b in other such that a.equivalent_to(b) returns True and that no other element in this shape is equivalent to b.

filter(predicate: Callable[[ShapeElement], Any]) Shape
filtered_to_attributes(attributes: Set[ElementAttributes]) Shape
is_embedded_in(other: Shape) bool

Returns True if for each ShapeElement a in this shape, there is an element b in other such that a.is_embedded_in(b) returns True.

maximize_and_recalibrate() Shape

Maximizes this shape in place and returns the newly maximized shape.

query(query: ShapeQuery) List[Transformation]

Computes all transformations t (see Transformation) of type query_transformation such that t @ query.shape <= self returns True. Currently only implemented for transformations of type Isometry, Similarity, and Affinity.

Parameters:

query – The ShapeQuery to use for computing transformations.

Returns:

All transformations t of type query_transformation such that t @ query_shape <= self returns True.

transform(transformation: Transformation) Shape

Apply a Transformation to all elements in this shape.

union(other: Shape, maximize: bool = True) Shape

Compute the boolean union between this shape and another.

Parameters:
  • other – The other shape.

  • maximize – If True, maximize the resulting shape.

Returns:

The union of this shape and the other shape.

property all_attributes: Set[ElementAttributes]
property all_concentric_carriers: bool

Returns True if all carriers in this shape are concentric.

arcs

The Arc instances in this shape.

property carriers: List[Carrier]

A list of all Carrier instances underlying the geometry of this shape. Provided as line carriers ( LineCarrier), then arc carriers ( ArcCarrier), then point carriers ( PointCarrier).

property center: ndarray[3]

The center of this shape.

property convex_hull: Shape
property elements_by_carrier_id: Dict[int, List[ShapeElement]]

A mapping of id(carrier) to all ShapeElement instances in this shape that have carrier as their carrier attribute.

lines

The Line instances in this shape.

property point_line_perpendicular_signature: ShapeSignature

A special ShapeSignature made of registration points (RegistrationPoint) at each point carrier (PointCarrier) and their perpendicular projection onto each line carrier (Line).

The spokes of each registration point are computed for the registration points on line carriers.

points

The Point instances in this shape.

property signature: ShapeSignature

This shape’s ShapeSignature.

A shape’s signature is created by marking all intersection locations of carriers. A RegistrationPoint is placed at each intersection with signature set as follows:

  1. If the registration point is coincident with a PointCarrier or the center of a ArcCarrier, its direct_attributes includes that carrier’s attributes_set.

  2. If the registration point is coincident to a LineCarrier, its spokes will include two spokes corresponding to that carrier.

    • Each spoke corresponds to the half of the carrier in that direction.

    • If there is not a Line in that direction from the registration point, the spoke’s type will be set to EMPTY.

    • If there is a line in this direction, the spoke’s type will be set to FILLED.