Skip to content

Polygon

Polygon object.

Source code in gdsr/_gdsr.pyi
class Polygon:
    """Polygon object."""

    @property
    def points(self) -> list[Point]:
        """Return the points of the polygon."""
    @points.setter
    def points(self, points: InputPointsLike) -> None:
        """Set the points of the polygon."""
    layer: Layer
    """The layer of the polygon."""
    data_type: DataType
    """The data type of the polygon."""
    def __init__(
        self, points: InputPointsLike, layer: Layer = 0, data_type: DataType = 0
    ) -> None:
        """Initialize the Polygon.

        If the first and last points are not the same,
        the first point is appended to the end, to ensure that the polygon is closed.

        :param InputPointsLike points: Polygon vertices. Sequence of objects that are
        indexable at 0 and 1. Must not be empty
        :param Layer layer: Polygon layer, defaults to 0
        :param DataType data_type: Polygon data_type, defaults to 0
        """
    @property
    def bounding_box(self) -> tuple[Point, Point]:
        """Return the bounding box of the polygon."""
    @property
    def area(self) -> float:
        """Return the area of the polygon."""
    @property
    def perimeter(self) -> float:
        """Return the perimeter of the polygon."""
    def set_points(self, points: InputPointsLike) -> Self:
        """Set the points of the polygon.

        If the first and last points are not the same,
        the first point is appended to the end, to ensure that the polygon is closed.

        :param InputPointsLike points: Polygon vertices. Sequence of objects that are
        indexable at 0 and 1. Must not be empty
        """
    def set_layer(self, layer: Layer) -> Self:
        """Set the layer of the polygon."""
    def set_data_type(self, data_type: DataType) -> Self:
        """Set the data type of the polygon."""

    def contains(self, point: PointLike) -> bool:
        """Return True if the polygon contains the point."""
    def contains_all(self, *points: PointLike) -> bool:
        """Return True if the polygon contains all of the points."""
    def contains_any(self, *points: PointLike) -> bool:
        """Return True if the polygon contains any of the points."""
    def on_edge(self, point: PointLike) -> bool:
        """Return True if the point is on the edge of the polygon."""
    def on_edge_all(self, *points: PointLike) -> bool:
        """Return True if all of the points are on the edge of the polygon."""
    def on_edge_any(self, *points: PointLike) -> bool:
        """Return True if any of the points are on the edge of the polygon."""
    def intersects(self, other: Polygon) -> bool:
        """Return True if the polygon intersects with another polygon."""
    def visualize(self) -> None:
        """Visualises the polygon in your default web browser."""
    def copy(self) -> Self:
        """Return a copy of the polygon."""
    def move_to(self, point: PointLike) -> Self:
        """Move the polygon to a point.

        This method modifies the polygon in place and returns itself.

        :param PointLike point: Point to move the polygon to.
        """
    def move_by(self, vector: PointLike) -> Self:
        """Move the polygon by a vector.

        This method modifies the polygon in place and returns itself.

        :param PointLike vector: Vector to move the polygon by.
        """
    def rotate(self, angle: float, centre: PointLike = Point(0, 0)) -> Self:
        """Rotate the polygon by an angle around a centre point.

        This method modifies the polygon in place and returns itself.

        :param float angle: Counter-clockwise rotation angle in degrees.
        :param PointLike centre: Centre point of rotation, defaults to (0, 0).
        """
    def scale(self, factor: float, centre: PointLike = Point(0, 0)) -> Self:
        """Scale the polygon by a factor around a centre point.

        This method modifies the polygon in place and returns itself.

        :param float factor: Scaling factor.
        :param PointLike centre: Centre point of scaling, defaults to (0, 0).
        """
    def is_on(self, *layer_data_types: LayerDataType) -> bool:
        """Return True if the polygon is on any of the layer, data_type pairs."""
    @staticmethod
    def regular(
        centre: PointLike,
        radius: float,
        n_sides: int,
        rotation: float = 0,
        layer: int = 0,
        data_type: int = 0,
    ) -> Polygon:
        """Return a regular polygon.

        :param PointLike centre: Centre of the polygon.
        :param float radius: Radius of the polygon.
        :param int n_sides: Number of sides of the polygon.
        :param float rotation: Rotation of the polygon in degrees.
        :param int layer: Layer of the polygon, defaults to 0.
        :param int data_type: Data type of the polygon, defaults to 0.
        """
    @staticmethod
    def ellipse(
        centre: PointLike,
        horizontal_radius: float,
        vertical_radius: float | None = None,
        initial_angle: float = 0.0,
        final_angle: float = 360.0,
        n_sides: int = 400,
        layer: int = 0,
        data_type: int = 0,
    ) -> Polygon:
        """Return an ellipse.

        :param PointLike centre: Centre of the ellipse.
        :param float radius: Radius of the ellipse.
        :param float initial_angle: Initial angle  in degrees, defaults to 0.
        :param float final_angle: Final angle in degrees, defaults to 0.
        :param int n_sides: Number of sides of the ellipse, defaults to 400.
        :param int layer: Layer of the ellipse, defaults to 0.
        :param int data_type: Data type of the ellipse, defaults to 0.
        """
    def __str__(self) -> str:
        """Return a string representation of the polygon."""
    def __repr__(self) -> str:
        """Return a string representation of the polygon."""
    def __eq__(self, value: object) -> bool:
        """Return True if the polygon is equal to another object."""

points property writable

points: list[Point]

Return the points of the polygon.

layer instance-attribute

layer: Layer

The layer of the polygon.

data_type instance-attribute

data_type: DataType

The data type of the polygon.

bounding_box property

bounding_box: tuple[Point, Point]

Return the bounding box of the polygon.

area property

area: float

Return the area of the polygon.

perimeter property

perimeter: float

Return the perimeter of the polygon.

__init__

__init__(points: InputPointsLike, layer: Layer = 0, data_type: DataType = 0) -> None

Initialize the Polygon.

If the first and last points are not the same, the first point is appended to the end, to ensure that the polygon is closed.

Parameters:

  • points (InputPointsLike) –

    Polygon vertices. Sequence of objects that are indexable at 0 and 1. Must not be empty

  • layer (Layer, default: 0 ) –

    Polygon layer, defaults to 0

  • data_type (DataType, default: 0 ) –

    Polygon data_type, defaults to 0

Source code in gdsr/_gdsr.pyi
def __init__(
    self, points: InputPointsLike, layer: Layer = 0, data_type: DataType = 0
) -> None:
    """Initialize the Polygon.

    If the first and last points are not the same,
    the first point is appended to the end, to ensure that the polygon is closed.

    :param InputPointsLike points: Polygon vertices. Sequence of objects that are
    indexable at 0 and 1. Must not be empty
    :param Layer layer: Polygon layer, defaults to 0
    :param DataType data_type: Polygon data_type, defaults to 0
    """

set_points

set_points(points: InputPointsLike) -> Self

Set the points of the polygon.

If the first and last points are not the same, the first point is appended to the end, to ensure that the polygon is closed.

Parameters:

  • points (InputPointsLike) –

    Polygon vertices. Sequence of objects that are indexable at 0 and 1. Must not be empty

Source code in gdsr/_gdsr.pyi
def set_points(self, points: InputPointsLike) -> Self:
    """Set the points of the polygon.

    If the first and last points are not the same,
    the first point is appended to the end, to ensure that the polygon is closed.

    :param InputPointsLike points: Polygon vertices. Sequence of objects that are
    indexable at 0 and 1. Must not be empty
    """

set_layer

set_layer(layer: Layer) -> Self

Set the layer of the polygon.

Source code in gdsr/_gdsr.pyi
def set_layer(self, layer: Layer) -> Self:
    """Set the layer of the polygon."""

set_data_type

set_data_type(data_type: DataType) -> Self

Set the data type of the polygon.

Source code in gdsr/_gdsr.pyi
def set_data_type(self, data_type: DataType) -> Self:
    """Set the data type of the polygon."""

contains

contains(point: PointLike) -> bool

Return True if the polygon contains the point.

Source code in gdsr/_gdsr.pyi
def contains(self, point: PointLike) -> bool:
    """Return True if the polygon contains the point."""

contains_all

contains_all(*points: PointLike) -> bool

Return True if the polygon contains all of the points.

Source code in gdsr/_gdsr.pyi
def contains_all(self, *points: PointLike) -> bool:
    """Return True if the polygon contains all of the points."""

contains_any

contains_any(*points: PointLike) -> bool

Return True if the polygon contains any of the points.

Source code in gdsr/_gdsr.pyi
def contains_any(self, *points: PointLike) -> bool:
    """Return True if the polygon contains any of the points."""

on_edge

on_edge(point: PointLike) -> bool

Return True if the point is on the edge of the polygon.

Source code in gdsr/_gdsr.pyi
def on_edge(self, point: PointLike) -> bool:
    """Return True if the point is on the edge of the polygon."""

on_edge_all

on_edge_all(*points: PointLike) -> bool

Return True if all of the points are on the edge of the polygon.

Source code in gdsr/_gdsr.pyi
def on_edge_all(self, *points: PointLike) -> bool:
    """Return True if all of the points are on the edge of the polygon."""

on_edge_any

on_edge_any(*points: PointLike) -> bool

Return True if any of the points are on the edge of the polygon.

Source code in gdsr/_gdsr.pyi
def on_edge_any(self, *points: PointLike) -> bool:
    """Return True if any of the points are on the edge of the polygon."""

intersects

intersects(other: Polygon) -> bool

Return True if the polygon intersects with another polygon.

Source code in gdsr/_gdsr.pyi
def intersects(self, other: Polygon) -> bool:
    """Return True if the polygon intersects with another polygon."""

visualize

visualize() -> None

Visualises the polygon in your default web browser.

Source code in gdsr/_gdsr.pyi
def visualize(self) -> None:
    """Visualises the polygon in your default web browser."""

copy

copy() -> Self

Return a copy of the polygon.

Source code in gdsr/_gdsr.pyi
def copy(self) -> Self:
    """Return a copy of the polygon."""

move_to

move_to(point: PointLike) -> Self

Move the polygon to a point.

This method modifies the polygon in place and returns itself.

Parameters:

  • point (PointLike) –

    Point to move the polygon to.

Source code in gdsr/_gdsr.pyi
def move_to(self, point: PointLike) -> Self:
    """Move the polygon to a point.

    This method modifies the polygon in place and returns itself.

    :param PointLike point: Point to move the polygon to.
    """

move_by

move_by(vector: PointLike) -> Self

Move the polygon by a vector.

This method modifies the polygon in place and returns itself.

Parameters:

  • vector (PointLike) –

    Vector to move the polygon by.

Source code in gdsr/_gdsr.pyi
def move_by(self, vector: PointLike) -> Self:
    """Move the polygon by a vector.

    This method modifies the polygon in place and returns itself.

    :param PointLike vector: Vector to move the polygon by.
    """

rotate

rotate(angle: float, centre: PointLike = Point(0, 0)) -> Self

Rotate the polygon by an angle around a centre point.

This method modifies the polygon in place and returns itself.

Parameters:

  • angle (float) –

    Counter-clockwise rotation angle in degrees.

  • centre (PointLike, default: Point(0, 0) ) –

    Centre point of rotation, defaults to (0, 0).

Source code in gdsr/_gdsr.pyi
def rotate(self, angle: float, centre: PointLike = Point(0, 0)) -> Self:
    """Rotate the polygon by an angle around a centre point.

    This method modifies the polygon in place and returns itself.

    :param float angle: Counter-clockwise rotation angle in degrees.
    :param PointLike centre: Centre point of rotation, defaults to (0, 0).
    """

scale

scale(factor: float, centre: PointLike = Point(0, 0)) -> Self

Scale the polygon by a factor around a centre point.

This method modifies the polygon in place and returns itself.

Parameters:

  • factor (float) –

    Scaling factor.

  • centre (PointLike, default: Point(0, 0) ) –

    Centre point of scaling, defaults to (0, 0).

Source code in gdsr/_gdsr.pyi
def scale(self, factor: float, centre: PointLike = Point(0, 0)) -> Self:
    """Scale the polygon by a factor around a centre point.

    This method modifies the polygon in place and returns itself.

    :param float factor: Scaling factor.
    :param PointLike centre: Centre point of scaling, defaults to (0, 0).
    """

is_on

is_on(*layer_data_types: LayerDataType) -> bool

Return True if the polygon is on any of the layer, data_type pairs.

Source code in gdsr/_gdsr.pyi
def is_on(self, *layer_data_types: LayerDataType) -> bool:
    """Return True if the polygon is on any of the layer, data_type pairs."""

regular staticmethod

regular(centre: PointLike, radius: float, n_sides: int, rotation: float = 0, layer: int = 0, data_type: int = 0) -> Polygon

Return a regular polygon.

Parameters:

  • centre (PointLike) –

    Centre of the polygon.

  • radius (float) –

    Radius of the polygon.

  • n_sides (int) –

    Number of sides of the polygon.

  • rotation (float, default: 0 ) –

    Rotation of the polygon in degrees.

  • layer (int, default: 0 ) –

    Layer of the polygon, defaults to 0.

  • data_type (int, default: 0 ) –

    Data type of the polygon, defaults to 0.

Source code in gdsr/_gdsr.pyi
@staticmethod
def regular(
    centre: PointLike,
    radius: float,
    n_sides: int,
    rotation: float = 0,
    layer: int = 0,
    data_type: int = 0,
) -> Polygon:
    """Return a regular polygon.

    :param PointLike centre: Centre of the polygon.
    :param float radius: Radius of the polygon.
    :param int n_sides: Number of sides of the polygon.
    :param float rotation: Rotation of the polygon in degrees.
    :param int layer: Layer of the polygon, defaults to 0.
    :param int data_type: Data type of the polygon, defaults to 0.
    """

ellipse staticmethod

ellipse(centre: PointLike, horizontal_radius: float, vertical_radius: float | None = None, initial_angle: float = 0.0, final_angle: float = 360.0, n_sides: int = 400, layer: int = 0, data_type: int = 0) -> Polygon

Return an ellipse.

Parameters:

  • centre (PointLike) –

    Centre of the ellipse.

  • radius (float) –

    Radius of the ellipse.

  • initial_angle (float, default: 0.0 ) –

    Initial angle in degrees, defaults to 0.

  • final_angle (float, default: 360.0 ) –

    Final angle in degrees, defaults to 0.

  • n_sides (int, default: 400 ) –

    Number of sides of the ellipse, defaults to 400.

  • layer (int, default: 0 ) –

    Layer of the ellipse, defaults to 0.

  • data_type (int, default: 0 ) –

    Data type of the ellipse, defaults to 0.

Source code in gdsr/_gdsr.pyi
@staticmethod
def ellipse(
    centre: PointLike,
    horizontal_radius: float,
    vertical_radius: float | None = None,
    initial_angle: float = 0.0,
    final_angle: float = 360.0,
    n_sides: int = 400,
    layer: int = 0,
    data_type: int = 0,
) -> Polygon:
    """Return an ellipse.

    :param PointLike centre: Centre of the ellipse.
    :param float radius: Radius of the ellipse.
    :param float initial_angle: Initial angle  in degrees, defaults to 0.
    :param float final_angle: Final angle in degrees, defaults to 0.
    :param int n_sides: Number of sides of the ellipse, defaults to 400.
    :param int layer: Layer of the ellipse, defaults to 0.
    :param int data_type: Data type of the ellipse, defaults to 0.
    """

__str__

__str__() -> str

Return a string representation of the polygon.

Source code in gdsr/_gdsr.pyi
def __str__(self) -> str:
    """Return a string representation of the polygon."""

__repr__

__repr__() -> str

Return a string representation of the polygon.

Source code in gdsr/_gdsr.pyi
def __repr__(self) -> str:
    """Return a string representation of the polygon."""

__eq__

__eq__(value: object) -> bool

Return True if the polygon is equal to another object.

Source code in gdsr/_gdsr.pyi
def __eq__(self, value: object) -> bool:
    """Return True if the polygon is equal to another object."""