Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
rectangle.c File Reference

Go to the source code of this file.

Functions

void ARC_Rect_CenterOn (ARC_Rect *rect, ARC_Rect *bounds)
 centers rect on given bounds
 
void ARC_FRect_CenterOn (ARC_FRect *rect, ARC_FRect *bounds)
 centers rect on given bounds
 
ARC_FRect ARC_Rect_CastToFRect (ARC_Rect *rect)
 casts Rect to FRect
 
ARC_Rect ARC_FRect_CastToRect (ARC_FRect *rect)
 casts FRect to Rect
 
int32_t ARC_Rect_Intersects (ARC_Rect *rect1, ARC_Rect *rect2)
 checks if two ARC_Rects intersect
 
int32_t ARC_FRect_Intersects (ARC_FRect *rect1, ARC_FRect *rect2)
 checks if two ARC_FRects intersect
 
int32_t ARC_Rect_IntersectsPoint (ARC_Rect *rect, ARC_Point *point)
 checks if ARC_Rect intersects with point
 
int32_t ARC_FRect_IntersectsPoint (ARC_FRect *rect, ARC_Point *point)
 checks if ARC_FRect intersects with point
 
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
 
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
 

Function Documentation

◆ ARC_FRect_CastToRect()

ARC_Rect ARC_FRect_CastToRect ( ARC_FRect * rect)

casts FRect to Rect

Parameters
rectARC_FRect to be casted
Returns
ARC_Rect

Definition at line 25 of file rectangle.c.

25 {
26 return (ARC_Rect){
27 .x = (int32_t)rect->x,
28 .y = (int32_t)rect->y,
29 .w = (int32_t)rect->w,
30 .h = (int32_t)rect->h,
31 };
32}
float y
Definition rectangle.h:28
float x
Definition rectangle.h:27
float w
Definition rectangle.h:29
float h
Definition rectangle.h:30

References ARC_FRect::h, ARC_FRect::w, ARC_FRect::x, and ARC_FRect::y.

◆ ARC_FRect_CenterOn()

void ARC_FRect_CenterOn ( ARC_FRect * rect,
ARC_FRect * bounds )

centers rect on given bounds

Parameters
rectARC_FRect to be centered
boundsARC_FRect area to center rect on

Definition at line 11 of file rectangle.c.

11 {
12 rect->x = (bounds->x + (bounds->w / 2.0f)) - (rect->w / 2.0f);
13 rect->y = (bounds->y + (bounds->h / 2.0f)) - (rect->h / 2.0f);
14}

References ARC_FRect::h, ARC_FRect::w, ARC_FRect::x, and ARC_FRect::y.

◆ 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

Note
need to update this documenation to word it better
Parameters
rectARC_Rect that might collide with the wall
velocitythe ammount ARC_Rect will move
wallARC_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

Definition at line 74 of file rectangle.c.

74 {
75 ARC_FRect nextRectPosition = {
76 .x = rect->x + velocity->x,
77 .y = rect->y + velocity->y,
78 .w = rect->w,
79 .h = rect->h
80 };
81
82 //there is no collision, return
83 if(!ARC_FRect_Intersects(&nextRectPosition, wall)){
84 return;
85 }
86
87 nextRectPosition.x = rect->x + velocity->x;
88 nextRectPosition.y = rect->y;
89 if(ARC_FRect_Intersects(&nextRectPosition, wall)){
90 velocity->x = 0;
91 }
92
93 nextRectPosition.x = rect->x;
94 nextRectPosition.y = rect->y + velocity->y;
95 if(ARC_FRect_Intersects(&nextRectPosition, wall)){
96 velocity->y = 0;
97 }
98}
int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2)
checks if two ARC_FRects intersect
Definition rectangle.c:42
float x
Definition vector2.h:9
float y
Definition vector2.h:9

References ARC_FRect_Intersects(), ARC_FRect::h, ARC_FRect::w, ARC_FRect::x, ARC_Vector2::x, ARC_FRect::y, and ARC_Vector2::y.

◆ ARC_FRect_Intersects()

int32_t ARC_FRect_Intersects ( ARC_FRect * rect1,
ARC_FRect * rect2 )

checks if two ARC_FRects intersect

Parameters
rect1ARC_FRect that will be checked against rect2
rect2ARC_FRect that will be checked against rect1
Returns
1 if they intersect, 0 if they don't intersect

Definition at line 42 of file rectangle.c.

42 {
43 if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
44 rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){
45 return 1;
46 }
47 return 0;
48}

References ARC_FRect::h, ARC_FRect::w, ARC_FRect::x, and ARC_FRect::y.

Referenced by ARC_FRect_CollideAndSlide().

◆ ARC_FRect_IntersectsPoint()

int32_t ARC_FRect_IntersectsPoint ( ARC_FRect * rect,
ARC_Point * point )

checks if ARC_FRect intersects with point

Parameters
rectARC_FRect that will be checked against point
pointARC_Point that will be checked against rect
Returns
1 if they intersect, 0 if they don't intersect

Definition at line 58 of file rectangle.c.

58 {
59 if(rect->x <= point->x && rect->x + rect->w >= point->x &&
60 rect->y <= point->y && rect->y + rect->h >= point->y){
61 return 1;
62 }
63 return 0;
64}
int32_t y
Definition point.h:12
int32_t x
Definition point.h:11

References ARC_FRect::h, ARC_FRect::w, ARC_FRect::x, ARC_Point::x, ARC_FRect::y, and ARC_Point::y.

◆ ARC_Rect_CastToFRect()

ARC_FRect ARC_Rect_CastToFRect ( ARC_Rect * rect)

casts Rect to FRect

Parameters
rectARC_Rect to be casted
Returns
ARC_FRect

Definition at line 16 of file rectangle.c.

16 {
17 return (ARC_FRect){
18 .x = (float)rect->x,
19 .y = (float)rect->y,
20 .w = (float)rect->w,
21 .h = (float)rect->h,
22 };
23}
int32_t x
Definition rectangle.h:13
int32_t w
Definition rectangle.h:15
int32_t y
Definition rectangle.h:14
int32_t h
Definition rectangle.h:16

References ARC_Rect::h, ARC_Rect::w, ARC_Rect::x, and ARC_Rect::y.

◆ ARC_Rect_CenterOn()

void ARC_Rect_CenterOn ( ARC_Rect * rect,
ARC_Rect * bounds )

centers rect on given bounds

Parameters
rectARC_Rect to be centered
boundsARC_Rect area to center rect on

Definition at line 6 of file rectangle.c.

6 {
7 rect->x = (bounds->x + (bounds->w / 2)) - (rect->w / 2);
8 rect->y = (bounds->y + (bounds->h / 2)) - (rect->h / 2);
9}

References ARC_Rect::h, ARC_Rect::w, ARC_Rect::x, and ARC_Rect::y.

◆ ARC_Rect_Intersects()

int32_t ARC_Rect_Intersects ( ARC_Rect * rect1,
ARC_Rect * rect2 )

checks if two ARC_Rects intersect

Parameters
rect1ARC_Rect that will be checked against rect2
rect2ARC_Rect that will be checked against rect1
Returns
1 if they intersect, 0 if they don't intersect

Definition at line 34 of file rectangle.c.

34 {
35 if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
36 rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){
37 return 1;
38 }
39 return 0;
40}

References ARC_Rect::h, ARC_Rect::w, ARC_Rect::x, and ARC_Rect::y.

◆ ARC_Rect_IntersectsPoint()

int32_t ARC_Rect_IntersectsPoint ( ARC_Rect * rect,
ARC_Point * point )

checks if ARC_Rect intersects with point

Parameters
rectARC_Rect that will be checked against point
pointARC_Point that will be checked against rect
Returns
1 if they intersect, 0 if they don't intersect

Definition at line 50 of file rectangle.c.

50 {
51 if(rect->x <= point->x && rect->x + rect->w >= point->x &&
52 rect->y <= point->y && rect->y + rect->h >= point->y){
53 return 1;
54 }
55 return 0;
56}

References ARC_Rect::h, ARC_Rect::w, ARC_Point::x, ARC_Rect::x, ARC_Point::y, and ARC_Rect::y.

◆ 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

Note
need to update this documenation to word it better
Parameters
rectARC_Rect that will be checked against line
x1first point's x value
y1first point's y value
y2second point's x value
y2second point's y value
Returns
1 if they intersect, 0 if they don't intersect

Definition at line 66 of file rectangle.c.

66 {
67 //TODO: Replace soon
68 // return SDL_IntersectRectAndLine((SDL_Rect *) rect, x1, y1, x2, y2);
69 return 1;
70}