Loading...
Searching...
No Matches
rectangle.h
Go to the documentation of this file.
#ifndef ARC_MATH_RECT_H_
#define ARC_MATH_RECT_H_
#include <stdint.h>
#include "point.h"
#include "vector2.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ARC_Rect {
int32_t x;
int32_t y;
int32_t w;
int32_t h;
} ARC_Rect;
typedef struct ARC_URect {
uint32_t x;
uint32_t y;
uint32_t w;
uint32_t h;
} ARC_URect;
typedef struct ARC_FRect {
float x;
float y;
float w;
float h;
} ARC_FRect;
/**
* @brief centers rect on given bounds
*
* @param rect ARC_Rect to be centered
* @param bounds ARC_Rect area to center rect on
*/
void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect *bounds);
/**
* @brief centers rect on given bounds
*
* @param rect ARC_FRect to be centered
* @param bounds ARC_FRect area to center rect on
*/
void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect *bounds);
/**
* @brief casts Rect to FRect
*
* @param rect ARC_Rect to be casted
*
* @return ARC_FRect
*/
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect *rect);
/**
* @brief casts FRect to Rect
*
* @param rect ARC_FRect to be casted
*
* @return ARC_Rect
*/
ARC_Rect ARC_FRect_CastToRect(ARC_FRect *rect);
/**
* @brief checks if two ARC_Rects intersect
*
* @param rect1 ARC_Rect that will be checked against rect2
* @param rect2 ARC_Rect that will be checked against rect1
*
* @return 1 if they intersect, 0 if they don't intersect
*/
int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2);
/**
* @brief checks if two ARC_FRects intersect
*
* @param rect1 ARC_FRect that will be checked against rect2
* @param rect2 ARC_FRect that will be checked against rect1
*
* @return 1 if they intersect, 0 if they don't intersect
*/
int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2);
/**
* @brief checks if ARC_Rect intersects with point
*
* @param rect ARC_Rect that will be checked against point
* @param point ARC_Point that will be checked against rect
*
* @return 1 if they intersect, 0 if they don't intersect
*/
int32_t ARC_Rect_IntersectsPoint(ARC_Rect *rect, ARC_Point *point);
/**
* @brief checks if ARC_FRect intersects with point
*
* @param rect ARC_FRect that will be checked against point
* @param point ARC_Point that will be checked against rect
*
* @return 1 if they intersect, 0 if they don't intersect
*/
int32_t ARC_FRect_IntersectsPoint(ARC_FRect *rect, ARC_Point *point);
/**
* @brief checks if ARC_Rect intersects a line
*
* @note need to update this documenation to word it better
*
* @param rect ARC_Rect that will be checked against line
* @param x1 first point's x value
* @param y1 first point's y value
* @param y2 second point's x value
* @param y2 second point's y value
*
* @return 1 if they intersect, 0 if they don't intersect
*/
int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2);
/**
* @brief checks for a ARC_Rect on ARC_Rect collision and slides on collision
*
* @note need to update this documenation to word it better
*
* @param rect ARC_Rect that might collide with the wall
* @param velocity the ammount ARC_Rect will move
* @param wall ARC_Rect that might have collision with rect
*
* @note velocity is updated based on colliding,
* rect's values are not changed,
* velocity should be applied after
*/
void ARC_FRect_CollideAndSlide(ARC_FRect *rect, ARC_Vector2 *velocity, ARC_FRect *wall);
#ifdef __cplusplus
}
#endif
#endif // ARC_MATH_POINT_H_
ARC_Rect_Intersects
int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2)
checks if two ARC_Rects intersect
ARC_FRect_CastToRect
ARC_Rect ARC_FRect_CastToRect(ARC_FRect *rect)
casts FRect to Rect
ARC_URect
struct ARC_URect ARC_URect
ARC_FRect_CollideAndSlide
void ARC_FRect_CollideAndSlide(ARC_FRect *rect, ARC_Vector2 *velocity, ARC_FRect *wall)
checks for a ARC_Rect on ARC_Rect collision and slides on collision
ARC_Rect_CastToFRect
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect *rect)
casts Rect to FRect
ARC_Rect_CenterOn
void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect *bounds)
centers rect on given bounds
ARC_FRect_IntersectsPoint
int32_t ARC_FRect_IntersectsPoint(ARC_FRect *rect, ARC_Point *point)
checks if ARC_FRect intersects with point
ARC_FRect_Intersects
int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2)
checks if two ARC_FRects intersect
ARC_Rect_IntersectsPoint
int32_t ARC_Rect_IntersectsPoint(ARC_Rect *rect, ARC_Point *point)
checks if ARC_Rect intersects with point
ARC_FRect
struct ARC_FRect ARC_FRect
ARC_Rect
struct ARC_Rect ARC_Rect
ARC_FRect_CenterOn
void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect *bounds)
centers rect on given bounds
ARC_Rect_LineIntersects
int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2)
checks if ARC_Rect intersects a line
point.h
ARC_FRect
Definition rectangle.h:26
ARC_FRect::y
float y
Definition rectangle.h:28
ARC_FRect::x
float x
Definition rectangle.h:27
ARC_FRect::w
float w
Definition rectangle.h:29
ARC_FRect::h
float h
Definition rectangle.h:30
ARC_Point
Definition point.h:10
ARC_Rect
Definition rectangle.h:12
ARC_Rect::x
int32_t x
Definition rectangle.h:13
ARC_Rect::w
int32_t w
Definition rectangle.h:15
ARC_Rect::y
int32_t y
Definition rectangle.h:14
ARC_Rect::h
int32_t h
Definition rectangle.h:16
ARC_URect
Definition rectangle.h:19
ARC_URect::x
uint32_t x
Definition rectangle.h:20
ARC_URect::w
uint32_t w
Definition rectangle.h:22
ARC_URect::h
uint32_t h
Definition rectangle.h:23
ARC_URect::y
uint32_t y
Definition rectangle.h:21
ARC_Vector2
Definition vector2.h:8
vector2.h