Geometry - momapy

Skip to content

# Geometry

## `` momapy.geometry

Classes and functions for geometry

Classes:

Name | Description
--- | ---
`Bbox` | Class for bounding boxes
`BezierCurve` | Class for bezier curves
`EllipticalArc` | Class for elliptical arcs
`GeometryObject` | Base class for geometry objects
`Line` | Class for lines
`MatrixTransformation` | Class for matrix transformations
`Point` | Class for points
`Rotation` | Class for rotations
`Scaling` | Class for scalings
`Segment` | Class for segments
`Transformation` | Base class for transformations
`Translation` | Class for translations

### `` Bbox `dataclass`

    Bbox(position: Point, width: float, height: float)

Bases: `object`

Class for bounding boxes

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`position` | `Point` |  | required
`width` | `float` |  | required
`height` | `float` |  | required

Methods:

Name | Description
--- | ---
`anchor_point` | Return a given anchor point of the bounding box
`center` | Return the center anchor point of the bounding box
`east` | Return the east anchor point of the bounding box
`east_north_east` | Return the east north east anchor point of the bounding box
`east_south_east` | Return the east south east anchor point of the bounding box
`from_bounds` | Create and return a bounding box from shaply bounds (min_x, min_y, max_x, max_y)
`isnan` | Return `true` if the position of the bounding box has a `nan` coordinate, `false` otherwise
`north` | Return the north anchor point of the bounding box
`north_east` | Return the north east anchor point of the bounding box
`north_north_east` | Return the north north east anchor point of the bounding box
`north_north_west` | Return the north north west anchor point of the bounding box
`north_west` | Return the north west anchor point of the bounding box
`size` | The size of the bounding box
`south` | Return the south anchor point of the bounding box
`south_east` | Return the south east anchor point of the bounding box
`south_south_east` | Return the south south east anchor point of the bounding box
`south_south_west` | Return the south south west anchor point of the bounding box
`south_west` | Return the south west anchor point of the bounding box
`west` | Return the west anchor point of the bounding box
`west_north_west` | Return the west north west anchor point of the bounding box
`west_south_west` | Return the west south west anchor point of the bounding box

Attributes:

Name | Type | Description
--- | --- | ---
`x` | `float` | The x coordinate of the bounding box
`y` | `float` | The y coordinate of the bounding box

#### `` anchor_point

    anchor_point(anchor_point: str) -> Point

Return a given anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    496
    497
    498
    def anchor_point(self, anchor_point: str) -> Point:
        """Return a given anchor point of the bounding box"""
        return getattr(self, anchor_point)()

#### `` center

    center() -> Point

Return the center anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    564
    565
    566
    def center(self) -> Point:
        """Return the center anchor point of the bounding box"""
        return Point(self.x, self.y)

#### `` east

    east() -> Point

Return the east anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    524
    525
    526
    def east(self) -> Point:
        """Return the east anchor point of the bounding box"""
        return Point(self.x + self.width / 2, self.y)

#### `` east_north_east

    east_north_east() -> Point

Return the east north east anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    520
    521
    522
    def east_north_east(self) -> Point:
        """Return the east north east anchor point of the bounding box"""
        return Point(self.x + self.width / 2, self.y - self.height / 4)

#### `` east_south_east

    east_south_east() -> Point

Return the east south east anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    528
    529
    530
    def east_south_east(self) -> Point:
        """Return the east south east anchor point of the bounding box"""
        return Point(self.x + self.width / 2, self.y + self.width / 4)

#### `` from_bounds `classmethod`

    from_bounds(bounds: tuple[float, float, float, float])

Create and return a bounding box from shaply bounds (min_x, min_y, max_x, max_y)

Source code in `src/momapy/geometry.py`

    572
    573
    574
    575
    576
    577
    578
    579
    @classmethod
    def from_bounds(cls, bounds: tuple[float, float, float, float]):
        """Create and return a bounding box from shaply bounds (min_x, min_y, max_x, max_y)"""
        return cls(
            Point((bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2),
            bounds[2] - bounds[0],
            bounds[3] - bounds[1],
        )

#### `` isnan

    isnan() -> bool

Return `true` if the position of the bounding box has a `nan` coordinate, `false` otherwise

Source code in `src/momapy/geometry.py`

    568
    569
    570
    def isnan(self) -> bool:
        """Return `true` if the position of the bounding box has a `nan` coordinate, `false` otherwise"""
        return self.position.isnan()

#### `` north

    north() -> Point

Return the north anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    508
    509
    510
    def north(self) -> Point:
        """Return the north anchor point of the bounding box"""
        return Point(self.x, self.y - self.height / 2)

#### `` north_east

    north_east() -> Point

Return the north east anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    516
    517
    518
    def north_east(self) -> Point:
        """Return the north east anchor point of the bounding box"""
        return Point(self.x + self.width / 2, self.y - self.height / 2)

#### `` north_north_east

    north_north_east() -> Point

Return the north north east anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    512
    513
    514
    def north_north_east(self) -> Point:
        """Return the north north east anchor point of the bounding box"""
        return Point(self.x + self.width / 4, self.y - self.height / 2)

#### `` north_north_west

    north_north_west() -> Point

Return the north north west anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    504
    505
    506
    def north_north_west(self) -> Point:
        """Return the north north west anchor point of the bounding box"""
        return Point(self.x - self.width / 4, self.y - self.height / 2)

#### `` north_west

    north_west() -> Point

Return the north west anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    500
    501
    502
    def north_west(self) -> Point:
        """Return the north west anchor point of the bounding box"""
        return Point(self.x - self.width / 2, self.y - self.height / 2)

#### `` size

    size() -> tuple[float, float]

The size of the bounding box

Source code in `src/momapy/geometry.py`

    492
    493
    494
    def size(self) -> tuple[float, float]:
        """The size of the bounding box"""
        return (self.width, self.height)

#### `` south

    south() -> Point

Return the south anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    540
    541
    542
    def south(self) -> Point:
        """Return the south anchor point of the bounding box"""
        return Point(self.x, self.y + self.height / 2)

#### `` south_east

    south_east() -> Point

Return the south east anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    532
    533
    534
    def south_east(self) -> Point:
        """Return the south east anchor point of the bounding box"""
        return Point(self.x + self.width / 2, self.y + self.height / 2)

#### `` south_south_east

    south_south_east() -> Point

Return the south south east anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    536
    537
    538
    def south_south_east(self) -> Point:
        """Return the south south east anchor point of the bounding box"""
        return Point(self.x + self.width / 4, self.y + self.height / 2)

#### `` south_south_west

    south_south_west() -> Point

Return the south south west anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    544
    545
    546
    def south_south_west(self) -> Point:
        """Return the south south west anchor point of the bounding box"""
        return Point(self.x - self.width / 4, self.y + self.height / 2)

#### `` south_west

    south_west() -> Point

Return the south west anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    548
    549
    550
    def south_west(self) -> Point:
        """Return the south west anchor point of the bounding box"""
        return Point(self.x - self.width / 2, self.y + self.height / 2)

#### `` west

    west() -> Point

Return the west anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    556
    557
    558
    def west(self) -> Point:
        """Return the west anchor point of the bounding box"""
        return Point(self.x - self.width / 2, self.y)

#### `` west_north_west

    west_north_west() -> Point

Return the west north west anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    560
    561
    562
    def west_north_west(self) -> Point:
        """Return the west north west anchor point of the bounding box"""
        return Point(self.x - self.width / 2, self.y - self.height / 4)

#### `` west_south_west

    west_south_west() -> Point

Return the west south west anchor point of the bounding box

Source code in `src/momapy/geometry.py`

    552
    553
    554
    def west_south_west(self) -> Point:
        """Return the west south west anchor point of the bounding box"""
        return Point(self.x - self.width / 2, self.y + self.height / 4)

#### `` x `property`

    x: float

The x coordinate of the bounding box

#### `` y `property`

    y: float

The y coordinate of the bounding box

### `` BezierCurve `dataclass`

    BezierCurve(
        p1: Point,
        p2: Point,
        control_points: tuple[Point, ...] = tuple(),
    )

Bases: `GeometryObject`

Class for bezier curves

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`p1` | `Point` |  | required
`p2` | `Point` |  | required
`control_points` | `tuple[Point, ...]` | Built-in immutable sequence. If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items. If the argument is a tuple, the return value is the same object. | `<dynamic>`

Methods:

Name | Description
--- | ---
`bbox` | Compute and return the bounding box of the bezier curve
`evaluate` | Compute and return the point at a given parameter value
`evaluate_multi` | Compute and return the points at given parameter values
`get_angle_at_fraction` | Compute and return the angle in radians formed by the tangent of the bezier curve and the horizontal at a given fraction (of the total length)
`get_intersection_with_line` | Compute and return the intersection of the bezier curve with a given line
`get_position_and_angle_at_fraction` | Compute and return the position on the bezier curve at a given fraction and the angle in radians formed of the tangent of the bezier curve and the horizontal at that position
`get_position_at_fraction` | Compute and return the position on the bezier curve at a given fraction (of the total length)
`length` | Compute and return the length of the bezier curve
`reversed` | Compute and return a reversed copy of the bezier curve
`shortened` | Compute and return a copy of the bezier curve shortened by a given length
`to_shapely` | Compute and return a shapely line string reproducing the bezier curve
`transformed` | Compute and return a copy of the bezier curve transformed with a given transformation

#### `` bbox

    bbox()

Compute and return the bounding box of the bezier curve

Source code in `src/momapy/geometry.py`

    346
    347
    348
    def bbox(self):
        """Compute and return the bounding box of the bezier curve"""
        return Bbox.from_bounds(self.to_shapely().bounds)

#### `` evaluate

    evaluate(s: float) -> Point

Compute and return the point at a given parameter value

Source code in `src/momapy/geometry.py`

    297
    298
    299
    300
    def evaluate(self, s: float) -> Point:
        """Compute and return the point at a given parameter value"""
        evaluation = self._to_bezier().evaluate(s)
        return Point.from_fortranarray(evaluation)

#### `` evaluate_multi

    evaluate_multi(s: ndarray) -> list[Point]

Compute and return the points at given parameter values

Source code in `src/momapy/geometry.py`

    302
    303
    304
    305
    def evaluate_multi(self, s: numpy.ndarray) -> list[Point]:
        """Compute and return the points at given parameter values"""
        evaluation = self._to_bezier().evaluate_multi(s)
        return [Point(e[0], e[1]) for e in evaluation.T]

#### `` get_angle_at_fraction

    get_angle_at_fraction(fraction: float)

Compute and return the angle in radians formed by the tangent of the bezier curve and the horizontal at a given fraction (of the total length)

Source code in `src/momapy/geometry.py`

    316
    317
    318
    def get_angle_at_fraction(self, fraction: float):
        """Compute and return the angle in radians formed by the tangent of the bezier curve and the horizontal at a given fraction (of the total length)"""
        return get_angle_at_fraction_of_bezier_curve(self, fraction)

#### `` get_intersection_with_line

    get_intersection_with_line(
        line: Line,
    ) -> list[Point] | list[Segment]

Compute and return the intersection of the bezier curve with a given line

Source code in `src/momapy/geometry.py`

    307
    308
    309
    def get_intersection_with_line(self, line: Line) -> list[Point] | list[Segment]:
        """Compute and return the intersection of the bezier curve with a given line"""
        return get_intersection_of_line_and_bezier_curve(line, self)

#### `` get_position_and_angle_at_fraction

    get_position_and_angle_at_fraction(fraction: float)

Compute and return the position on the bezier curve at a given fraction and the angle in radians formed of the tangent of the bezier curve and the horizontal at that position

Source code in `src/momapy/geometry.py`

    320
    321
    322
    def get_position_and_angle_at_fraction(self, fraction: float):
        """Compute and return the position on the bezier curve at a given fraction and the angle in radians formed of the tangent of the bezier curve and the horizontal at that position"""
        return get_position_and_angle_at_fraction_of_bezier_curve(self, fraction)

#### `` get_position_at_fraction

    get_position_at_fraction(fraction: float)

Compute and return the position on the bezier curve at a given fraction (of the total length)

Source code in `src/momapy/geometry.py`

    311
    312
    313
    314
    def get_position_at_fraction(self, fraction: float):
        """Compute and return the position on the bezier curve at a given fraction (of the total length)"""

        return get_position_at_fraction_of_bezier_curve(self, fraction)

#### `` length

    length() -> float

Compute and return the length of the bezier curve

Source code in `src/momapy/geometry.py`

    293
    294
    295
    def length(self) -> float:
        """Compute and return the length of the bezier curve"""
        return self._to_bezier().length

#### `` reversed

    reversed()

Compute and return a reversed copy of the bezier curve

Source code in `src/momapy/geometry.py`

    334
    335
    336
    def reversed(self):
        """Compute and return a reversed copy of the bezier curve"""
        return reverse_bezier_curve(self)

#### `` shortened

    shortened(
        length: float,
        start_or_end: Literal["start", "end"] = "end",
    ) -> BezierCurve

Compute and return a copy of the bezier curve shortened by a given length

Source code in `src/momapy/geometry.py`

    324
    325
    326
    327
    328
    def shortened(
        self, length: float, start_or_end: typing.Literal["start", "end"] = "end"
    ) -> "BezierCurve":
        """Compute and return a copy of the bezier curve shortened by a given length"""
        return shorten_bezier_curve(self, length, start_or_end)

#### `` to_shapely

    to_shapely(n_segs=50)

Compute and return a shapely line string reproducing the bezier curve

Source code in `src/momapy/geometry.py`

    338
    339
    340
    341
    342
    343
    344
    def to_shapely(self, n_segs=50):
        """Compute and return a shapely line string reproducing the bezier curve"""

        points = self.evaluate_multi(
            numpy.arange(0, 1 + 1 / n_segs, 1 / n_segs, dtype="double")
        )
        return shapely.LineString([point.to_tuple() for point in points])

#### `` transformed

    transformed(transformation)

Compute and return a copy of the bezier curve transformed with a given transformation

Source code in `src/momapy/geometry.py`

    330
    331
    332
    def transformed(self, transformation):
        """Compute and return a copy of the bezier curve transformed with a given transformation"""
        return transform_bezier_curve(self, transformation)

### `` EllipticalArc `dataclass`

    EllipticalArc(
        p1: Point,
        p2: Point,
        rx: float,
        ry: float,
        x_axis_rotation: float,
        arc_flag: int,
        sweep_flag: int,
    )

Bases: `GeometryObject`

Class for elliptical arcs

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`p1` | `Point` |  | required
`p2` | `Point` |  | required
`rx` | `float` |  | required
`ry` | `float` |  | required
`x_axis_rotation` | `float` |  | required
`arc_flag` | `int` |  | required
`sweep_flag` | `int` |  | required

Methods:

Name | Description
--- | ---
`bbox` | Compute and return the bounding box of the elliptical arc
`get_angle_at_fraction` | Compute and return the angle in radians formed by the tangent of the elliptical arc and the horizontal at a given fraction (of the total length)
`get_center` | Compute and return the center of the elliptical arc
`get_center_parameterization` | Compute and return the center paramaterizaion of the elliptical arc (cx, cy, rx, ry, sigma, theta1, theta2, delta_theta)
`get_intersection_with_line` | Compute and return the intersection of the elliptical arc with a given line
`get_position_and_angle_at_fraction` | Compute and return the position on the elliptical arc at a given fraction and the angle in radians formed of the tangent of the bezier curve at that position and the horizontal
`get_position_at_fraction` | Compute and return the position on the elliptical arc at a given fraction (of the total length)
`reversed` | Compute and return a reversed copy of the elliptical arc
`shortened` | Compute and return a copy of the elliptical arc shortened by a given length
`to_bezier_curves` | Compute and return a bezier curve reproducing the elliptical arc
`to_shapely` | Compute and return a shapely linestring reproducing the elliptical arc
`transformed` | Compute and return a copy of the elliptical arc transformed by a given transformation

#### `` bbox

    bbox() -> Bbox

Compute and return the bounding box of the elliptical arc

Source code in `src/momapy/geometry.py`

    446
    447
    448
    def bbox(self) -> "Bbox":
        """Compute and return the bounding box of the elliptical arc"""
        return Bbox.from_bounds(self.to_shapely().bounds)

#### `` get_angle_at_fraction

    get_angle_at_fraction(fraction: float) -> float

Compute and return the angle in radians formed by the tangent of the elliptical arc and the horizontal at a given fraction (of the total length)

Source code in `src/momapy/geometry.py`

    381
    382
    383
    def get_angle_at_fraction(self, fraction: float) -> float:
        """Compute and return the angle in radians formed by the tangent of the elliptical arc and the horizontal at a given fraction (of the total length)"""
        return get_angle_at_fraction_of_elliptical_arc(self, fraction)

#### `` get_center

    get_center() -> Point

Compute and return the center of the elliptical arc

Source code in `src/momapy/geometry.py`

    373
    374
    375
    def get_center(self) -> Point:
        """Compute and return the center of the elliptical arc"""
        return get_center_of_elliptical_arc(self)

#### `` get_center_parameterization

    get_center_parameterization() -> tuple[
        float, float, float, float, float, float, float, float
    ]

Compute and return the center paramaterizaion of the elliptical arc (cx, cy, rx, ry, sigma, theta1, theta2, delta_theta)

Source code in `src/momapy/geometry.py`

    367
    368
    369
    370
    371
    def get_center_parameterization(
        self,
    ) -> tuple[float, float, float, float, float, float, float, float]:
        """Compute and return the center paramaterizaion of the elliptical arc (cx, cy, rx, ry, sigma, theta1, theta2, delta_theta)"""
        return get_center_parameterization_of_elliptical_arc(self)

#### `` get_intersection_with_line

    get_intersection_with_line(line: Line) -> list[Point]

Compute and return the intersection of the elliptical arc with a given line

Source code in `src/momapy/geometry.py`

    363
    364
    365
    def get_intersection_with_line(self, line: Line) -> list[Point]:
        """Compute and return the intersection of the elliptical arc with a given line"""
        return get_intersection_of_line_and_elliptical_arc(line, self)

#### `` get_position_and_angle_at_fraction

    get_position_and_angle_at_fraction(
        fraction: float,
    ) -> tuple[Point, float]

Compute and return the position on the elliptical arc at a given fraction and the angle in radians formed of the tangent of the bezier curve at that position and the horizontal

Source code in `src/momapy/geometry.py`

    385
    386
    387
    388
    389
    def get_position_and_angle_at_fraction(
        self, fraction: float
    ) -> tuple[Point, float]:
        """Compute and return the position on the elliptical arc at a given fraction and the angle in radians formed of the tangent of the bezier curve at that position and the horizontal"""
        return get_position_and_angle_at_fraction_of_elliptical_arc(self, fraction)

#### `` get_position_at_fraction

    get_position_at_fraction(fraction: float) -> Point

Compute and return the position on the elliptical arc at a given fraction (of the total length)

Source code in `src/momapy/geometry.py`

    377
    378
    379
    def get_position_at_fraction(self, fraction: float) -> Point:
        """Compute and return the position on the elliptical arc at a given fraction (of the total length)"""
        return get_position_at_fraction_of_elliptical_arc(self, fraction)

#### `` reversed

    reversed() -> EllipticalArc

Compute and return a reversed copy of the elliptical arc

Source code in `src/momapy/geometry.py`

    462
    463
    464
    def reversed(self) -> "EllipticalArc":
        """Compute and return a reversed copy of the elliptical arc"""
        return reverse_elliptical_arc(self)

#### `` shortened

    shortened(
        length: float,
        start_or_end: Literal["start", "end"] = "end",
    ) -> EllipticalArc

Compute and return a copy of the elliptical arc shortened by a given length

Source code in `src/momapy/geometry.py`

    450
    451
    452
    453
    454
    455
    456
    def shortened(
        self,
        length: float,
        start_or_end: typing.Literal["start", "end"] = "end",
    ) -> "EllipticalArc":
        """Compute and return a copy of the elliptical arc shortened by a given length"""
        return shorten_elliptical_arc(self, length, start_or_end)

#### `` to_bezier_curves

    to_bezier_curves() -> BezierCurve

Compute and return a bezier curve reproducing the elliptical arc

Source code in `src/momapy/geometry.py`

    466
    467
    468
    def to_bezier_curves(self) -> BezierCurve:
        """Compute and return a bezier curve reproducing the elliptical arc"""
        return transform_elliptical_arc_to_bezier_curves(self)

#### `` to_shapely

    to_shapely()

Compute and return a shapely linestring reproducing the elliptical arc

Source code in `src/momapy/geometry.py`

    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    def to_shapely(self):
        """Compute and return a shapely linestring reproducing the elliptical arc"""

        def _split_line_string(
            line_string: shapely.LineString,
            point: Point,
        ):
            segment = Segment(
                Point.from_tuple(line_string.coords[0]),
                Point.from_tuple(line_string.coords[1]),
            )
            min_distance = segment.get_distance_to_point(point)
            min_i = 0
            for i, current_coord in enumerate(line_string.coords[2:]):
                previous_coord = line_string.coords[i + 1]
                segment = Segment(
                    Point.from_tuple(previous_coord),
                    Point.from_tuple(current_coord),
                )
                distance = segment.get_distance_to_point(point)
                if distance <= min_distance:
                    min_distance = distance
                    min_i = i
            left_coords = line_string.coords[0 : min_i + 1] + [point.to_shapely()]
            right_coords = [point.to_shapely()] + line_string.coords[min_i + 1 :]
            left_line_string = shapely.LineString(left_coords)
            right_line_string = shapely.LineString(right_coords)
            return [left_line_string, right_line_string]

        origin = shapely.Point(0, 0)
        circle = origin.buffer(1.0).boundary
        ellipse = shapely.affinity.scale(circle, self.rx, self.ry)
        ellipse = shapely.affinity.rotate(ellipse, self.x_axis_rotation)
        center = self.get_center()
        ellipse = shapely.affinity.translate(ellipse, center.x, center.y)
        line1 = Line(center, Point.from_tuple(ellipse.coords[0]))
        angle1 = get_angle_to_horizontal_of_line(line1)
        line2 = Line(center, Point.from_tuple(ellipse.coords[-2]))
        angle2 = get_angle_to_horizontal_of_line(line2)
        angle = angle1 - angle2
        if angle >= 0:
            sweep = 1
        else:
            sweep = 0
        if sweep != self.sweep_flag:
            ellipse = shapely.LineString(ellipse.coords[::-1])
        if ellipse.coords[0] == self.p1.to_tuple():
            ellipse = shapely.LineString(ellipse.coords[1:] + [ellipse.coords[0]])
        first_split = _split_line_string(ellipse, self.p1)
        multi_line = shapely.MultiLineString([first_split[1], first_split[0]])
        line_string = shapely.ops.linemerge(multi_line)
        second_split = _split_line_string(line_string, self.p2)
        shapely_arc = second_split[0]
        return shapely_arc

#### `` transformed

    transformed(
        transformation: Transformation,
    ) -> EllipticalArc

Compute and return a copy of the elliptical arc transformed by a given transformation

Source code in `src/momapy/geometry.py`

    458
    459
    460
    def transformed(self, transformation: "Transformation") -> "EllipticalArc":
        """Compute and return a copy of the elliptical arc transformed by a given transformation"""
        return transform_elliptical_arc(self, transformation)

### `` GeometryObject `dataclass`

    GeometryObject()

Bases: `ABC`

Base class for geometry objects

Methods:

Name | Description
--- | ---
`to_shapely` | Compute and return a shapely geometry object that reproduces the geometry object

#### `` to_shapely `abstractmethod`

    to_shapely() -> Geometry

Compute and return a shapely geometry object that reproduces the geometry object

Source code in `src/momapy/geometry.py`

    24
    25
    26
    27
    @abc.abstractmethod
    def to_shapely(self) -> shapely.Geometry:
        """Compute and return a shapely geometry object that reproduces the geometry object"""
        pass

### `` Line `dataclass`

    Line(p1: Point, p2: Point)

Bases: `GeometryObject`

Class for lines

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`p1` | `Point` |  | required
`p2` | `Point` |  | required

Methods:

Name | Description
--- | ---
`get_angle_to_horizontal` | Return the angle in radians formed by the line and the horizontal
`get_distance_to_point` | Compute and return the distance of a given point to the line
`get_intersection_with_line` | Compute and return the instersection of the line with another given line
`has_point` | Return `true` if a given point is on the line, `false` otherwise
`intercept` | Return the intercept of the line
`is_coincident_to_line` | Return `true` if the line is coincident to another given line, and `false` otherwise
`is_parallel_to_line` | Return `true` if the line is parallel to another given line, and `false` otherwise
`reversed` | Return a reversed copy of the line
`slope` | Return the slope of the line
`to_shapely` | Return a shapeply line string reproducing the line
`transformed` | Return a copy of the line transformed with the given transformation

#### `` get_angle_to_horizontal

    get_angle_to_horizontal() -> float

Return the angle in radians formed by the line and the horizontal

Source code in `src/momapy/geometry.py`

    145
    146
    147
    def get_angle_to_horizontal(self) -> float:
        """Return the angle in radians formed by the line and the horizontal"""
        return get_angle_to_horizontal_of_line(self)

#### `` get_distance_to_point

    get_distance_to_point(point: Point) -> float

Compute and return the distance of a given point to the line

Source code in `src/momapy/geometry.py`

    161
    162
    163
    def get_distance_to_point(self, point: Point) -> float:
        """Compute and return the distance of a given point to the line"""
        return get_distance_between_line_and_point(self, point)

#### `` get_intersection_with_line

    get_intersection_with_line(
        line: Line,
    ) -> list[Line] | list[Point]

Compute and return the instersection of the line with another given line

Source code in `src/momapy/geometry.py`

    157
    158
    159
    def get_intersection_with_line(self, line: "Line") -> list["Line"] | list["Point"]:
        """Compute and return the instersection of the line with another given line"""
        return get_intersection_of_lines(self, line)

#### `` has_point

    has_point(point: Point, max_distance: float = 0.01) -> bool

Return `true` if a given point is on the line, `false` otherwise

Source code in `src/momapy/geometry.py`

    165
    166
    167
    def has_point(self, point: Point, max_distance: float = 0.01) -> bool:
        """Return `true` if a given point is on the line, `false` otherwise"""
        return line_has_point(self, point, max_distance)

#### `` intercept

    intercept() -> float

Return the intercept of the line

Source code in `src/momapy/geometry.py`

    137
    138
    139
    140
    141
    142
    143
    def intercept(self) -> float:
        """Return the intercept of the line"""
        slope = self.slope()
        if not math.isnan(slope):
            return self.p1.y - slope * self.p1.x
        else:
            return float("NAN")

#### `` is_coincident_to_line

    is_coincident_to_line(line: Line) -> bool

Return `true` if the line is coincident to another given line, and `false` otherwise

Source code in `src/momapy/geometry.py`

    153
    154
    155
    def is_coincident_to_line(self, line: "Line") -> bool:
        """Return `true` if the line is coincident to another given line, and `false` otherwise"""
        return are_lines_coincident(self, line)

#### `` is_parallel_to_line

    is_parallel_to_line(line: Line) -> bool

Return `true` if the line is parallel to another given line, and `false` otherwise

Source code in `src/momapy/geometry.py`

    149
    150
    151
    def is_parallel_to_line(self, line: "Line") -> bool:
        """Return `true` if the line is parallel to another given line, and `false` otherwise"""
        return are_lines_parallel(self, line)

#### `` reversed

    reversed() -> Line

Return a reversed copy of the line

Source code in `src/momapy/geometry.py`

    173
    174
    175
    def reversed(self) -> "Line":
        """Return a reversed copy of the line"""
        return reverse_line(self)

#### `` slope

    slope() -> float

Return the slope of the line

Source code in `src/momapy/geometry.py`

    131
    132
    133
    134
    135
    def slope(self) -> float:
        """Return the slope of the line"""
        if self.p1.x != self.p2.x:
            return round((self.p2.y - self.p1.y) / (self.p2.x - self.p1.x), ROUNDING)
        return float("NAN")  # infinite slope

#### `` to_shapely

    to_shapely() -> LineString

Return a shapeply line string reproducing the line

Source code in `src/momapy/geometry.py`

    177
    178
    179
    180
    181
    182
    183
    184
    def to_shapely(self) -> shapely.LineString:
        """Return a shapeply line string reproducing the line"""
        return shapely.LineString(
            [
                self.p1.to_tuple(),
                self.p2.to_tuple(),
            ]
        )

#### `` transformed

    transformed(transformation: Transformation) -> Line

Return a copy of the line transformed with the given transformation

Source code in `src/momapy/geometry.py`

    169
    170
    171
    def transformed(self, transformation: "Transformation") -> "Line":
        """Return a copy of the line transformed with the given transformation"""
        return transform_line(self, transformation)

### `` MatrixTransformation `dataclass`

    MatrixTransformation(m: NDArray)

Bases: `Transformation`

Class for matrix transformations

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`m` | `ndarray[tuple[Any, ...], dtype[TypeVar]]` |  | required

Methods:

Name | Description
--- | ---
`inverted` | Compute and return the inverse of the matrix transformation
`to_matrix` | Return a matrix representation of the matrix transformation

#### `` inverted

    inverted() -> Transformation

Compute and return the inverse of the matrix transformation

Source code in `src/momapy/geometry.py`

    610
    611
    612
    def inverted(self) -> Transformation:
        """Compute and return the inverse of the matrix transformation"""
        return invert_matrix_transformation(self)

#### `` to_matrix

    to_matrix() -> NDArray

Return a matrix representation of the matrix transformation

Source code in `src/momapy/geometry.py`

    606
    607
    608
    def to_matrix(self) -> numpy.typing.NDArray:
        """Return a matrix representation of the matrix transformation"""
        return self.m

### `` Point `dataclass`

    Point(x: float, y: float)

Bases: `GeometryObject`

Class for points

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`x` | `float` |  | required
`y` | `float` |  | required

Methods:

Name | Description
--- | ---
`bbox` | Return the bounding box of the point
`from_fortranarray` | Return a point from a numpy fortran array representation
`from_shapely` | Return a point reproducing a given shapely point
`from_tuple` | Return a point from a tuple representation
`get_angle_to_horizontal` | Return the angle in radians formed by the line passing through the origin and the point and the horizontal
`get_intersection_with_line` | Compute and return a list of the intersections of the point and a given line
`isnan` | Return `true` if the point has a nan coordinate, `false` otherwise
`reversed` | Return a reversed copy of the point
`to_fortranarray` | Return a numpy fortran array representation of the point
`to_matrix` | Return a `numpy.array` representation of the point
`to_shapely` | Return a shapely point that reproduces the point
`to_tuple` | Return a tuple representation of the point
`transformed` | Return a copy of the the point transformed by the given transformation

#### `` bbox

    bbox() -> Bbox

Return the bounding box of the point

Source code in `src/momapy/geometry.py`

    100
    101
    102
    def bbox(self) -> "Bbox":
        """Return the bounding box of the point"""
        return Bbox(copy.deepcopy(self), 0, 0)

#### `` from_fortranarray `classmethod`

    from_fortranarray(fortranarray: Any) -> Self

Return a point from a numpy fortran array representation

Source code in `src/momapy/geometry.py`

    113
    114
    115
    116
    @classmethod
    def from_fortranarray(cls, fortranarray: typing.Any) -> typing.Self:
        """Return a point from a numpy fortran array representation"""
        return cls(fortranarray[0][0], fortranarray[1][1])

#### `` from_shapely `classmethod`

    from_shapely(point: Point) -> Self

Return a point reproducing a given shapely point

Source code in `src/momapy/geometry.py`

    108
    109
    110
    111
    @classmethod
    def from_shapely(cls, point: shapely.Point) -> typing.Self:
        """Return a point reproducing a given shapely point"""
        return cls(float(point.x), float(point.y))

#### `` from_tuple `classmethod`

    from_tuple(t: tuple[float, float]) -> Self

Return a point from a tuple representation

Source code in `src/momapy/geometry.py`

    118
    119
    120
    121
    @classmethod
    def from_tuple(cls, t: tuple[float, float]) -> typing.Self:
        """Return a point from a tuple representation"""
        return cls(t[0], t[1])

#### `` get_angle_to_horizontal

    get_angle_to_horizontal() -> float

Return the angle in radians formed by the line passing through the origin and the point and the horizontal

Source code in `src/momapy/geometry.py`

    77
    78
    79
    def get_angle_to_horizontal(self) -> float:
        """Return the angle in radians formed by the line passing through the origin and the point and the horizontal"""
        return get_angle_to_horizontal_of_point(self)

#### `` get_intersection_with_line

    get_intersection_with_line(line: Line) -> list[Point]

Compute and return a list of the intersections of the point and a given line

Source code in `src/momapy/geometry.py`

    73
    74
    75
    def get_intersection_with_line(self, line: "Line") -> list["Point"]:
        """Compute and return a list of the intersections of the point and a given line"""
        return get_intersection_of_line_and_point(line, self)

#### `` isnan

    isnan() -> bool

Return `true` if the point has a nan coordinate, `false` otherwise

Source code in `src/momapy/geometry.py`

    104
    105
    106
    def isnan(self) -> bool:
        """Return `true` if the point has a nan coordinate, `false` otherwise"""
        return math.isnan(self.x) or math.isnan(self.y)

#### `` reversed

    reversed() -> Point

Return a reversed copy of the point

Source code in `src/momapy/geometry.py`

    85
    86
    87
    def reversed(self) -> "Point":
        """Return a reversed copy of the point"""
        return reverse_point(self)

#### `` to_fortranarray

    to_fortranarray() -> Any

Return a numpy fortran array representation of the point

Source code in `src/momapy/geometry.py`

    96
    97
    98
    def to_fortranarray(self) -> typing.Any:
        """Return a numpy fortran array representation of the point"""
        return numpy.asfortranarray([[self.x], [self.y]])

#### `` to_matrix

    to_matrix() -> ndarray

Return a `numpy.array` representation of the point

Source code in `src/momapy/geometry.py`

    61
    62
    63
    64
    def to_matrix(self) -> numpy.ndarray:
        """Return a `numpy.array` representation of the point"""
        m = numpy.array([[self.x], [self.y], [1]], dtype=float)
        return m

#### `` to_shapely

    to_shapely() -> Point

Return a shapely point that reproduces the point

Source code in `src/momapy/geometry.py`

    92
    93
    94
    def to_shapely(self) -> shapely.Point:
        """Return a shapely point that reproduces the point"""
        return shapely.Point(self.x, self.y)

#### `` to_tuple

    to_tuple() -> tuple[float, float]

Return a tuple representation of the point

Source code in `src/momapy/geometry.py`

    66
    67
    68
    69
    70
    71
    def to_tuple(self) -> tuple[float, float]:
        """Return a tuple representation of the point"""
        return (
            self.x,
            self.y,
        )

#### `` transformed

    transformed(transformation: Transformation) -> Point

Return a copy of the the point transformed by the given transformation

Source code in `src/momapy/geometry.py`

    81
    82
    83
    def transformed(self, transformation: "Transformation") -> "Point":
        """Return a copy of the the point transformed by the given transformation"""
        return transform_point(self, transformation)

### `` Rotation `dataclass`

    Rotation(angle: float, point: Point | None = None)

Bases: `Transformation`

Class for rotations

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`angle` | `float` |  | required
`point` | `Point | None` |  | `None`

Methods:

Name | Description
--- | ---
`inverted` | Compute and return the inverse of the rotation
`to_matrix` | Compute and return a matrix representation of the rotation

#### `` inverted

    inverted() -> Transformation

Compute and return the inverse of the rotation

Source code in `src/momapy/geometry.py`

    640
    641
    642
    def inverted(self) -> Transformation:
        """Compute and return the inverse of the rotation"""
        return invert_rotation(self)

#### `` to_matrix

    to_matrix() -> NDArray

Compute and return a matrix representation of the rotation

Source code in `src/momapy/geometry.py`

    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    def to_matrix(self) -> numpy.typing.NDArray:
        """Compute and return a matrix representation of the rotation"""
        m = numpy.array(
            [
                [math.cos(self.angle), -math.sin(self.angle), 0],
                [math.sin(self.angle), math.cos(self.angle), 0],
                [0, 0, 1],
            ],
            dtype=float,
        )
        if self.point is not None:
            translation = Translation(self.point.x, self.point.y)
            m = numpy.matmul(
                numpy.matmul(translation.to_matrix(), m),
                translation.inverted().to_matrix(),
            )
        return m

### `` Scaling `dataclass`

    Scaling(sx: float, sy: float)

Bases: `Transformation`

Class for scalings

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`sx` | `float` |  | required
`sy` | `float` |  | required

Methods:

Name | Description
--- | ---
`inverted` | Compute and return the inverse of the scaling
`to_matrix` | Return a matrix representation of the scaling

#### `` inverted

    inverted() -> Transformation

Compute and return the inverse of the scaling

Source code in `src/momapy/geometry.py`

    681
    682
    683
    def inverted(self) -> Transformation:
        """Compute and return the inverse of the scaling"""
        return invert_scaling(self)

#### `` to_matrix

    to_matrix() -> NDArray

Return a matrix representation of the scaling

Source code in `src/momapy/geometry.py`

    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    def to_matrix(self) -> numpy.typing.NDArray:
        """Return a matrix representation of the scaling"""
        m = numpy.array(
            [
                [self.sx, 0, 0],
                [0, self.sy, 0],
                [0, 0, 1],
            ],
            dtype=float,
        )
        return m

### `` Segment `dataclass`

    Segment(p1: Point, p2: Point)

Bases: `GeometryObject`

Class for segments

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`p1` | `Point` |  | required
`p2` | `Point` |  | required

Methods:

Name | Description
--- | ---
`bbox` | Compute and return the bounding box of the segment
`from_shapely` | Compute and return the segment reproducing a shapely line string
`get_angle_at_fraction` | Compute and return the angle in radians formed by the segment and the horizontal at a given fraction (of the total length)
`get_angle_to_horizontal` | Compute and return the angle formed by the segment and the horizontal
`get_distance_to_point` | Return the distance of a given point to the segment
`get_intersection_with_line` | Compute and return the intersection of the segment with a given line
`get_position_and_angle_at_fraction` | Compute and return the position on the segment at a given fraction and the angle in radians formed of the segment and the horizontal at that position
`get_position_at_fraction` | Compute and return the position on the segment at a given fraction (of the total length)
`has_point` | Return `true` if the given point is on the segment, `false` otherwise
`length` | Return the length of the segment
`reversed` | Compute and return a reversed copy of the segment
`shortened` | Compute and return a copy of the segment shortened by a given length
`to_shapely` | Return a shapely line string reproducing the segment
`transformed` | Compute and return a copy of the segment transformed with a given transformation

#### `` bbox

    bbox() -> Bbox

Compute and return the bounding box of the segment

Source code in `src/momapy/geometry.py`

    253
    254
    255
    def bbox(self) -> "Bbox":
        """Compute and return the bounding box of the segment"""
        return Bbox.from_bounds(self.to_shapely().bounds)

#### `` from_shapely `classmethod`

    from_shapely(line_string: LineString) -> Self

Compute and return the segment reproducing a shapely line string

Source code in `src/momapy/geometry.py`

    257
    258
    259
    260
    261
    262
    263
    264
    @classmethod
    def from_shapely(cls, line_string: shapely.LineString) -> typing.Self:
        """Compute and return the segment reproducing a shapely line string"""
        shapely_points = line_string.boundary.geoms
        return cls(
            Point.from_shapely(shapely_points[0]),
            Point.from_shapely(shapely_points[1]),
        )

#### `` get_angle_at_fraction

    get_angle_at_fraction(fraction: float) -> float

Compute and return the angle in radians formed by the segment and the horizontal at a given fraction (of the total length)

Source code in `src/momapy/geometry.py`

    218
    219
    220
    def get_angle_at_fraction(self, fraction: float) -> float:
        """Compute and return the angle in radians formed by the segment and the horizontal at a given fraction (of the total length)"""
        return get_angle_at_fraction_of_segment(self, fraction)

#### `` get_angle_to_horizontal

    get_angle_to_horizontal() -> float

Compute and return the angle formed by the segment and the horizontal

Source code in `src/momapy/geometry.py`

    206
    207
    208
    def get_angle_to_horizontal(self) -> float:
        """Compute and return the angle formed by the segment and the horizontal"""
        return get_angle_to_horizontal_of_line(self)

#### `` get_distance_to_point

    get_distance_to_point(point: Point) -> float

Return the distance of a given point to the segment

Source code in `src/momapy/geometry.py`

    198
    199
    200
    def get_distance_to_point(self, point: Point) -> float:
        """Return the distance of a given point to the segment"""
        return get_distance_between_segment_and_point(self, point)

#### `` get_intersection_with_line

    get_intersection_with_line(
        line: Line,
    ) -> list[Point] | list[Segment]

Compute and return the intersection of the segment with a given line

Source code in `src/momapy/geometry.py`

    210
    211
    212
    def get_intersection_with_line(self, line: Line) -> list[Point] | list["Segment"]:
        """Compute and return the intersection of the segment with a given line"""
        return get_intersection_of_line_and_segment(line, self)

#### `` get_position_and_angle_at_fraction

    get_position_and_angle_at_fraction(
        fraction: float,
    ) -> tuple[Point, float]

Compute and return the position on the segment at a given fraction and the angle in radians formed of the segment and the horizontal at that position

Source code in `src/momapy/geometry.py`

    222
    223
    224
    225
    226
    def get_position_and_angle_at_fraction(
        self, fraction: float
    ) -> tuple[Point, float]:
        """Compute and return the position on the segment at a given fraction and the angle in radians formed of the segment and the horizontal at that position"""
        return get_position_and_angle_at_fraction_of_segment(self, fraction)

#### `` get_position_at_fraction

    get_position_at_fraction(fraction: float) -> Point

Compute and return the position on the segment at a given fraction (of the total length)

Source code in `src/momapy/geometry.py`

    214
    215
    216
    def get_position_at_fraction(self, fraction: float) -> Point:
        """Compute and return the position on the segment at a given fraction (of the total length)"""
        return get_position_at_fraction_of_segment(self, fraction)

#### `` has_point

    has_point(point: Point, max_distance: float = 0.01) -> bool

Return `true` if the given point is on the segment, `false` otherwise

Source code in `src/momapy/geometry.py`

    202
    203
    204
    def has_point(self, point: Point, max_distance: float = 0.01) -> bool:
        """Return `true` if the given point is on the segment, `false` otherwise"""
        return segment_has_point(self, point, max_distance)

#### `` length

    length() -> float

Return the length of the segment

Source code in `src/momapy/geometry.py`

    194
    195
    196
    def length(self) -> float:
        """Return the length of the segment"""
        return math.sqrt((self.p2.x - self.p1.x) ** 2 + (self.p2.y - self.p1.y) ** 2)

#### `` reversed

    reversed() -> Segment

Compute and return a reversed copy of the segment

Source code in `src/momapy/geometry.py`

    240
    241
    242
    def reversed(self) -> "Segment":
        """Compute and return a reversed copy of the segment"""
        return reverse_segment(self)

#### `` shortened

    shortened(
        length: float,
        start_or_end: Literal["start", "end"] = "end",
    ) -> Segment

Compute and return a copy of the segment shortened by a given length

Source code in `src/momapy/geometry.py`

    228
    229
    230
    231
    232
    233
    234
    def shortened(
        self,
        length: float,
        start_or_end: typing.Literal["start", "end"] = "end",
    ) -> "Segment":
        """Compute and return a copy of the segment shortened by a given length"""
        return shorten_segment(self, length, start_or_end)

#### `` to_shapely

    to_shapely() -> LineString

Return a shapely line string reproducing the segment

Source code in `src/momapy/geometry.py`

    244
    245
    246
    247
    248
    249
    250
    251
    def to_shapely(self) -> shapely.LineString:
        """Return a shapely line string reproducing the segment"""
        return shapely.LineString(
            [
                self.p1.to_tuple(),
                self.p2.to_tuple(),
            ]
        )

#### `` transformed

    transformed(transformation: Transformation) -> Segment

Compute and return a copy of the segment transformed with a given transformation

Source code in `src/momapy/geometry.py`

    236
    237
    238
    def transformed(self, transformation: "Transformation") -> "Segment":
        """Compute and return a copy of the segment transformed with a given transformation"""
        return transform_segment(self, transformation)

### `` Transformation `dataclass`

    Transformation()

Bases: `ABC`

Base class for transformations

Methods:

Name | Description
--- | ---
`inverted` | Compute and return the inverse transformation
`to_matrix` | Return a matrix representation of the transformation

#### `` inverted `abstractmethod`

    inverted() -> Transformation

Compute and return the inverse transformation

Source code in `src/momapy/geometry.py`

    591
    592
    593
    594
    @abc.abstractmethod
    def inverted(self) -> "Transformation":
        """Compute and return the inverse transformation"""
        pass

#### `` to_matrix `abstractmethod`

    to_matrix() -> NDArray

Return a matrix representation of the transformation

Source code in `src/momapy/geometry.py`

    586
    587
    588
    589
    @abc.abstractmethod
    def to_matrix(self) -> numpy.typing.NDArray:
        """Return a matrix representation of the transformation"""
        pass

### `` Translation `dataclass`

    Translation(tx: float, ty: float)

Bases: `Transformation`

Class for translations

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`tx` | `float` |  | required
`ty` | `float` |  | required

Methods:

Name | Description
--- | ---
`inverted` | Compute and return the inverse of the translation
`to_matrix` | Return a matrix representation of the translation

#### `` inverted

    inverted() -> Transformation

Compute and return the inverse of the translation

Source code in `src/momapy/geometry.py`

    657
    658
    659
    def inverted(self) -> Transformation:
        """Compute and return the inverse of the translation"""
        return invert_translation(self)

#### `` to_matrix

    to_matrix() -> NDArray

Return a matrix representation of the translation

Source code in `src/momapy/geometry.py`

    652
    653
    654
    655
    def to_matrix(self) -> numpy.typing.NDArray:
        """Return a matrix representation of the translation"""
        m = numpy.array([[1, 0, self.tx], [0, 1, self.ty], [0, 0, 1]], dtype=float)
        return m