Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
geometryFl.c File Reference

Functions

bool circleCircleFlIntersection (circleFl_t circle1, circleFl_t circle2, vecFl_t *collisionPoint, vecFl_t *collisionVec)
 Check if two circles intersect.
 
bool circlePointFlIntersection (circleFl_t circle, vecFl_t point, vecFl_t *collisionVec)
 Check if a point and a circle intersect.
 
bool rectRectFlIntersection (rectangleFl_t rect1, rectangleFl_t rect2, vecFl_t *collisionVec)
 Check if two rectangles intersect.
 
bool circleRectFlIntersection (circleFl_t circle, rectangleFl_t rect, vecFl_t *collisionVec)
 Check if a circle and a rectangle intersect.
 
bool circleLineFlIntersection (circleFl_t circle, lineFl_t line, bool checkEnds, vecFl_t *cpOnLine, vecFl_t *collisionVec)
 Check if a circle and a line intersect.
 
int16_t circleLineFlIntersectionPoints (circleFl_t circle, lineFl_t line, vecFl_t *intersection_1, vecFl_t *intersection_2)
 Find the points of intersection between a circle's circumference and a line. There may be zero (no intersection), one (tangent), or two points of intersection.
 
bool lineLineFlIntersection (lineFl_t a, lineFl_t b)
 Check if two lines intersect.
 
vecFl_t infLineIntersectionPoint (lineFl_t a, lineFl_t b)
 Find the intersection point between two infinitely long lines.
 
bool rectLineFlIntersection (rectangleFl_t rect, lineFl_t line, vecFl_t *collisionVec)
 Check if a line intersects with a rectangle.
 

Function Documentation

◆ circleCircleFlIntersection()

bool circleCircleFlIntersection ( circleFl_t circle1,
circleFl_t circle2,
vecFl_t * collisionPoint,
vecFl_t * collisionVec )

Check if two circles intersect.

Parameters
circle1[IN] One circle to check for intersection, assumed to be moving
circle2[IN] The other circle to check for intersection, assumed to be fixed
collisionPoint[OUT] The point at which the two circles collide, on the circumference of circle2. May be NULL
collisionVec[OUT] A vector pointing from the second circle to the first in the direction of the collision. May be NULL.
Returns
true if the circles intersect or touch, false if they do not

◆ circlePointFlIntersection()

bool circlePointFlIntersection ( circleFl_t circle,
vecFl_t point,
vecFl_t * collisionVec )

Check if a point and a circle intersect.

Parameters
circle[IN] A circle to check for intersection
point[IN] A point to check for intersection
collisionVec[OUT] A vector pointing from the point to the circle in the direction of the collision. May be NULL.
Returns
true if the point intersects or touches the circle, false if it doesn't

◆ rectRectFlIntersection()

bool rectRectFlIntersection ( rectangleFl_t rect1,
rectangleFl_t rect2,
vecFl_t * collisionVec )

Check if two rectangles intersect.

Adapted from https://www.jeffreythompson.org/collision-detection/rect-rect.php

Parameters
rect1[IN] One rectangle to check for intersection
rect2[IN] The other rectangle to check for intersection
collisionVec[OUT] A vector pointing from the second rectangle to the first in the direction of the collision. May be NULL.
Returns
true if the rectangles intersect or touch, false if they do not

◆ circleRectFlIntersection()

bool circleRectFlIntersection ( circleFl_t circle,
rectangleFl_t rect,
vecFl_t * collisionVec )

Check if a circle and a rectangle intersect.

Adapted from https://www.jeffreythompson.org/collision-detection/circle-rect.php

Parameters
circle[IN] The circle to check for intersection
rect[IN] The rectangle to check for intersection
collisionVec[OUT] A vector pointing from the rectangle to the circle in the direction of the collision. May be NULL.
Returns
true if the shapes intersect or touch, false if they do not

◆ circleLineFlIntersection()

bool circleLineFlIntersection ( circleFl_t circle,
lineFl_t line,
bool checkEnds,
vecFl_t * cpOnLine,
vecFl_t * collisionVec )

Check if a circle and a line intersect.

Adapted from https://www.jeffreythompson.org/collision-detection/line-circle.php

Parameters
circle[IN] A circle to test intersection
line[IN] A line to test intersection
checkEnds[IN] True to check the points at the end of the line, false to ignore them
cpOnLine[OUT] The closest point on the line to the circle
collisionVec[OUT] A vector pointing from the line to the circle in the direction of the collision. This may be NULL.
Returns
true if the circle intersects the line, false if it doesn't

◆ circleLineFlIntersectionPoints()

int16_t circleLineFlIntersectionPoints ( circleFl_t circle,
lineFl_t line,
vecFl_t * intersection_1,
vecFl_t * intersection_2 )

Find the points of intersection between a circle's circumference and a line. There may be zero (no intersection), one (tangent), or two points of intersection.

See https://cp-algorithms.com/geometry/circle-line-intersection.html

Parameters
circle[IN] The circle to check for intersection
line[IN] The line to check for intersection
intersection_1[OUT] If it exists, the first intersection will be written to this pointer
intersection_2[OUT] If it exists, the second intersection will be written to this pointer
Returns
The number of intersections, between 0 and 2. intersection_1 is filled before intersection_2.

◆ lineLineFlIntersection()

bool lineLineFlIntersection ( lineFl_t a,
lineFl_t b )

Check if two lines intersect.

Adapted from https://www.jeffreythompson.org/collision-detection/line-line.php

Parameters
a[IN] One line to check for intersection
b[IN] Another line to check for intersection
Returns
true if the lines intersect, false if they do not

◆ infLineIntersectionPoint()

vecFl_t infLineIntersectionPoint ( lineFl_t a,
lineFl_t b )

Find the intersection point between two infinitely long lines.

Parameters
aOne infinitely long line
bAnother infinitely long line
Returns
The intersection, or (FLT_MAX, FLT_MAX) for parallel lines

◆ rectLineFlIntersection()

bool rectLineFlIntersection ( rectangleFl_t rect,
lineFl_t line,
vecFl_t * collisionVec )

Check if a line intersects with a rectangle.

Adapted from https://www.jeffreythompson.org/collision-detection/line-rect.php

Parameters
rect[IN] A rectangle to check for intersection
line[IN] A line to check for intersection
collisionVec[OUT] A vector pointing from the rectangle to the line in the direction of the collision. May be NULL.
Returns
true if the line intersects the rectangle, false if it doesn't