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 = Rectangle((0, 0), (2, 1)) # corners >>> rect2 = Rectangle(center=(1, 0.5), size=(2, 1)) # center/size
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.
Structure perimeter.
rotate
(rotation[, center])Rotate this structure.
scale
(scaling[, center])Scale this structure.
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 of the rectangle.
(DEPRECATED) Json representation of this layer specification.
Object properties.
Rotation angle of rectangle (in degrees).
Size of the rectangle.
Upper bound in the x axis.
Bounding box center in the x axis.
Lower bound in the x axis.
Upper bound in the y axis.
Bounding box center in the y axis.
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))
- center¶
Center of the rectangle.
- Type:
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:
- perimeter()¶
Structure perimeter.
- Returns:
Perimeter of the structure.
- Return type:
float
- properties¶
Object properties.
- Type:
- 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:
- 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:
- size¶
Size of the rectangle.
- Type:
ndarray
- to_polygon()¶
Create a Polygon from this structure.
- Returns:
New polygon instance.
- Return type:
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] | 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:
- translate(translation)¶
Translate this structure.
- Parameters:
translation (Sequence[float] | complex) – Translation vector.
- Returns:
This object.
- Return type:
- 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