ZLayout EDA Library v1.0.0
Advanced Electronic Design Automation Layout Library with Bilingual Documentation
Loading...
Searching...
No Matches
zlayout::geometry::Rectangle Class Reference

Axis-aligned rectangle for bounding boxes and simple EDA components. More...

#include <rectangle.hpp>

Public Member Functions

 Rectangle ()
 Default constructor - creates empty rectangle at origin.
 Rectangle (double x, double y, double width, double height)
 Constructor with position and dimensions.
 Rectangle (const Point &bottom_left, const Point &top_right)
 Constructor from two corner points.
 Rectangle (const Rectangle &other)=default
 Copy constructor.
Rectangleoperator= (const Rectangle &other)=default
 Assignment operator.
bool operator== (const Rectangle &other) const
 Equality operator.
bool operator!= (const Rectangle &other) const
 Inequality operator.
bool operator< (const Rectangle &other) const
 Less than operator for sorting.
double left () const
 Get left edge X coordinate.
double right () const
 Get right edge X coordinate.
double bottom () const
 Get bottom edge Y coordinate.
double top () const
 Get top edge Y coordinate.
Point center () const
 Get center point of rectangle.
Point bottom_left () const
 Get bottom-left corner point.
Point bottom_right () const
 Get bottom-right corner point.
Point top_left () const
 Get top-left corner point.
Point top_right () const
 Get top-right corner point.
std::vector< Pointcorners () const
 Get all four corner points.
double area () const
 Calculate rectangle area.
double perimeter () const
 Calculate rectangle perimeter.
bool is_empty () const
 Check if rectangle is empty (zero area)
bool is_valid () const
 Check if rectangle is valid (positive dimensions)
bool contains_point (const Point &point) const
 Check if point is inside rectangle (inclusive of boundary)
bool contains_rectangle (const Rectangle &other) const
 Check if another rectangle is completely inside this rectangle.
bool intersects (const Rectangle &other) const
 Check if this rectangle intersects with another rectangle.
Rectangle intersection (const Rectangle &other) const
 Calculate intersection rectangle with another rectangle.
Rectangle union_with (const Rectangle &other) const
 Calculate union rectangle that contains both rectangles.
Rectangle expand (double margin) const
 Expand rectangle by given margin in all directions.
Rectangle expand (double left, double right, double bottom, double top) const
 Expand rectangle by different margins in each direction.
Rectangle translate (const Point &offset) const
 Translate rectangle by given offset.
Rectangle scale (double factor) const
 Scale rectangle by given factor (around center)
Rectangle scale (double x_factor, double y_factor) const
 Scale rectangle by different factors in X and Y.
double distance_to (const Rectangle &other) const
 Calculate minimum distance to another rectangle.
double distance_to (const Point &point) const
 Calculate minimum distance to a point.
Polygon to_polygon () const
 Convert rectangle to polygon representation.
std::string to_string () const
 Get string representation.
 __init__ (self, float x, float y, float width, float height)
str __repr__ (self)
float left (self)
float right (self)
float top (self)
float bottom (self)
Point center (self)
bool contains_point (self, Point point)
bool intersects (self, 'Rectangle' other)
'Polygonto_polygon (self)

Static Public Member Functions

static Rectangle from_center (const Point &center, double width, double height)
 Create rectangle from center point and dimensions.
static Rectangle bounding_box (const std::vector< Point > &points)
 Create bounding rectangle for a set of points.
static Rectangle bounding_box (const std::vector< Rectangle > &rectangles)
 Create rectangle that bounds multiple rectangles.

Public Attributes

double x
 X coordinate of bottom-left corner.
double y
 Y coordinate of bottom-left corner.
double width
 Width of rectangle.
double height
 Height of rectangle.
 x = float(x)
 y = float(y)
 width = float(width)
 height = float(height)
 bottom

Friends

std::ostream & operator<< (std::ostream &os, const Rectangle &rect)
 Stream output operator.

Detailed Description

Axis-aligned rectangle for bounding boxes and simple EDA components.

Axis-aligned rectangle for bounding boxes and simple components.

Represents an axis-aligned rectangle in 2D space. Commonly used for component bounding boxes, chip outlines, and simple rectangular components in EDA layouts.

Definition at line 26 of file rectangle.hpp.

Constructor & Destructor Documentation

◆ Rectangle() [1/4]

zlayout::geometry::Rectangle::Rectangle ( )
inline

Default constructor - creates empty rectangle at origin.

Definition at line 36 of file rectangle.hpp.

Here is the caller graph for this function:

◆ Rectangle() [2/4]

zlayout::geometry::Rectangle::Rectangle ( double x,
double y,
double width,
double height )

Constructor with position and dimensions.

Parameters
xX coordinate of bottom-left corner
yY coordinate of bottom-left corner
widthRectangle width
heightRectangle height

Definition at line 16 of file rectangle.cpp.

◆ Rectangle() [3/4]

zlayout::geometry::Rectangle::Rectangle ( const Point & bottom_left,
const Point & top_right )

Constructor from two corner points.

Parameters
bottom_leftBottom-left corner
top_rightTop-right corner

Definition at line 23 of file rectangle.cpp.

Here is the call graph for this function:

◆ Rectangle() [4/4]

zlayout::geometry::Rectangle::Rectangle ( const Rectangle & other)
default

Copy constructor.

Here is the call graph for this function:

◆ __init__()

zlayout.geometry.Rectangle.__init__ ( self,
float x,
float y,
float width,
float height )

Definition at line 72 of file geometry.py.

Member Function Documentation

◆ __repr__()

str zlayout.geometry.Rectangle.__repr__ ( self)

Definition at line 78 of file geometry.py.

◆ area()

double zlayout::geometry::Rectangle::area ( ) const
inline

Calculate rectangle area.

Definition at line 134 of file rectangle.hpp.

Here is the caller graph for this function:

◆ bottom() [1/2]

float zlayout.geometry.Rectangle.bottom ( self)

Definition at line 94 of file geometry.py.

◆ bottom() [2/2]

double zlayout::geometry::Rectangle::bottom ( ) const
inline

Get bottom edge Y coordinate.

Definition at line 93 of file rectangle.hpp.

◆ bottom_left()

Point zlayout::geometry::Rectangle::bottom_left ( ) const
inline

Get bottom-left corner point.

Definition at line 108 of file rectangle.hpp.

Here is the caller graph for this function:

◆ bottom_right()

Point zlayout::geometry::Rectangle::bottom_right ( ) const
inline

Get bottom-right corner point.

Definition at line 113 of file rectangle.hpp.

◆ bounding_box() [1/2]

Rectangle zlayout::geometry::Rectangle::bounding_box ( const std::vector< Point > & points)
static

Create bounding rectangle for a set of points.

Parameters
pointsVector of points
Returns
Bounding rectangle

Definition at line 221 of file rectangle.cpp.

Here is the call graph for this function:

◆ bounding_box() [2/2]

Rectangle zlayout::geometry::Rectangle::bounding_box ( const std::vector< Rectangle > & rectangles)
static

Create rectangle that bounds multiple rectangles.

Parameters
rectanglesVector of rectangles
Returns
Bounding rectangle

Definition at line 239 of file rectangle.cpp.

Here is the call graph for this function:

◆ center() [1/2]

Point zlayout.geometry.Rectangle.center ( self)

Definition at line 98 of file geometry.py.

◆ center() [2/2]

Point zlayout::geometry::Rectangle::center ( ) const

Get center point of rectangle.

Definition at line 68 of file rectangle.cpp.

Here is the caller graph for this function:

◆ contains_point() [1/2]

bool zlayout.geometry.Rectangle.contains_point ( self,
Point point )
Check if point is inside rectangle.

Definition at line 101 of file geometry.py.

Here is the call graph for this function:

◆ contains_point() [2/2]

bool zlayout::geometry::Rectangle::contains_point ( const Point & point) const

Check if point is inside rectangle (inclusive of boundary)

Parameters
pointPoint to test
Returns
true if point is inside or on rectangle boundary

Definition at line 89 of file rectangle.cpp.

Here is the caller graph for this function:

◆ contains_rectangle()

bool zlayout::geometry::Rectangle::contains_rectangle ( const Rectangle & other) const

Check if another rectangle is completely inside this rectangle.

Parameters
otherRectangle to test
Returns
true if other rectangle is completely inside

Definition at line 94 of file rectangle.cpp.

Here is the call graph for this function:

◆ corners()

std::vector< Point > zlayout::geometry::Rectangle::corners ( ) const

Get all four corner points.

Returns
Vector of corner points in order: bottom-left, bottom-right, top-right, top-left

Definition at line 72 of file rectangle.cpp.

Here is the caller graph for this function:

◆ distance_to() [1/2]

double zlayout::geometry::Rectangle::distance_to ( const Point & point) const

Calculate minimum distance to a point.

Parameters
pointTarget point
Returns
Minimum distance to point

Definition at line 187 of file rectangle.cpp.

Here is the call graph for this function:

◆ distance_to() [2/2]

double zlayout::geometry::Rectangle::distance_to ( const Rectangle & other) const

Calculate minimum distance to another rectangle.

Parameters
otherTarget rectangle
Returns
Minimum distance (0 if rectangles intersect)

Definition at line 164 of file rectangle.cpp.

Here is the call graph for this function:

◆ expand() [1/2]

Rectangle zlayout::geometry::Rectangle::expand ( double left,
double right,
double bottom,
double top ) const

Expand rectangle by different margins in each direction.

Parameters
leftLeft margin
rightRight margin
bottomBottom margin
topTop margin
Returns
Expanded rectangle

Definition at line 135 of file rectangle.cpp.

Here is the call graph for this function:

◆ expand() [2/2]

Rectangle zlayout::geometry::Rectangle::expand ( double margin) const

Expand rectangle by given margin in all directions.

Parameters
marginMargin to add (can be negative to shrink)
Returns
Expanded rectangle

Definition at line 130 of file rectangle.cpp.

Here is the call graph for this function:

◆ from_center()

Rectangle zlayout::geometry::Rectangle::from_center ( const Point & center,
double width,
double height )
static

Create rectangle from center point and dimensions.

Parameters
centerCenter point
widthRectangle width
heightRectangle height
Returns
Rectangle centered at given point

Definition at line 217 of file rectangle.cpp.

Here is the call graph for this function:

◆ intersection()

Rectangle zlayout::geometry::Rectangle::intersection ( const Rectangle & other) const

Calculate intersection rectangle with another rectangle.

Parameters
otherRectangle to intersect with
Returns
Intersection rectangle (may be empty)

Definition at line 105 of file rectangle.cpp.

Here is the call graph for this function:

◆ intersects() [1/2]

bool zlayout.geometry.Rectangle.intersects ( self,
'Rectangle' other )
Check if this rectangle intersects with another.

Definition at line 106 of file geometry.py.

Here is the call graph for this function:

◆ intersects() [2/2]

bool zlayout::geometry::Rectangle::intersects ( const Rectangle & other) const

Check if this rectangle intersects with another rectangle.

Parameters
otherRectangle to test intersection with
Returns
true if rectangles intersect

Definition at line 100 of file rectangle.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_empty()

bool zlayout::geometry::Rectangle::is_empty ( ) const

Check if rectangle is empty (zero area)

Definition at line 81 of file rectangle.cpp.

Here is the caller graph for this function:

◆ is_valid()

bool zlayout::geometry::Rectangle::is_valid ( ) const

Check if rectangle is valid (positive dimensions)

Definition at line 85 of file rectangle.cpp.

◆ left() [1/2]

float zlayout.geometry.Rectangle.left ( self)

Definition at line 82 of file geometry.py.

◆ left() [2/2]

double zlayout::geometry::Rectangle::left ( ) const
inline

Get left edge X coordinate.

Definition at line 83 of file rectangle.hpp.

Here is the caller graph for this function:

◆ operator!=()

bool zlayout::geometry::Rectangle::operator!= ( const Rectangle & other) const

Inequality operator.

Definition at line 37 of file rectangle.cpp.

Here is the call graph for this function:

◆ operator<()

bool zlayout::geometry::Rectangle::operator< ( const Rectangle & other) const

Less than operator for sorting.

Definition at line 41 of file rectangle.cpp.

Here is the call graph for this function:

◆ operator=()

Rectangle & zlayout::geometry::Rectangle::operator= ( const Rectangle & other)
default

Assignment operator.

Here is the call graph for this function:

◆ operator==()

bool zlayout::geometry::Rectangle::operator== ( const Rectangle & other) const

Equality operator.

Definition at line 30 of file rectangle.cpp.

Here is the call graph for this function:

◆ perimeter()

double zlayout::geometry::Rectangle::perimeter ( ) const
inline

Calculate rectangle perimeter.

Definition at line 139 of file rectangle.hpp.

◆ right() [1/2]

float zlayout.geometry.Rectangle.right ( self)

Definition at line 86 of file geometry.py.

◆ right() [2/2]

double zlayout::geometry::Rectangle::right ( ) const
inline

Get right edge X coordinate.

Definition at line 88 of file rectangle.hpp.

Here is the caller graph for this function:

◆ scale() [1/2]

Rectangle zlayout::geometry::Rectangle::scale ( double factor) const

Scale rectangle by given factor (around center)

Parameters
factorScale factor
Returns
Scaled rectangle

Definition at line 144 of file rectangle.cpp.

Here is the call graph for this function:

◆ scale() [2/2]

Rectangle zlayout::geometry::Rectangle::scale ( double x_factor,
double y_factor ) const

Scale rectangle by different factors in X and Y.

Parameters
x_factorX scale factor
y_factorY scale factor
Returns
Scaled rectangle

Definition at line 154 of file rectangle.cpp.

Here is the call graph for this function:

◆ to_polygon() [1/2]

'Polygon' zlayout.geometry.Rectangle.to_polygon ( self)
Convert rectangle to polygon.

Definition at line 111 of file geometry.py.

Here is the call graph for this function:

◆ to_polygon() [2/2]

Polygon zlayout::geometry::Rectangle::to_polygon ( ) const

Convert rectangle to polygon representation.

Returns
Polygon with rectangle vertices

Definition at line 198 of file rectangle.cpp.

Here is the call graph for this function:

◆ to_string()

std::string zlayout::geometry::Rectangle::to_string ( ) const

Get string representation.

Definition at line 203 of file rectangle.cpp.

Here is the caller graph for this function:

◆ top() [1/2]

float zlayout.geometry.Rectangle.top ( self)

Definition at line 90 of file geometry.py.

◆ top() [2/2]

double zlayout::geometry::Rectangle::top ( ) const
inline

Get top edge Y coordinate.

Definition at line 98 of file rectangle.hpp.

Here is the caller graph for this function:

◆ top_left()

Point zlayout::geometry::Rectangle::top_left ( ) const
inline

Get top-left corner point.

Definition at line 118 of file rectangle.hpp.

◆ top_right()

Point zlayout::geometry::Rectangle::top_right ( ) const
inline

Get top-right corner point.

Definition at line 123 of file rectangle.hpp.

Here is the caller graph for this function:

◆ translate()

Rectangle zlayout::geometry::Rectangle::translate ( const Point & offset) const

Translate rectangle by given offset.

Parameters
offsetTranslation vector
Returns
Translated rectangle

Definition at line 140 of file rectangle.cpp.

Here is the call graph for this function:

◆ union_with()

Rectangle zlayout::geometry::Rectangle::union_with ( const Rectangle & other) const

Calculate union rectangle that contains both rectangles.

Parameters
otherRectangle to union with
Returns
Union rectangle

Definition at line 118 of file rectangle.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Rectangle & rect )
friend

Stream output operator.

Definition at line 210 of file rectangle.cpp.

Member Data Documentation

◆ bottom

zlayout.geometry.Rectangle.bottom

Definition at line 109 of file geometry.py.

◆ height [1/2]

zlayout.geometry.Rectangle.height = float(height)

Definition at line 76 of file geometry.py.

◆ height [2/2]

double zlayout::geometry::Rectangle::height

Height of rectangle.

Definition at line 31 of file rectangle.hpp.

◆ width [1/2]

zlayout.geometry.Rectangle.width = float(width)

Definition at line 75 of file geometry.py.

◆ width [2/2]

double zlayout::geometry::Rectangle::width

Width of rectangle.

Definition at line 30 of file rectangle.hpp.

◆ x [1/2]

zlayout.geometry.Rectangle.x = float(x)

Definition at line 73 of file geometry.py.

◆ x [2/2]

double zlayout::geometry::Rectangle::x

X coordinate of bottom-left corner.

Definition at line 28 of file rectangle.hpp.

◆ y [1/2]

zlayout.geometry.Rectangle.y = float(y)

Definition at line 74 of file geometry.py.

◆ y [2/2]

double zlayout::geometry::Rectangle::y

Y coordinate of bottom-left corner.

Definition at line 29 of file rectangle.hpp.


The documentation for this class was generated from the following files: