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 (seeShapeElement
) 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
Returns
True
if all carriers in this shape are concentric.A list of all
Carrier
instances underlying the geometry of this shape.The center of this shape.
A mapping of
id(carrier)
to allShapeElement
instances in this shape that havecarrier
as theircarrier
attribute.A special
ShapeSignature
made of registration points (RegistrationPoint
) at each point carrier (PointCarrier
) and their perpendicular projection onto each line carrier (Line
).This shape's
ShapeSignature
.The
Line
instances in this shape.The
Arc
instances in this shape.The
Point
instances in this shape.Methods
Returns
self - self.center
.Retrieve the subshape of this shape located within a rectangular region.
Compute the boolean difference between this shape and another.
Returns true if for each
ShapeElement
a
in this shape, there is an elementb
inother
such thata.equivalent_to(b)
returnsTrue
and that no other element in this shape is equivalent tob
.Returns
True
if for eachShapeElement
a
in this shape, there is an elementb
inother
such thata.is_embedded_in(b)
returnsTrue
.Maximizes this shape in place and returns the newly maximized shape.
Computes all transformations
t
(seeTransformation
) of typequery_transformation
such thatt @ query.shape <= self
returnsTrue
.Apply a
Transformation
to all elements in this shape.Compute the boolean union between this shape and another.
- __add__(other: ndarray[3] | Shape) Shape
Shifts a shape by
other
(ifother
is a vector) or performsunion()
(ifother
is aShape
).
- __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 performingt @ transformable
for aTransformation
t
andTransformableMixin
transformable
.
- __sub__(other: ndarray[3] | Shape) Shape
Shifts a shape by
-other
(ifother
is a vector) or performsdifference()
(ifother
is aShape
).
- 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 elementb
inother
such thata.equivalent_to(b)
returnsTrue
and that no other element in this shape is equivalent tob
.
- filter(predicate: Callable[[ShapeElement], Any]) Shape
- filtered_to_attributes(attributes: Set[ElementAttributes]) Shape
- is_embedded_in(other: Shape) bool
Returns
True
if for eachShapeElement
a
in this shape, there is an elementb
inother
such thata.is_embedded_in(b)
returnsTrue
.
- maximize_and_recalibrate() Shape
Maximizes this shape in place and returns the newly maximized shape.
- query(query: ShapeQuery) List[Transformation]
Computes all transformations
t
(seeTransformation
) of typequery_transformation
such thatt @ query.shape <= self
returnsTrue
. Currently only implemented for transformations of typeIsometry
,Similarity
, andAffinity
.- Parameters:
query – The
ShapeQuery
to use for computing transformations.- Returns:
All transformations
t
of typequery_transformation
such thatt @ query_shape <= self
returnsTrue
.
- 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 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 elements_by_carrier_id: Dict[int, List[ShapeElement]]
A mapping of
id(carrier)
to allShapeElement
instances in this shape that havecarrier
as theircarrier
attribute.
- 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.
- property signature: ShapeSignature
This shape’s
ShapeSignature
.A shape’s signature is created by marking all intersection locations of
carriers
. ARegistrationPoint
is placed at each intersection withsignature
set as follows:If the registration point is coincident with a
PointCarrier
or the center of aArcCarrier
, itsdirect_attributes
includes that carrier’sattributes_set
.If the registration point is coincident to a
LineCarrier
, itsspokes
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 toEMPTY
.If there is a line in this direction, the spoke’s type will be set to
FILLED
.