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

tuple[float, float, float, float]

Available

CScript
CRect.getLeft()

Returns the left component of the rectangle

Returns

The left side

Return type

float

Available

CScript

rect::left

CRect.getTop()

Returns the top component of the rectangle

Returns

The top side

Return type

float

Available

CScript

rect::top

CRect.getRight()

Returns the right component of the rectangle

Returns

The right side

Return type

float

Available

CScript

rect::right

CRect.getBottom()

Returns the bottom component of the rectangle

Returns

The bottom side

Return type

float

Available

CScript

rect::bottom

CRect.getCenter()

Returns the center of the rectangle

Returns

The center (x, y)

Return type

tuple(float, float)

Available

CScript
CRect.getWidth()

Returns the width of the rectanggle

Returns

The width

Return type

float

Available

CScript

rect::width

CRect.getHeight()

Returns the height of the rectanggle

Returns

The height

Return type

float

Available

CScript

rect::height

CRect.getArea()

Returns the total area the rectangle covers

Returns

The rectangle are

Return type

float

Available

CScript

rect::area

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

float

Available

CScript

rect::aspect_ratio

CRect.moveTo(x, y, refPoint=0)

Move all coordinates so the reference point of the rectangle aligns with the provided coordinates

Parameters
Return type

None

Raises
  • TypeError – When parameter types are invalid

  • ValueError – When parameter refPoint has invalid value

Available

CScript

rect::move_to

CRect.moveBy(x, y)

Move all coordinates horizontally by x and vertically by y

Parameters
  • x (float) – The amount to move horizontally

  • y (float) – The amount to move vertically

Return type

None

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::move_rel

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
Return type

None

Raises
  • TypeError – When parameter types are invalid

  • ValueError – When parameter refPoint has invalid value

Available

CScript

rect::inset

CRect.setLeft(value)

Set the left value component of the rectangle

Parameters

value (float) – The new left side

Return type

None

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::set_left

CRect.setTop(value)

Set the top value component of the rectangle

Parameters

value (float) – The new top side

Return type

None

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::set_top

CRect.setRight(value)

Set the right value component of the rectangle

Parameters

value (float) – The new right side

Return type

None

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::set_right

CRect.setBottom(value)

Set the bottom value component of the rectangle

Parameters

value (float) – The new bottom side

Return type

None

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::set_bottom

CRect.setWidth(value, refPoint=0)

Sets the new width of the rectangle by adjusting the horizontal components.

The center remains the same.

Parameters
Return type

None

Raises
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameter value has invalid value (< 0.0)

    • When parameter refPoint has invalid value

Available

CScript

rect::set_width

CRect.setHeight(value, refPoint=0)

Sets the new height of the rectangle by adjusting the vertical components. The center remains the same.

Parameters
Return type

None

Raises
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameter value has invalid value (< 0.0)

    • When parameter refPoint has invalid value

Available

CScript

rect::set_height

CRect.intersects(other)

Determines whether this rectangle intersects with another.

Parameters

other (CRect) – The other rectangle to test the intersection for

Returns

Whether the two rectangles intersect

Return type

bool

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::intersect

CRect.createIntersection(other)

Create a new CRect by determining the intersection with other. May create a zero-length rectangle when no intersection is found.

Parameters

other (CRect) – The other rectangle to create an intersection with

Returns

The intersection of the two rectangles

Return type

CRect

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::intersection

CRect.createUnion(other)

Create a union of the CRect instances.

Parameters

other (CRect) – The other rectangle to create a union with.

Returns

The intersection of the two rectangles

Return type

CRect

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::union_

CRect.containsPoint(x, y)

Determine whether the rectangle contains the point defined by x and y.

Parameters
  • x (float) – The x coordinate of the point to test

  • y (float) – The y coordinate of the point to test

Returns

Whether the rectangle contains the point defined by x/y

Return type

bool

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::contains_point

CRect.containsRect(other)

Determine whether the rectangle fully contains another one.

Parameters

other (CRect) – The other rectangle to test

Returns

Whether the rectangle fully contains other

Return type

bool

Raises

TypeError – When parameter types are invalid

Available

CScript

rect::contains