Polygon

class photonforge.Polygon(vertices, holes=None)

Polygonal geometric object.

Parameters:
  • vertices (Sequence[Sequence[float] | complex]) – Vertices of the exterior boundary of the polygon.

  • holes – (Sequence[Sequence[Sequence[float] | complex]]): Sequence of boundaries representing holes in the polygon.

Examples

>>> polygon1 = Polygon([(0, 0), (1, 0), (1, 1.5), (0, 1)])
>>> boundary = [(-1, -2), (3, -2), (3, 2), (-1, 2)]
>>> hole1 = [(0, 0), (0, 1), (1, 1)]
>>> hole2 = [(0, -1), (2, -1), (2, 1)]
>>> polygon2 = Polygon(boundary, [hole1, hole2])

Methods

add_gds_property(value)

Add a custom property to this object compatible with GDSII files.

area()

Structure area.

bounds()

Calculate the structure bounds

copy()

Create a copy of this structure.

mirror([axis_endpoint, axis_origin])

Mirror this structure.

perimeter()

Structure perimeter.

remove_collinear()

Remove internal vertices from straight segments in the polygon contours.

rotate(rotation[, center])

Rotate this structure.

scale(scaling[, center])

Scale this structure.

to_polygon()

Create a Polygon from this structure.

transform([translation, rotation, scaling, ...])

Apply a transformation to this structure: self = translate(rotate(mirror(scale(self))))

translate(translation)

Translate this structure.

Attributes

holes

List of polygon holes (read-only).

json

(DEPRECATED) Json representation of this layer specification.

properties

Object properties.

vertices

Vertices of the exterior boundary of the polygon (read-only).

x_max

Upper bound in the x axis.

x_mid

Bounding box center in the x axis.

x_min

Lower bound in the x axis.

y_max

Upper bound in the y axis.

y_mid

Bounding box center in the y axis.

y_min

Lower bound in the y axis.

add_gds_property(value)

Add a custom property to this object compatible with GDSII files.

Parameters:
  • attribute (int) – Property number.

  • value (str) – Property value.

area()

Structure area.

Returns:

Area of the structure.

Return type:

float

bounds()

Calculate the structure bounds

Returns:

The lower-left and upper-right corners of the bounding box of the structure: ((min_x, min_y), (max_x, max_y)).

Return type:

tuple[ndarray, ndarray]

Example

>>> polygon = Polygon([(0, 1), (1, 2), (3, -1)])
>>> bounds = polygon.bounds()
>>> print(bounds)
((0.0, -1.0), (3.0, 2.0))
copy()

Create a copy of this structure.

Returns:

New copy.

Return type:

Polygon

holes

List of polygon holes (read-only).

Type:

list[ndarray]

json

(DEPRECATED) Json representation of this layer specification.

Type:

str

mirror(axis_endpoint=(1, 0), axis_origin=(0, 0))

Mirror this structure.

Parameters:
  • axis_endpoint (Sequence[float] | complex) – Mirror axis endpoint.

  • axis_origin (Sequence[float] | complex) – Mirror axis origin.

Returns:

This object.

Return type:

Polygon

perimeter()

Structure perimeter.

Returns:

Perimeter of the structure.

Return type:

float

properties

Object properties.

Type:

Properties

remove_collinear()

Remove internal vertices from straight segments in the polygon contours.

Returns:

This polygon.

Return type:

Polygon

rotate(rotation, center=(0, 0))

Rotate this structure.

Parameters:
  • rotation (float) – Rotation angle (in degrees).

  • center (Sequence[float, float] | complex) – Center of rotation.

Returns:

This object.

Return type:

Polygon

scale(scaling, center=(0, 0))

Scale this structure.

Parameters:
  • scaling (float) – Magnification factor.

  • center (Sequence[float, float] | complex) – Center of scaling.

Returns:

This object.

Return type:

Polygon

to_polygon()

Create a Polygon from this structure.

Returns:

New polygon instance.

Return type:

Polygon

Examples

>>> rectangle = Rectangle((0, 0), (2, 1), rotation=45)
>>> polygon = rectangle.to_polygon()
>>> circle = Circle(5, (0, 0), inner_radius=3)
>>> polygon = circle.to_polygon()
>>> path = Path((0, 0), 0.5).s_bend((10, 2))
>>> polygon = path.to_polygon()
transform(translation=(0, 0), rotation=0, scaling=1, x_reflection=False)

Apply a transformation to this structure: self = translate(rotate(mirror(scale(self))))

Parameters:
  • translation (Sequence[float, float] | complex) – Translation vector.

  • rotation (float) – Rotation angle (in degrees).

  • scaling (float) – Magnification factor.

  • x_reflection (bool) – Mirror across the horizontal axis.

Returns:

This object.

Return type:

Polygon

translate(translation)

Translate this structure.

Parameters:

translation (Sequence[float, float] | complex) – Translation vector.

Returns:

This object.

Return type:

Polygon

vertices

Vertices of the exterior boundary of the polygon (read-only).

Type:

ndarray

x_max

Upper bound in the x axis.

Type:

float

x_mid

Bounding box center in the x axis.

Type:

float

x_min

Lower bound in the x axis.

Type:

float

y_max

Upper bound in the y axis.

Type:

float

y_mid

Bounding box center in the y axis.

Type:

float

y_min

Lower bound in the y axis.

Type:

float