shapes

A set of functions to evaluate whether or not a point pos lies in a given shape. The available shapes are:

  • line – a line segment defined by endpoints a and b with a given thickness
  • circle – a circle originating at center with radius r
  • rectangle – an axis-aligned rectangle with corners lb and rt
  • halfPlane – a half-plane defined by an oriented line segment a, b
  • triangle – a triangle defined by its corners a, b, c in counter-clockwise order
  • convexPolygon – a convex polygon with N vertices in counter-clockwise order. Its functions are templates of N
  • polygon – a general polygon with N vertices in counter-clockwise order. Slower than convexPolygon.

Get the signed distance to the shape's closest edge. Values will be positive inside the shape, negative outside

float lineDistance(vec2 pos, vec2 a, vec2 b, float thickness);
float circleDistance(vec2 pos, vec2 center, float r);
float rectangleDistance(vec2 pos, vec2 lb, vec2 rt);
float halfPlaneDistance(vec2 pos, vec2 a, vec2 b);
float triangleDistance(vec2 pos, vec2 a, vec2 b, vec2 c);
template <N> float convexPolygonDistance(vec2 pos, vec2[N] vertices);
template <N> float polygonDistance(vec2 pos, vec2[N] vertices);

Decide whether the point lies inside the shape (only returns 0 or 1)

float line(vec2 pos, vec2 a, vec2 b, float thickness);
float circle(vec2 pos, vec2 center, float r);
float rectangle(vec2 pos, vec2 lb, vec2 rt);
float halfPlane(vec2 pos, vec2 a, vec2 b);
float triangle(vec2 pos, vec2 a, vec2 b, vec2 c);
template <N> float convexPolygon(vec2 pos, vec2[N] vertices);
template <N> float polygon(vec2 pos, vec2[N] vertices);

Draw the shape with anti-aliasing. border specifies the thickness of the border, typically 1 pixel

float lineSmooth(vec2 pos, vec2 a, vec2 b, float thickness, float border);
float circleSmooth(vec2 pos, vec2 center, float r, float border);
float rectangleSmooth(vec2 pos, vec2 lb, vec2 rt, float border);
float halfPlaneSmooth(vec2 pos, vec2 a, vec2 b, float border);
float triangleSmooth(vec2 pos, vec2 a, vec2 b, vec2 c, float border);
template <N> float convexPolygonSmooth(vec2 pos, vec2[N] vertices, float border);
template <N> float polygonSmooth(vec2 pos, vec2[N] vertices, float border);