Polygons

class wasabi.geom.poly.Rect

2D rectangle class.

classmethod as_bounding(points)

Construct a Rect as the bounds of a sequence of points.

Parameters:points – An iterable of the points to bound.
bottomleft()

The bottom left point.

bottomright()

The bottom right point.

contains(p)

Return True if the point p is within the Rect.

classmethod from_blwh(bl, w, h)

Construct a Rect from its bottom left and dimensions.

classmethod from_cwh(c, w, h)

Construct a Rect from its center and dimensions.

classmethod from_points(p1, p2)

Construct the smallest Rect that contains the points p1 and p2.

get_aabb()

Return the axis-aligned bounding box of the Rect - ie. self.

h

Height of the rectangle.

intersection(r)

The intersection of this Rect with another.

overlaps(r)

Return True if this Rect overlaps another.

Not to be confused with .intersects(), which works for arbitrary convex polygons and computes a separation vector.

points

A list of the points in the rectangle.

topleft()

The top left point.

topright()

The top right point.

translate(off)

Return a new Rect translated by the vector off.

w

Width of the rectangle.

class wasabi.geom.poly.Triangle(base, primary, secondary)

Two-dimensional vector (oriented) triangle implementation.

area

The unsigned area of the triangle.

first

The point at the end of the primary vector.

classmethod from_points(base, first, second)

Create a Triangle object from its three points.

Parameters:
base : Vector

The base point of the triangle.

first, second : Vector

The other two points of the triangle.

is_clockwise

True if the primary and secondary are clockwise.

second

The point at the end of the secondary vector.

class wasabi.geom.poly.ConvexPolygon(points)
to_tri_strip()

Generate a list of the points in triangle-strip order

class wasabi.geom.poly.Polygon(vertices=None)

Mutable polygon, possibly with holes, multiple contours, etc.

This exists mainly as a wrapper for polygon triangulation, but also provides some useful methods.

add_contour(vertices)

Adds a contour

polylines_facing(v, threshold=0)

Compute a list of PolyLines on the edge of this contour whose normals face v.

threshold the value of the segment normal dot v required to include a segment in the polyline.