Geometry

SpatialObject

class serge.geometry.SpatialObject[source]

Bases: object

Represents a spatial object

isInside(other)[source]

Return True if this object is inside another

isOverlapping(other)[source]

Return True if this object overlaps another

Rectangle

class serge.geometry.Rectangle(x=0, y=0, w=0, h=0)[source]

Bases: serge.geometry.SpatialObject, serge.serialize.Serializable

Represents a rectangle

classmethod fromCenter(cx, cy, w, h)[source]

Return a new rectangle giving the center x, y and width, height

getArea()[source]

Return the area of the shape

getDistanceFrom(other)[source]

Return the distance we are from another

getOrigin()[source]

Get the left and top coords

getRelativeLocation(other)[source]

Return the relative location of another object

getRelativeLocationCentered(other)[source]

Return the relative location of another object

getSpatial()[source]

Return spatial details

getSpatialCentered()[source]

Return spatial details

init()[source]

Initialize from serialized

isInside(other)[source]

Return True if this object is inside another

isOverlapping(other)[source]

Return True if this object overlaps another

move(dx, dy)[source]

Move the actor

moveTo(x, y, override_lock=False)[source]

Move the center of this object to the given location, unless it is locked

This is the main method used to implement the position of the shape. This is the one to override.

resizeBy(w, h)[source]

Resize the spatial by the given extent

resizeTo(w, h)[source]

Resize the spatial by the given extent

scale(factor)[source]

Rescale the spatial extent

setOrigin(x, y)[source]

Set the left and top coords

setSpatial(x, y, w, h)[source]

Set the spatial details of ourself

setSpatialCentered(x, y, w, h)[source]

Set the spatial details of ourself

Point

class serge.geometry.Point(x, y)[source]

Bases: serge.geometry.Rectangle

Represents a point

isInside(other)[source]

Return True if this object is inside another

isOverlapping(other)[source]

Return True if this object overlaps another

SimpleRect

class serge.geometry.SimpleRect(*args)[source]

Bases: list

A simple rectangle implementation

collidepoint(x, y)[source]

Return True if this rectangle collides with another

colliderect(other)[source]

Return True if this rectangle collides with another

contains(other)[source]

Return True if this rectangle contains another

inflate(w, h)[source]

Inflate to new width and height staying in the same centered place

inflate_ip(w, h)[source]

Inflate current rectangle to new width and height staying in the same centered place

move_ip(dx, dy)[source]

Move in place

Vec2d

class serge.simplevecs.Vec2d(x_or_pair=None, y=None)[source]

Bases: object

2d vector class, supports vector and scalar operators, and also provides some high level functions

angle

Gets or sets the angle (in radians) of a vector

angle_degrees

Gets or sets the angle (in degrees) of a vector

cpvrotate(other)[source]

Uses complex multiplication to rotate this vector by the other.

cpvunrotate(other)[source]

The inverse of cpvrotate

cross(other)[source]
The cross product between the vector and other vector
v1.cross(v2) -> v1.x*v2.y - v2.y*v1.x
Returns:The cross product
dot(other)[source]
The dot product between the vector and other vector
v1.dot(v2) -> v1.x*v2.x + v1.y*v2.y
Returns:The dot product
classmethod from_param(arg)[source]

Used by ctypes to automatically create Vec2ds

get_angle_between(other)[source]

Get the angle between the vector and the other in radians

Returns:The angle
get_angle_degrees_between(other)[source]

Get the angle between the vector and the other in degrees

Returns:The angle (in degrees)
get_dist_sqrd(other)[source]

The squared distance between the vector and other vector It is more efficent to use this method than to call get_distance() first and then do a sqrt() on the result.

Returns:The squared distance
get_distance(other)[source]

The distance between the vector and other vector

Returns:The distance
get_length()[source]

Get the length of the vector.

Returns:The length
get_length_sqrd()[source]

Get the squared length of the vector. It is more efficent to use this method instead of first call get_length() or access .length and then do a sqrt().

Returns:The squared length
int_tuple

Return the x and y values of this vector as ints

length

Gets or sets the magnitude of the vector

normalize_return_length()[source]

Normalize the vector and return its length before the normalization

Returns:The length before the normalization
normalized()[source]

Get a normalized copy of the vector Note: This function will return 0 if the length of the vector is 0.

Returns:A normalized vector
static ones()[source]

A vector where both x and y is 1

rotate(angle_radians)[source]

Rotate the vector by angle_radians radians.

rotate_degrees(angle_degrees)[source]

Rotate the vector by angle_degrees degrees.

rotated(angle_radians)[source]

Create and return a new vector by rotating this vector by angle_radians radians.

Returns:Rotade vector
rotated_degrees(angle_degrees)[source]

Create and return a new vector by rotating this vector by angle_degrees degrees.

Returns:Rotade vector
static unit()[source]

A unit vector pointing up

static zero()[source]

A vector of zero length