mahautils.shapes.Layer¶
- class mahautils.shapes.Layer(*shapes: Shape2D, name: str | None = None, color: str = 'default', print_multiline: bool = True)¶
Bases:
TypedListWithID[Shape2D]An object for storing a set of 2D shapes
A
Layeris intended to store a set of related shapes, allowing more complex, multi-shape geometries to be constructed. For instance, one potential application would be to use aLayerto store the disjoint polygons that constitute the high-pressure ports in an axial piston pump.The
Layerinherits from Python’sMutableSequencetype, so most operations that can be performed for a Pythonlist(append, pop, insert, etc.) are valid operations for aLayer.Attributes
The color with which to display the layer in plots
A descriptive name to identify the layer
The number of shapes in the layer
Methods
__init__(*shapes[, name, color, print_multiline])Creates a new layer to store shapes
plot([units, figure, show, return_fig])Plots the shapes in the layer
reflect(pntA, pntB)Reflects all shapes in the layer about a line specified by two points
Reflects all shapes in the layer about the \(x\)-axis
Reflects all shapes in the layer about the \(y\)-axis
rotate(center, angle[, angle_units])Rotates all shapes in the layer a given angle in the \(xy\)-plane about a user-specified point
translate([x, y])Translates all shapes in the layer a user-specified distance in the \(x\)- and/or \(y\)-directions
Inherited Attributes
A unique class instance identification number
The required type of all items in the list
The number of spaces on either side of the list of items in the list when displaying the list's string representation in multiline format
Whether to display the object's string representation in multiline format
Inherited Methods
append(value)S.append(value) -- append value to the end of the sequence
clear()count(value)extend(values)S.extend(iterable) -- extend sequence by appending elements from the iterable
index(value, [start, [stop]])Raises ValueError if the value is not present.
insert(index, value)Inserts a value at a given index in the list
pop([index])Raise IndexError if list is empty or index is out of range.
remove(value)S.remove(value) -- remove first occurrence of value.
reverse()S.reverse() -- reverse IN PLACE
- __init__(*shapes: Shape2D, name: str | None = None, color: str = 'default', print_multiline: bool = True) None¶
Creates a new layer to store shapes
Creates a new
Layerobject in which a set of 2D shapes (of typeShape2D) can be stored.- Parameters:
*shapes (Shape2D, optional) – Shapes to add to the layer after the layer is created (default is no shapes)
name (str, optional) – A descriptive name to identify the layer. If not provided, the layer name is generated automatically
color (str, optional) – The color with which to display the layer in plots. If not provided or set to
'default', the colors from Plotly’s default color order are usedprint_multiline (bool, optional) – Whether to return a printable string representation of the list in multiline format (default is
True). Multiline format places each item in the list on its own line
Notes
Any valid color accepted by Plotly can be specified, either as a named color (
'blue','green', etc.) or a hex code. Valid options are described on this page.
- property color: str¶
The color with which to display the layer in plots
Notes
Any valid color accepted by Plotly can be specified, either as a named color (
'blue','green', etc.) or a hex code. Valid options are described on this page.
- property name: str¶
A descriptive name to identify the layer
- property num_shapes: int¶
The number of shapes in the layer
- plot(units: str | None = None, figure: Figure | None = None, show: bool = True, return_fig: bool = False) Figure | None¶
Plots the shapes in the layer
Creates a Plotly figure illustrating the shapes in the layer, or optionally appends traces for each shape to an existing figure. The figure can be opened in a browser (default behavior) and/or returned (to allow subsequent user-specific customizations).
- Parameters:
units (str, optional) – If units are provided, it will be verified that all plotted shapes have these units in their
Shape2D.unitsattribute (default isNone, which performs no unit checks). Additionally, if thefigureargument was not provided, the specified units will be included in the axis titlesfigure (go.Figure, optional) – A Plotly figure. If provided, rather than creating a new figure from scratch, the layer’s shapes will be added as new traces in the provided figure (default is
None, which creates a new figure from scratch)show (bool, optional) – Whether to open the figure in a browser (default is
True)return_fig (bool, optional) – Whether to return the figure (default is
False)
- Returns:
A Plotly figure depicting the layer. Returned if and only if
return_figisTrue- Return type:
go.Figure
- reflect(pntA: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D, pntB: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D) None¶
Reflects all shapes in the layer about a line specified by two points
- Parameters:
pntA (list or tuple or CartesianPoint2D) – One point on the line across which the shape is to be reflected
pntB (list or tuple or CartesianPoint2D) – Another point on the line across which the shape is to be reflected
- append(value)¶
S.append(value) – append value to the end of the sequence
- clear() None -- remove all items from S¶
- count(value) integer -- return number of occurrences of value¶
- extend(values)¶
S.extend(iterable) – extend sequence by appending elements from the iterable
- property id: int¶
A unique class instance identification number
- index(value[, start[, stop]]) integer -- return first index of value.¶
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- insert(index: int, value: T)¶
Inserts a value at a given index in the list
- property list_type: Type[T]¶
The required type of all items in the list
- property multiline_padding: int¶
The number of spaces on either side of the list of items in the list when displaying the list’s string representation in multiline format
- pop([index]) item -- remove and return item at index (default last).¶
Raise IndexError if list is empty or index is out of range.
- property print_multiline: bool¶
Whether to display the object’s string representation in multiline format
- reflect_x() None¶
Reflects all shapes in the layer about the \(x\)-axis
- remove(value)¶
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- reverse()¶
S.reverse() – reverse IN PLACE
- reflect_y() None¶
Reflects all shapes in the layer about the \(y\)-axis
- rotate(center: List[float] | Tuple[float, float] | ndarray | CartesianPoint2D, angle: float, angle_units: str = 'rad') None¶
Rotates all shapes in the layer a given angle in the \(xy\)-plane about a user-specified point
- Parameters:
center (list or tuple or CartesianPoint2D) – The center of rotation about which to rotate the shapes
angle (float) – The angle by which to rotate the shapes about
centerangle_units (str, optional) – The units (radians or degrees) of the
angleargument. Must be either'rad'or'deg'(default is'rad')
- translate(x: float = 0, y: float = 0) None¶
Translates all shapes in the layer a user-specified distance in the \(x\)- and/or \(y\)-directions
- Parameters:
x (float, optional) – The distance to translate the shapes in the \(x\)-direction (default is
0)y (float, optional) – The distance to translate the shapes in the \(y\)-direction (default is
0)