comet.CRect¶
- class comet.CRect¶
A convenience class representing an always axis-aligned 2D rectangle. Coordinate values shrink towards top, grow towards bottom, shrink towards left and grow towards the right. The internal data is stored as float values.
Methods¶
- CRect.getValues()¶
Convenience functions to return all four side coordinates at once
- Returns
All sides as (left, top, right, bottom)
- Return type
- Available
- CScript
- CRect.getLeft()¶
Returns the left component of the rectangle
- Returns
The left side
- Return type
- Available
- CScript
- CRect.getTop()¶
Returns the top component of the rectangle
- CRect.getRight()¶
Returns the right component of the rectangle
- Returns
The right side
- Return type
- Available
- CScript
- CRect.getBottom()¶
Returns the bottom component of the rectangle
- Returns
The bottom side
- Return type
- Available
- CScript
- CRect.getCenter()¶
Returns the center of the rectangle
- Returns
The center (x, y)
- Return type
- Available
- CScript
- CRect.getWidth()¶
Returns the width of the rectanggle
- Returns
The width
- Return type
- Available
- CScript
- CRect.getHeight()¶
Returns the height of the rectanggle
- Returns
The height
- Return type
- Available
- CScript
- CRect.getArea()¶
Returns the total area the rectangle covers
- Returns
The rectangle are
- Return type
- Available
- CScript
- CRect.getAspectRatio()¶
Calculates the aspect ratio for the rectangle.
The aspect ratio is calculated as the ratio of the rectangle’s height to its width.
If the rectangle is empty, 0.0 is returned.
- Returns
The aspect ratio
- Return type
- Available
- CScript
- CRect.moveTo(x, y, refPoint=0)¶
Move all coordinates so the reference point of the rectangle aligns with the provided coordinates
- Parameters
x (float) – The new horizontal center
y (float) – The new vertical center
refPoint (int) –
The reference point which should be moved to the target coordinates.
One of Reference Points.
Default is
comet.kRefPointTopLeft
.
- Return type
- Raises
TypeError – When parameter types are invalid
ValueError – When parameter refPoint has invalid value
- Available
- CScript
- CRect.moveBy(x, y)¶
Move all coordinates horizontally by x and vertically by y
- Parameters
- Return type
- Raises
TypeError – When parameter types are invalid
- Available
- CScript
- CRect.adjust(dx, dy, refPoint=0)¶
Enlarge (positive values) or shrink (negative values) the rectangle by moving the sides by the specified amounts. The adjusting is done around a fixed reference point.
- Parameters
dx (float) – The amount to adjust horizontally
dy (float) – The amount to adjust vertically
refPoint (int) –
The reference point which is fixed during resize.
One of Reference Points.
Default is
comet.kRefPointTopLeft
.
- Return type
- Raises
TypeError – When parameter types are invalid
ValueError – When parameter refPoint has invalid value
- Available
- CScript
- CRect.setLeft(value)¶
Set the left value component of the rectangle
- CRect.setTop(value)¶
Set the top value component of the rectangle
- CRect.setRight(value)¶
Set the right value component of the rectangle
- CRect.setBottom(value)¶
Set the bottom value component of the rectangle
- CRect.setWidth(value, refPoint=0)¶
Sets the new width of the rectangle by adjusting the horizontal components.
The center remains the same.
- Parameters
value (float) – The new desired rectangle width
refPoint (int) –
The reference point which is fixed during resize.
One of Reference Points.
Default is
comet.kRefPointTopLeft
.
- Return type
- Raises
TypeError – When parameter types are invalid
When parameter value has invalid value (< 0.0)
When parameter refPoint has invalid value
- Available
- CScript
- CRect.setHeight(value, refPoint=0)¶
Sets the new height of the rectangle by adjusting the vertical components. The center remains the same.
- Parameters
value (float) – The new desired rectangle height
refPoint (int) –
The reference point which is fixed during resize.
One of Reference Points.
Default is
comet.kRefPointTopLeft
.
- Return type
- Raises
TypeError – When parameter types are invalid
When parameter value has invalid value (< 0.0)
When parameter refPoint has invalid value
- Available
- CScript
- CRect.intersects(other)¶
Determines whether this rectangle intersects with another.
- CRect.createIntersection(other)¶
Create a new CRect by determining the intersection with other. May create a zero-length rectangle when no intersection is found.
- CRect.createUnion(other)¶
Create a union of the CRect instances.
- CRect.containsPoint(x, y)¶
Determine whether the rectangle contains the point defined by x and y.
- Parameters
- Returns
Whether the rectangle contains the point defined by x/y
- Return type
- Raises
TypeError – When parameter types are invalid
- Available
- CScript