updated rect class and added some documentation
This commit is contained in:
parent
2b02bf9d2e
commit
3565a5cf15
3 changed files with 74 additions and 0 deletions
|
|
@ -21,8 +21,61 @@ typedef struct ARC_URect {
|
|||
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 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 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ uint8_t ARC_String_Equals(ARC_String *first, ARC_String *second);
|
|||
* @param string ARC_string to check
|
||||
* @param cstring cstring to check
|
||||
* @param length length of cstring
|
||||
*
|
||||
* @return 1 if match, 0 if they don't match
|
||||
*/
|
||||
uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,25 @@
|
|||
//VERY TEMP
|
||||
// #include <SDL.h>
|
||||
|
||||
void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect *bounds){
|
||||
rect->x = ((bounds->x + bounds->w) / 2) - (rect->w / 2);
|
||||
rect->y = ((bounds->y + bounds->h) / 2) - (rect->h / 2);
|
||||
}
|
||||
|
||||
void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect *bounds){
|
||||
rect->x = ((bounds->x + bounds->w) / 2.0f) - (rect->w / 2.0f);
|
||||
rect->y = ((bounds->y + bounds->h) / 2.0f) - (rect->h / 2.0f);
|
||||
}
|
||||
|
||||
ARC_Rect ARC_FRect_CastToRect(ARC_FRect *rect){
|
||||
return (ARC_Rect){
|
||||
.x = (int32_t)rect->x,
|
||||
.y = (int32_t)rect->y,
|
||||
.w = (int32_t)rect->w,
|
||||
.h = (int32_t)rect->h,
|
||||
};
|
||||
}
|
||||
|
||||
int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2){
|
||||
if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
|
||||
rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue