1from __future__
import annotations
3from typing
import Union, Any
13 A rectangle defined by a point and a size.
15 Represents a rectangle composed of a position (top-left corner) and a size.
16 The position and size types are customizable via template parameters.
18 @ingroup ids_peak_common_python_types_geometry
21 def __init__(self, point: Point, size: Size) ->
None:
24 Creates a rectangle from a point and a size.
25 @param point: The top-left corner of the rectangle.
26 @param size: The dimensions of the rectangle.
29 if isinstance(point, Point)
and isinstance(size, Size):
30 validate_parameter_types(
31 point.x, point.y, size.width, size.height,
32 accepted_types=(int, float))
36 raise TypeError(
"Rectangle expected (Point, Size)")
43 width: Union[int, float],
44 height: Union[int, float]
48 Constructs a rectangle from x, y, width and height.
49 @param x: x coordinate of the upper left corner
50 @param y: y coordinate of the upper left corner
51 @param width: Width of the rectangle
52 @param height: Height of the rectangle
54 validate_parameter_types(x, y, width, height,
55 accepted_types=(int, float))
58 def __eq__(self, other: Any) -> bool:
61 Check if two rectangles are equal.
63 @param other: Another rectangle object OR
64 List of coordinates [x,y,width,height] OR
65 Tuple of coordinates (x,y,width,height)
67 @return True if rectangles are equal, False otherwise
69 if isinstance(other, Rectangle):
70 return self.
_point == other.position
and self.
_size == other.size
71 if isinstance(other, (list, tuple)):
74 return Point.__eq__(self.
_point, other[:2])
and Size.__eq__(self.
_size, other[2:])
78 def __ne__(self, other: Any) -> bool:
81 Check if two rectangles are not equal.
83 @param other: Another rectangle object
85 @return True if rectangles are not equal, False otherwise
87 return not self.
__eq__(other)
92 Get a string representation of the rectangle.
94 @return String representation of the rectangle
96 return (f
"(x={self.x}, y={self.y}, width={self.width}, "
97 f
"height={self.height})")
102 Return an unambiguous string of the Rectangle object.
104 return (f
"{self.__class__.__name__}(point={self._point!r}, "
105 f
"size={self._size!r})")
111 Returns the top-left corner of the rectangle.
116 def size(self) -> Size:
119 Returns the dimensions of the rectangle.
124 def x(self) -> Union[int, float]:
127 Returns the x-coordinate of the rectangle's top-left corner.
132 def y(self) -> Union[int, float]:
135 Returns the y-coordinate of the rectangle's top-left corner.
140 def width(self) -> Union[int, float]:
143 Returns the width of the rectangle.
145 return self.
_size.width
151 Returns the height of the rectangle.
153 return self.
_size.height
Represents a point in 2D space with x and y coordinates.
A rectangle defined by a point and a size.
None __init__(self, Point point, Size size)
Creates a rectangle from a point and a size.
Union[int, float] height(self)
Returns the height of the rectangle.
Point position(self)
Returns the top-left corner of the rectangle.
Union[int, float] x(self)
Returns the x-coordinate of the rectangle's top-left corner.
bool __ne__(self, Any other)
Check if two rectangles are not equal.
Union[int, float] y(self)
Returns the y-coordinate of the rectangle's top-left corner.
Union[int, float] width(self)
Returns the width of the rectangle.
Rectangle create_from_coordinates_and_dimensions(cls, Union[int, float] x, Union[int, float] y, Union[int, float] width, Union[int, float] height)
Constructs a rectangle from x, y, width and height.
str __str__(self)
Get a string representation of the rectangle.
str __repr__(self)
Return an unambiguous string of the Rectangle object.
bool __eq__(self, Any other)
Check if two rectangles are equal.
A size consists of width and height where width and height have to be greater than or equal to zero.