Drawing
momapy.drawing
SVG-like drawing elements for momapy.
This module provides classes for creating and manipulating SVG-like drawing elements including paths, shapes, text, filters, and groups. It supports transformations, styling attributes, and conversion to/from shapely geometries.
Examples:
Classes:
| Name | Description |
|---|---|
ClosePath |
Close the current path. |
CompositeEffect |
Composite filter effect. |
CompositionOperator |
Composition operators for filter effects. |
CurveTo |
Draw a cubic Bezier curve. |
DrawingElement |
Abstract base class for drawing elements. |
DropShadowEffect |
Drop shadow filter effect. |
EdgeMode |
Edge mode for blur effects. |
Ellipse |
Ellipse drawing element. |
EllipticalArc |
Draw an elliptical arc. |
FillRule |
Fill rule for complex shapes. |
Filter |
Filter with multiple effects. |
FilterEffect |
Abstract base class for filter effects. |
FilterEffectInput |
Filter effect input types. |
FilterUnits |
Units for filter regions. |
FloodEffect |
Flood filter effect. |
FontStyle |
Font style options. |
FontWeight |
Font weight options. |
GaussianBlurEffect |
Gaussian blur filter effect. |
Group |
Group of drawing elements. |
LineTo |
Draw a line to a point. |
MoveTo |
Move to a point (start a new subpath). |
NoneValueType |
Singleton type for None values (as in SVG). |
OffsetEffect |
Offset filter effect. |
Path |
Path drawing element composed of path actions. |
PathAction |
Abstract base class for path actions. |
QuadraticCurveTo |
Draw a quadratic Bezier curve. |
Rectangle |
Rectangle drawing element with optional rounded corners. |
Text |
Text drawing element. |
TextAnchor |
Text anchor options. |
Functions:
| Name | Description |
|---|---|
drawing_elements_to_shapely |
Convert drawing elements to shapely geometry. |
get_drawing_elements_anchor_point |
Get anchor point of drawing elements. |
get_drawing_elements_angle |
Get border point at an angle from center. |
get_drawing_elements_bbox |
Get bounding box of drawing elements. |
get_drawing_elements_border |
Get border point in a direction from center. |
get_initial_value |
Get the initial value of a presentation attribute. |
Attributes:
| Name | Type | Description |
|---|---|---|
NoneValue |
A singleton value for type |
ClosePath
dataclass
Bases: PathAction
Close the current path.
Methods:
| Name | Description |
|---|---|
transformed |
Apply a transformation. |
transformed
transformed(transformation: Transformation, current_point: Point) -> ClosePath
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation (unused). |
required |
current_point
|
Point
|
Current point (unused). |
required |
Returns:
| Type | Description |
|---|---|
ClosePath
|
A new ClosePath. |
Source code in src/momapy/drawing.py
CompositeEffect
dataclass
CompositeEffect(result: str | None = None, *, in_: FilterEffectInput | str | None = None, in2: FilterEffectInput | str | None = None, operator: CompositionOperator | None = OVER)
Bases: FilterEffect
Composite filter effect.
Attributes:
| Name | Type | Description |
|---|---|---|
in_ |
FilterEffectInput | str | None
|
First input or filter effect name. |
in2 |
FilterEffectInput | str | None
|
Second input or filter effect name. |
operator |
CompositionOperator | None
|
Composition operator. |
CompositionOperator
Bases: Enum
Composition operators for filter effects.
CurveTo
dataclass
Bases: PathAction
Draw a cubic Bezier curve.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Point
|
End point. |
control_point1 |
Point
|
First control point. |
control_point2 |
Point
|
Second control point. |
Methods:
| Name | Description |
|---|---|
to_geometry |
Convert to BezierCurve geometry. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation. |
to_geometry
to_geometry(current_point: Point) -> BezierCurve
Convert to BezierCurve geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
BezierCurve
|
A BezierCurve. |
Source code in src/momapy/drawing.py
to_shapely
to_shapely(current_point: Point, n_segs: int = 50) -> GeometryCollection
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
n_segs
|
int
|
Number of segments. |
50
|
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A LineString approximating the curve. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation, current_point: Point) -> CurveTo
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Start point (unused). |
required |
Returns:
| Type | Description |
|---|---|
CurveTo
|
A new CurveTo with transformed points. |
Source code in src/momapy/drawing.py
DrawingElement
dataclass
DrawingElement(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None)
Bases: ABC
Abstract base class for drawing elements.
Attributes:
| Name | Type | Description |
|---|---|---|
class_ |
str | None
|
CSS class name. |
fill |
NoneValueType | Color | None
|
Fill color. |
fill_rule |
FillRule | None
|
Fill rule for complex shapes. |
filter |
NoneValueType | Filter | None
|
Filter to apply. |
font_family |
str | None
|
Font family. |
font_size |
float | None
|
Font size. |
font_style |
FontStyle | None
|
Font style. |
font_weight |
FontWeight | int | None
|
Font weight. |
id_ |
str | None
|
Element ID. |
stroke |
NoneValueType | Color | None
|
Stroke color. |
stroke_dasharray |
NoneValueType | tuple[float, ...] | None
|
Stroke dash pattern. |
stroke_dashoffset |
NoneValueType | float | None
|
Stroke dash offset. |
stroke_width |
NoneValueType | float | None
|
Stroke width. |
text_anchor |
TextAnchor | None
|
Text anchor. |
transform |
NoneValueType | tuple[Transformation] | None
|
Transformation tuple. |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_shapely |
Convert to a shapely geometry collection. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_shapely
abstractmethod
Convert to a shapely geometry collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_polygons
|
Whether to convert to polygons. |
False
|
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A shapely GeometryCollection. |
Source code in src/momapy/drawing.py
DropShadowEffect
dataclass
DropShadowEffect(result: str | None = None, *, dx: float = 0.0, dy: float = 0.0, std_deviation: float = 0.0, flood_opacity: float = 1.0, flood_color: Color = black)
Bases: FilterEffect
Drop shadow filter effect.
Attributes:
| Name | Type | Description |
|---|---|---|
dx |
float
|
Horizontal offset of the shadow. |
dy |
float
|
Vertical offset of the shadow. |
std_deviation |
float
|
Standard deviation for blur. |
flood_opacity |
float
|
Opacity of the shadow. |
flood_color |
Color
|
Color of the shadow. |
Methods:
| Name | Description |
|---|---|
to_compat |
Convert to more compatible filter effects. |
to_compat
to_compat() -> list[FilterEffect]
Convert to more compatible filter effects.
Returns:
| Type | Description |
|---|---|
list[FilterEffect]
|
List of equivalent filter effects. |
Source code in src/momapy/drawing.py
EdgeMode
Bases: Enum
Edge mode for blur effects.
Ellipse
dataclass
Ellipse(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, point: Point, rx: float, ry: float)
Bases: DrawingElement
Ellipse drawing element.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Point
|
Center point. |
rx |
float
|
X-radius. |
ry |
float
|
Y-radius. |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_path |
Convert to a Path. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_path
to_path() -> Path
Convert to a Path.
Returns:
| Type | Description |
|---|---|
Path
|
A Path approximating the ellipse. |
Source code in src/momapy/drawing.py
to_shapely
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_polygons
|
Whether to return polygons. |
False
|
Returns:
| Type | Description |
|---|---|
|
A GeometryCollection containing the ellipse. |
Source code in src/momapy/drawing.py
EllipticalArc
dataclass
EllipticalArc(point: Point, rx: float, ry: float, x_axis_rotation: float, arc_flag: int, sweep_flag: int)
Bases: PathAction
Draw an elliptical arc.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Point
|
End point. |
rx |
float
|
X-radius. |
ry |
float
|
Y-radius. |
x_axis_rotation |
float
|
Rotation of x-axis. |
arc_flag |
int
|
Large arc flag. |
sweep_flag |
int
|
Sweep flag. |
Methods:
| Name | Description |
|---|---|
to_geometry |
Convert to geometry. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation. |
to_geometry
to_geometry(current_point: Point) -> EllipticalArc
Convert to geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
EllipticalArc
|
An EllipticalArc geometry. |
Source code in src/momapy/drawing.py
to_shapely
to_shapely(current_point: Point) -> GeometryCollection
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A LineString approximating the arc. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation, current_point: Point) -> EllipticalArc
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
EllipticalArc
|
A new EllipticalArc with transformed parameters. |
Source code in src/momapy/drawing.py
FillRule
Bases: Enum
Fill rule for complex shapes.
Filter
dataclass
Filter(*, id_: str = make_uuid4_as_str(), filter_units: FilterUnits = OBJECT_BOUNDING_BOX, effects: tuple[FilterEffect] = tuple(), width: float | str = '120%', height: float | str = '120%', x: float | str = '-10%', y: float | str = '-10%')
Bases: object
Filter with multiple effects.
Attributes:
| Name | Type | Description |
|---|---|---|
id_ |
str
|
Unique identifier. |
filter_units |
FilterUnits
|
Units for filter region. |
effects |
tuple[FilterEffect]
|
Tuple of filter effects. |
width |
float | str
|
Width of filter region. |
height |
float | str
|
Height of filter region. |
x |
float | str
|
X position of filter region. |
y |
float | str
|
Y position of filter region. |
Methods:
| Name | Description |
|---|---|
to_compat |
Convert to compatible filter with simpler effects. |
to_compat
Convert to compatible filter with simpler effects.
Returns:
| Type | Description |
|---|---|
Self
|
A filter with effects replaced by simpler equivalents. |
Source code in src/momapy/drawing.py
FilterEffect
dataclass
Bases: ABC
Abstract base class for filter effects.
FilterEffectInput
Bases: Enum
Filter effect input types.
FilterUnits
Bases: Enum
Units for filter regions.
FloodEffect
dataclass
Bases: FilterEffect
Flood filter effect.
Attributes:
| Name | Type | Description |
|---|---|---|
flood_color |
Color
|
Color of the flood. |
flood_opacity |
float
|
Opacity of the flood. |
FontStyle
Bases: Enum
Font style options.
FontWeight
Bases: Enum
Font weight options.
GaussianBlurEffect
dataclass
GaussianBlurEffect(result: str | None = None, *, in_: FilterEffectInput | str | None = None, std_deviation: float = 0.0, edge_mode: NoneValueType | EdgeMode = NoneValue)
Bases: FilterEffect
Gaussian blur filter effect.
Attributes:
| Name | Type | Description |
|---|---|---|
in_ |
FilterEffectInput | str | None
|
Input or filter effect name. |
std_deviation |
float
|
Standard deviation for blur. |
edge_mode |
NoneValueType | EdgeMode
|
Edge handling mode. |
Group
dataclass
Group(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, elements: tuple[DrawingElement] = tuple())
Bases: DrawingElement
Group of drawing elements.
Attributes:
| Name | Type | Description |
|---|---|---|
elements |
tuple[DrawingElement]
|
Tuple of child elements. |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation to all elements. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_shapely
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_polygons
|
Whether to convert to polygons. |
False
|
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A GeometryCollection of all elements. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Self
Apply a transformation to all elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new Group with transformed elements. |
Source code in src/momapy/drawing.py
LineTo
dataclass
LineTo(point: Point)
Bases: PathAction
Draw a line to a point.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Point
|
The end point. |
Methods:
| Name | Description |
|---|---|
to_geometry |
Convert to a segment. |
to_shapely |
Convert to shapely LineString. |
transformed |
Apply a transformation. |
to_geometry
to_shapely
to_shapely(current_point: Point) -> LineString
Convert to shapely LineString.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
LineString
|
A LineString. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation, current_point: Point)
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Current point (unused). |
required |
Returns:
| Type | Description |
|---|---|
|
A new LineTo with transformed point. |
Source code in src/momapy/drawing.py
MoveTo
dataclass
MoveTo(point: Point)
Bases: PathAction
Move to a point (start a new subpath).
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Point
|
The point to move to. |
Methods:
| Name | Description |
|---|---|
transformed |
Apply a transformation. |
transformed
transformed(transformation: Transformation, current_point: Point) -> MoveTo
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Current point (unused). |
required |
Returns:
| Type | Description |
|---|---|
MoveTo
|
A new MoveTo with transformed point. |
Source code in src/momapy/drawing.py
NoneValueType
Bases: object
Singleton type for None values (as in SVG).
OffsetEffect
dataclass
OffsetEffect(result: str | None = None, *, in_: FilterEffectInput | str | None = None, dx: float = 0.0, dy: float = 0.0)
Bases: FilterEffect
Offset filter effect.
Attributes:
| Name | Type | Description |
|---|---|---|
in_ |
FilterEffectInput | str | None
|
Input or filter effect name. |
dx |
float
|
Horizontal offset. |
dy |
float
|
Vertical offset. |
Path
dataclass
Path(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, actions: tuple[PathAction] = tuple())
Bases: DrawingElement
Path drawing element composed of path actions.
Attributes:
| Name | Type | Description |
|---|---|---|
actions |
tuple[PathAction]
|
Tuple of path actions. |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_path_with_bezier_curves |
Convert to path with only Bezier curves. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation to all actions. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_path_with_bezier_curves
Convert to path with only Bezier curves.
Converts elliptical arcs to Bezier curves.
Returns:
| Type | Description |
|---|---|
Self
|
A new Path with Bezier curves only. |
Source code in src/momapy/drawing.py
to_shapely
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_polygons
|
Whether to convert closed paths to polygons. |
False
|
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A GeometryCollection. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Self
Apply a transformation to all actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new Path with transformed actions. |
Source code in src/momapy/drawing.py
QuadraticCurveTo
dataclass
Bases: PathAction
Draw a quadratic Bezier curve.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Point
|
End point. |
control_point |
Point
|
Control point. |
Methods:
| Name | Description |
|---|---|
to_curve_to |
Convert to cubic CurveTo. |
to_geometry |
Convert to BezierCurve geometry. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation. |
to_curve_to
Convert to cubic CurveTo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
CurveTo
|
An equivalent CurveTo. |
Source code in src/momapy/drawing.py
to_geometry
to_geometry(current_point: Point) -> BezierCurve
Convert to BezierCurve geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
BezierCurve
|
A BezierCurve. |
Source code in src/momapy/drawing.py
to_shapely
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Start point. |
required | |
n_segs
|
Number of segments. |
50
|
Returns:
| Type | Description |
|---|---|
|
A LineString approximating the curve. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation, current_point: Point) -> QuadraticCurveTo
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Start point (unused). |
required |
Returns:
| Type | Description |
|---|---|
QuadraticCurveTo
|
A new QuadraticCurveTo with transformed points. |
Source code in src/momapy/drawing.py
Rectangle
dataclass
Rectangle(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, point: Point, width: float, height: float, rx: float, ry: float)
Bases: DrawingElement
Rectangle drawing element with optional rounded corners.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Point
|
Top-left corner. |
width |
float
|
Width. |
height |
float
|
Height. |
rx |
float
|
X-radius for rounded corners. |
ry |
float
|
Y-radius for rounded corners. |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_path |
Convert to a Path. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_path
to_path() -> Path
Convert to a Path.
Returns:
| Type | Description |
|---|---|
Path
|
A Path representing the rectangle. |
Source code in src/momapy/drawing.py
to_shapely
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_polygons
|
Whether to return polygons. |
False
|
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A GeometryCollection. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Path
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
A transformed Path. |
Source code in src/momapy/drawing.py
Text
dataclass
Text(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, text: str, point: Point)
Bases: DrawingElement
Text drawing element.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str
|
The text content. |
point |
Point
|
Position of the text. |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_shapely |
Convert to shapely geometry. |
transformed |
Apply a transformation. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_shapely
Convert to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_polygons
|
Whether to convert to polygons. |
False
|
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A GeometryCollection containing the point. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Self
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the text element. |
Source code in src/momapy/drawing.py
TextAnchor
Bases: Enum
Text anchor options.
drawing_elements_to_shapely
drawing_elements_to_shapely(drawing_elements: Sequence[DrawingElement]) -> GeometryCollection
Convert drawing elements to shapely geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Sequence of drawing elements. |
required |
Returns:
| Type | Description |
|---|---|
GeometryCollection
|
A GeometryCollection. |
Source code in src/momapy/drawing.py
get_drawing_elements_anchor_point
get_drawing_elements_anchor_point(drawing_elements, anchor_point: str, center: Point | None = None) -> Point
Get anchor point of drawing elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Drawing elements. |
required | |
anchor_point
|
str
|
Name of anchor point. |
required |
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
The anchor point. |
Source code in src/momapy/drawing.py
get_drawing_elements_angle
get_drawing_elements_angle(drawing_elements: Sequence[DrawingElement], angle: float, unit='degrees', center: Point | None = None) -> Point
Get border point at an angle from center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Drawing elements. |
required |
angle
|
float
|
The angle. |
required |
unit
|
Unit ('degrees' or 'radians'). |
'degrees'
|
|
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
The border point. |
Source code in src/momapy/drawing.py
get_drawing_elements_bbox
get_drawing_elements_bbox(drawing_elements: Sequence[DrawingElement]) -> Bbox
Get bounding box of drawing elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Drawing elements. |
required |
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_drawing_elements_border
get_drawing_elements_border(drawing_elements: Sequence[DrawingElement], point: Point, center: Point | None = None) -> Point
Get border point in a direction from center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Drawing elements. |
required |
point
|
Point
|
Direction point. |
required |
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
The border point. |
Source code in src/momapy/drawing.py
get_initial_value
Get the initial value of a presentation attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attr_name
|
str
|
Name of the attribute. |
required |
Returns:
| Type | Description |
|---|---|
|
The initial value. |