clubsandwich.geom

Simple data structures for working with points, sizes, and rects.

class clubsandwich.geom.Point(x=0, y=0)
Parameters:
  • x (Real) –
  • y (Real) –

Represents a point in 2D space. Supports arithmetic operations with other points, and supports multiplication and division with numbers.

BearLibTerminal requires ints for all coordinate values, so floored is your friend.

x

X axis coordinate; may be any number

y

Y coordinate; may be any number

diagonal_neighbors

Generator of all points that share only a corner with self.

floored

A copy of this point with math.floor() called on each coordinate.

get_closest_point(candidates)
Parameters:candidates ([Point]) –
Returns:Point

Of all the point in candidates, return the one closest to self.

get_farthest_point(candidates)
Parameters:candidates ([Point]) –
Returns:Point

Of all the point in candidates, return the one farthest from self.

manhattan_distance_to(target)
Returns:Manhattan distance between self and target
neighbors

Generator of all points that share a horizontal or vertical edge with this one.

path_L_to(target)

Generator of all points on an L-shaped path between self and target.

points_bresenham_to(other)
Parameters:other (Point) –

Generator of all points on a Bresenham algorithm line between self and other.

class clubsandwich.geom.Rect(origin=None, size=None)
Parameters:

Represents an rectangle in 2D space.

BearLibTerminal requires ints for all coordinate values, so floored is your friend.

origin

Origin of the rectangle

size

Size of the rectangle

area
Returns:int (area of self)
center

Point at the center of this rect

contains(point)

Returns True iff self contains all of other’s points

floored

A copy of this rect with the Point.floored origin/size copies

get_random_point()

Returns a random point inside self

get_random_rect(min_size=Size(1, 1))
Parameters:min_size (Size) –
Returns:Rect

Returns a random rect inside self with the given minimum size. Returns self unmodified if size won’t fit.

height

Forwarded from self.size.height

intersects(other)

Returns True iff self and other share any points

moved_by(delta)
Parameters:delta (Point) –

A copy of this rect with the origin moved by delta

point_bottom_left

Point at the bottom left corner of this rect

point_bottom_right

Point at the bottom right corner of this rect

point_top_right

Point at the top right corner of this rect

points

Iterator of all points in this rect

points_bottom

Iterator of all points along the bottom edge of this rect

points_corners

Iterator of all four points in this rect’s corners

points_left

Iterator of all points along the left edge of this rect

points_right

Iterator of all points along the right edge of this rect

points_top

Iterator of all points along the top edge of this rect

width

Forwarded from self.size.width

with_inset(inset)
Parameters:inset (Point|Real) –

A copy of this rect inset by the given amount. If you pass a number, all sides will be inset by the same amount. If you pass a Point or a Size, the X and Y axes will be inset by the respective amounts specified in each coordinate.

with_origin(new_origin)
Parameters:new_origin (Point) –

A copy of this rect with the given origin

with_size(new_size)
Parameters:new_size (Point) –

A copy of this rect with the given size

x

Forwarded from self.origin.x

x2

Max X value of this rect. Read-only.

y

Forwarded from self.origin.y

y2

Max Y value of this rect. Read-only.

class clubsandwich.geom.Size(width=0, height=0)
Parameters:
  • width (Real) –
  • height (Real) –

Thin wrapper over Point that forwards x to width and y to height.

width

alias for x

height

alias for y