Rectangle

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

Rectangular geometric object.

Parameters:
  • corner1 – Pair of coordinates (or complex number) for the first corner of the rectangle.

  • corner2 – Pair of coordinates (or complex number) for the second corner of the rectangle.

  • center – Pair of coordinates (or complex number) for the center of the rectangle.

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

  • size – Pair of dimensions (or complex number) for the size of the rectangle.

Example

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

Methods

area()

Structure area.

bounds()

Calculate the structure bounds

copy()

Create a copy of this structure.

mirror([axis_endpoint, axis_origin])

Mirror this structure.

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.

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.

area()

Structure area.

Returns:

Area of the structure.

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)).

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.

copy()

Create a copy of this structure.

Returns:

New copy.

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

Mirror this structure.

Parameters:
  • axis_endpoint – Mirror axis endpoint.

  • axis_origin – Mirror axis origin.

Returns:

This object.

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

Rotate this structure.

Parameters:
  • rotation – Rotation angle in degrees.

  • center – Center of rotation.

Returns:

This object.

rotation

Rotation angle of rectangle (in degrees).

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

Scale this structure.

Parameters:
  • scaling – Magnification factor.

  • center – Center of scaling.

Returns:

This object.

size

Size of the rectangle.

to_polygon()

Create a Polygon from this structure.

Returns:

New polygon instance.

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 – Coordinate pair used as a translation vector.

  • rotation – Rotation angle in degrees.

  • scaling – Magnification factor.

  • x_reflection – Mirror across the horizontal axis.

Returns:

This object.

translate(translation)

Translate this structure.

Parameters:

translation – Coordinate pair used as a translation vector.

Returns:

This object.

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.