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
andtarget

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 Lshaped path between
self
andtarget
.

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
iffself
contains all ofother
’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. Returnsself
unmodified if size won’t fit.

height
¶ Forwarded from
self.size.height

intersects
(other)¶ Returns
True
iffself
andother
share any points

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 (PointReal) – 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 aSize
, the X and Y axes will be inset by the respective amounts specified in each coordinate.

x
¶ Forwarded from
self.origin.x

x2
¶ Max X value of this rect. Readonly.

y
¶ Forwarded from
self.origin.y

y2
¶ Max Y value of this rect. Readonly.
