PER Firmware
Loading...
Searching...
No Matches
geometry.h File Reference

Planar computational geometry utility header. More...

#include <stdbool.h>
#include "utils/abs.h"
#include "utils/vector2.h"
#include "utils/max.h"
#include "utils/min.h"
Include dependency graph for geometry.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  segment2_t
 

Enumerations

enum  winding_t { WINDING_COLLINEAR = 0 , WINDING_CLOCKWISE , WINDING_COUNTERCLOCKWISE }
 

Functions

static winding_t vector2_winding (const vector2_t a, const vector2_t b, const vector2_t c)
 Determine which way the path a -> b -> c turns.
 
static float segment2_length (const segment2_t segment)
 Calculate the length of a segment.
 
static bool segment2_contains_bounds (const segment2_t segment, const vector2_t point)
 Test whether a point falls inside a segment's bounding box.
 
static bool segment2_intersects (const segment2_t a, const segment2_t b)
 Test whether two segments intersect, including collinear overlap.
 
static segment2_t segment2_perpendicular_bisector (const segment2_t segment, const float half_length)
 Build the segment perpendicular to a segment through its midpoint.
 

Variables

static constexpr float GEOMETRY_EPSILON = 1e-6f
 

Detailed Description

Planar computational geometry utility header.

Winding and segment intersection tests built on vector2_t. All points must live in the same cartesian frame; units are arbitrary but must be consistent.

Author
Amruth Nadimpally (nadim.nosp@m.paa@.nosp@m.purdu.nosp@m.e.ed.nosp@m.u)
Aditya Saini (saini.nosp@m.91@p.nosp@m.urdue.nosp@m..edu)

Enumeration Type Documentation

◆ winding_t

enum winding_t
Enumerator
WINDING_COLLINEAR 
WINDING_CLOCKWISE 
WINDING_COUNTERCLOCKWISE 

Function Documentation

◆ segment2_contains_bounds()

static bool segment2_contains_bounds ( const segment2_t segment,
const vector2_t point )
inlinestatic

Test whether a point falls inside a segment's bounding box.

Only meaningful for a point already known to be collinear with the segment, where it distinguishes lying on the segment from lying on its extension.

Parameters
segmentThe input segment
pointThe point to test
Returns
True if the point is within the segment bounds.
Here is the caller graph for this function:

◆ segment2_intersects()

static bool segment2_intersects ( const segment2_t a,
const segment2_t b )
inlinestatic

Test whether two segments intersect, including collinear overlap.

Parameters
aThe first segment
bThe second segment
Returns
True if the segments touch or cross anywhere.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ segment2_length()

static float segment2_length ( const segment2_t segment)
inlinestatic

Calculate the length of a segment.

Parameters
segmentThe input segment
Returns
The distance between the segment endpoints.
Here is the call graph for this function:

◆ segment2_perpendicular_bisector()

static segment2_t segment2_perpendicular_bisector ( const segment2_t segment,
const float half_length )
inlinestatic

Build the segment perpendicular to a segment through its midpoint.

Parameters
segmentThe segment to bisect
half_lengthDistance the result extends either side of the midpoint
Returns
The perpendicular bisector, degenerate if segment has no length.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vector2_winding()

static winding_t vector2_winding ( const vector2_t a,
const vector2_t b,
const vector2_t c )
inlinestatic

Determine which way the path a -> b -> c turns.

Parameters
aThe first point
bThe second point
cThe third point
Returns
The winding direction of the three points.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ GEOMETRY_EPSILON

float GEOMETRY_EPSILON = 1e-6f
staticconstexpr