Location & Vector

class sorrel.location.Location(*coords)

A custom subclass of tuple that represents a location in the environment.

This class provides additional functionality for calculations, such as addition and scalar multiplication. Since it is a subclass of tuple, Location objects are immutable.

Examples

>>> Location(1, 2, 3) + Location(2, 4, 8)
Location(3, 6, 11)
>>> Location(2, 4) * 3
Location(6, 12, 0)
__add__(other: tuple | Vector) Location

Add a coordinate or a vector to this location.

Parameters:

other (tuple | Vector) – A set of coordinates (can be a Location object) or a vector.

Returns:

The resulting location.

Return type:

Location

__eq__(other) bool

Compare self with another coordinate or a vector.

Parameters:

other (tuple | Vector) – A set of coordinates (can be a Location object) or a vector.

Returns:

whether this Location has the same dimension and the same values as the other object.

Return type:

bool

__mul__(other) Location

Multiply a location by an integer amount (scalar multiplication).

Parameters:

other (int) – The scalar to multiply by.

Returns:

The resulting location.

Return type:

Location

class sorrel.location.Vector(forward: int, right: int, backward: int = 0, left: int = 0, layer: int = 0, direction: int = 0)

A class that represents vectors. Handy for calculations involving beams and more.

forward

The number of steps forward.

Type:

int

right

The number of steps right.

Type:

int

backward

(Optional) The number of steps backward. Since negative vectors are supported, this can be carried by the forward value.

Type:

int

left

(Optional) The number of steps left. Since negative vectors are supported, this can be carried by the right value.

Type:

int

layer

(Optional) The number of layers up (positive) or down (negative).

Type:

int

direction

(Optional) A compass direction. 0 = NORTH, 1 = EAST, 2 = SOUTH, 3 = WEST.

Type:

int

__add__(other) Vector

Add two vectors together.

The vectors must be with respect to the same direction.

__mul__(other) Vector

Multiply a location by an integer amount.

compute() Location

Given a direction being faced and a number of paces forward / right / backward / left, compute the location.

rotate(new_direction: int)

Rotate the vector to face a new direction.