r2d.h File Reference
#include <stdint.h>

Go to the source code of this file.

Classes

struct  r2d_rvec2
 Vector struct. More...
 
struct  r2d_dvec2
 Integer vector struct for grid indexing. More...
 
struct  r2d_plane
 A plane. More...
 
struct  r2d_orientation
 Perpendicular distances and bit flags for up to 6 faces. More...
 
struct  r2d_vertex
 A doubly-linked vertex. More...
 
struct  r2d_poly
 A polygon. More...
 
struct  r2d_dest_grid
 Destination grid information. More...
 

Macros

#define R2D_MAX_VERTS   64
 

Typedefs

typedef double r2d_real
 Real type specifying the precision to be used in calculations. More...
 
typedef int32_t r2d_int
 Integer type used for grid indexing and bit flags. More...
 
typedef int64_t r2d_long
 Long integer type used for grid indexing. More...
 

Functions

void r2d_rasterize_quad (r2d_plane *faces, r2d_dest_grid *grid)
 Rasterize a convex quadrilateral to the destination grid. More...
 
void r2d_clip_quad (r2d_poly *poly, unsigned char andcmp)
 Clip a polygon against four clip planes (find its intersection with a quadrilateral). More...
 
void r2d_reduce (r2d_poly *poly, r2d_int polyorder, r2d_real *moments)
 Integrate a polynomial density over a polygon using simplicial decomposition. More...
 
void r2du_init_box (r2d_poly *poly, r2d_rvec2 rbounds[2])
 Initialize a polygon as an axis-aligned box. More...
 
void r2du_faces_from_verts (r2d_rvec2 *verts, r2d_int nverts, r2d_plane *faces)
 Get faces (unit normals and distances to the origin) from an ordered-vertex description of a convex polygon. More...
 
r2d_real r2du_orient (r2d_rvec2 pa, r2d_rvec2 pb, r2d_rvec2 pc)
 Get the signed area of the triangle defined by the input vertices. More...
 

Macro Definition Documentation

◆ R2D_MAX_VERTS

#define R2D_MAX_VERTS   64

Typedef Documentation

◆ r2d_int

typedef int32_t r2d_int

Integer type used for grid indexing and bit flags.

◆ r2d_long

typedef int64_t r2d_long

Long integer type used for grid indexing.

◆ r2d_real

typedef double r2d_real

Real type specifying the precision to be used in calculations.

Default is double (recommended). float precision is enabled by compiling with -DSINGLE_PRECISION.

Function Documentation

◆ r2d_clip_quad()

void r2d_clip_quad ( r2d_poly poly,
unsigned char  andcmp 
)

Clip a polygon against four clip planes (find its intersection with a quadrilateral).

Parameters
[in,out]polyThe polygon to be clipped. The distances to the clip plane and bit flags in poly.verts[...].orient must be set prior to calling this function.
[in]andcmpSet of bit flags allowing faces to be skipped. Face f will be skipped if andcmp & (1 << f) evaluates to true.

◆ r2d_rasterize_quad()

void r2d_rasterize_quad ( r2d_plane faces,
r2d_dest_grid grid 
)

Rasterize a convex quadrilateral to the destination grid.

Parameters
[in]facesThe four faces of the quadrilateral to be voxelized.
[in,out]gridThe destination grid buffer that the quadrilateral will be voxelized to. The results of the rasterization are found in grid.moments.

◆ r2d_reduce()

void r2d_reduce ( r2d_poly poly,
r2d_int  polyorder,
r2d_real moments 
)

Integrate a polynomial density over a polygon using simplicial decomposition.

Parameters
[in]polyThe polygon over which to integrate.
[in]polyorderOrder of the polynomial density field. 0 for constant (1 moment), 1 for linear (3 moments), 2 for quadratic (6 moments).
[in,out]momentsArray to be filled with the integration results, up to the sepcified polyorder. Order of moments is 1, x, y, x^2, y^2, x*y.

◆ r2du_faces_from_verts()

void r2du_faces_from_verts ( r2d_rvec2 verts,
r2d_int  nverts,
r2d_plane faces 
)

Get faces (unit normals and distances to the origin) from an ordered-vertex description of a convex polygon.

Parameters
[in]vertsList of polygon vertices.
[in]nvertsNumber of polygon vertices in the list.
[out]facesArray of planes defining the faces of the polygon. Must be at least nverts in size.

◆ r2du_init_box()

void r2du_init_box ( r2d_poly poly,
r2d_rvec2  rbounds[2] 
)

Initialize a polygon as an axis-aligned box.

Parameters
[in,out]polyThe polygon to initialize.
[in]rboundsAn array of two vectors, giving the lower and upper corners of the box.

◆ r2du_orient()

r2d_real r2du_orient ( r2d_rvec2  pa,
r2d_rvec2  pb,
r2d_rvec2  pc 
)

Get the signed area of the triangle defined by the input vertices.

Parameters
[in]pa,pb,pcVertices defining a triangle from which to calculate an area.
Returns
The signed area of the input triangle.