ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::geometry Namespace Reference

Functions

template<typename T >
Vec2< T >::Real signed_area (const Polygon< T > &polygon)
 Get the signed area of a polygon.
 
template<typename T >
Quad< T > bounds (const Polygon< T > &polygon)
 Get the smallest rectangle that holds every corner of a polygon.
 
template<typename T >
bool point_in_triangle (const Vec2< T > &point, const Vec2< T > &a, const Vec2< T > &b, const Vec2< T > &c)
 Check if a point is inside a triangle. Points on an edge are inside.
 
std::optional< float > ray_hit (const Vec2f &origin, const Vec2f &direction, const Vec2f &a, const Vec2f &b)
 Find where a ray hits a line segment.
 
Polygonf visibility (const Vec2f &from, float radius, const std::vector< Polygonf > &occluders, float direction=0.0F, float cone=0.0F)
 Find the area that can be seen from a point.
 
void visibility (Polygonf &result, const Vec2f &from, float radius, const std::vector< Polygonf > &occluders, float direction=0.0F, float cone=0.0F)
 Find the area that can be seen from a point, into a polygon you keep between calls so it does not allocate each time.
 
void visibility (Polygonf &result, const Vec2f &from, float radius, const std::vector< Polygonf > &occluders, const std::vector< Quadf > &occluder_bounds, float direction=0.0F, float cone=0.0F)
 Find the area that can be seen from a point, with the bounds of the occluders already worked out, e.g. once per frame for many lights.
 

Function Documentation

◆ bounds()

template<typename T >
Quad< T > asw::geometry::bounds ( const Polygon< T > & polygon)

Get the smallest rectangle that holds every corner of a polygon.

Parameters
polygonThe polygon.
Returns
The bounds, or an empty rectangle at 0, 0 for no corners.

Definition at line 766 of file geometry.h.

◆ point_in_triangle()

template<typename T >
bool asw::geometry::point_in_triangle ( const Vec2< T > & point,
const Vec2< T > & a,
const Vec2< T > & b,
const Vec2< T > & c )

Check if a point is inside a triangle. Points on an edge are inside.

Parameters
pointThe point to check.
aThe first corner.
bThe second corner.
cThe third corner.
Returns
true if the point is inside or on the edge.

Definition at line 790 of file geometry.h.

◆ ray_hit()

std::optional< float > asw::geometry::ray_hit ( const Vec2f & origin,
const Vec2f & direction,
const Vec2f & a,
const Vec2f & b )

Find where a ray hits a line segment.

Parameters
originWhere the ray starts.
directionWhich way the ray goes. It does not need to be normalized.
aOne end of the segment.
bThe other end of the segment.
Returns
How far along the ray the hit is, in lengths of direction, or nothing when the ray misses or runs along the segment.

Definition at line 86 of file geometry.cpp.

◆ signed_area()

template<typename T >
Vec2< T >::Real asw::geometry::signed_area ( const Polygon< T > & polygon)

Get the signed area of a polygon.

Parameters
polygonThe polygon.
Returns
The area. It is positive when the corners go clockwise on screen and negative when they go anticlockwise.

Definition at line 751 of file geometry.h.

◆ visibility() [1/3]

asw::Polygonf asw::geometry::visibility ( const Vec2f & from,
float radius,
const std::vector< Polygonf > & occluders,
float direction = 0.0F,
float cone = 0.0F )

Find the area that can be seen from a point.

Useful for field of view and for light. Rays stop at the first polygon edge, and at a square of half size radius around from.

Parameters
fromThe point to look from.
radiusHow far to look.
occludersPolygons that block the view.
directionDirection to look, in radians, when cone is set.
coneWidth of the view in radians. 0 looks all round.
Returns
The edge of the visible area in angle order, not including from.

Definition at line 104 of file geometry.cpp.

◆ visibility() [2/3]

void asw::geometry::visibility ( Polygonf & result,
const Vec2f & from,
float radius,
const std::vector< Polygonf > & occluders,
const std::vector< Quadf > & occluder_bounds,
float direction = 0.0F,
float cone = 0.0F )

Find the area that can be seen from a point, with the bounds of the occluders already worked out, e.g. once per frame for many lights.

Parameters
occluder_boundsThe bounds() of each occluder, in the same order. Must be the same size as occluders.

Definition at line 123 of file geometry.cpp.

◆ visibility() [3/3]

void asw::geometry::visibility ( Polygonf & result,
const Vec2f & from,
float radius,
const std::vector< Polygonf > & occluders,
float direction = 0.0F,
float cone = 0.0F )

Find the area that can be seen from a point, into a polygon you keep between calls so it does not allocate each time.

Parameters
resultReplaced with the edge of the visible area.

Definition at line 112 of file geometry.cpp.