Rectangle

class photonforge.Rectangle(corner1=None, corner2=None, center=None, size=None, rotation=0)

Rectangular geometric object.

Parameters:
  • corner1 (Sequence[float] | complex) – First rectangle corner.

  • corner2 (Sequence[float] | complex) – Second rectangle corner.

  • center (Sequence[float] | complex) – Rectangle center.

  • size (Sequence[float] | complex) – Rectangle size.

  • rotation (float) – Rotation angle around the center (in degrees).

Example

>>> rect1 = pf.Rectangle((0, 0), (2, 1))  # corners
>>> rect2 = pf.Rectangle(center=(1, 0.5), size=(2, 1))

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.

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

center

Center of the rectangle.

properties

Object properties.

rotation

Rotation angle of rectangle (in degrees).

size

Size of the rectangle.

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 = pf.Polygon([(0, 1), (1, 2), (3, -1)])
>>> bounds = polygon.bounds()
>>> print(bounds)
(array([ 0., -1.]), array([3., 2.]))
center

Center of the rectangle.

Type:

ndarray

copy()

Create a copy of this structure.

Returns:

New copy.

Return type:

Rectangle

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:

Rectangle

perimeter()

Structure perimeter.

Returns:

Perimeter of the structure.

Return type:

float

properties

Object properties.

Type:

Properties

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

Rotate this structure.

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

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

Returns:

This object.

Return type:

Rectangle

rotation

Rotation angle of rectangle (in degrees).

Type:

float

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

Scale this structure.

Parameters:
  • scaling (float) – Magnification factor.

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

Returns:

This object.

Return type:

Rectangle

size

Size of the rectangle.

Type:

ndarray

to_polygon()

Create a Polygon from this structure.

Returns:

New polygon instance.

Return type:

Polygon

Examples

>>> rectangle = pf.Rectangle((0, 0), (2, 1), rotation=45)
>>> polygon = rectangle.to_polygon()
>>> circle = pf.Circle(5, (0, 0), inner_radius=3)
>>> polygon = circle.to_polygon()
>>> path = pf.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] | 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:

Rectangle

translate(translation)

Translate this structure.

Parameters:

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

Returns:

This object.

Return type:

Rectangle

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