Loading...
Searching...
No Matches
rectangle.c File Reference
`#include "arc/math/rectangle.h"`

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

  rect | ARC_FRect to be casted

Returns
  ARC_Rect

Definition at line 25 of file rectangle.c.

{
return (ARC_Rect){
.x = (int32_t)rect->x,
.y = (int32_t)rect->y,
.w = (int32_t)rect->w,
.h = (int32_t)rect->h,
};
}
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_Rect
Definition rectangle.h:12

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

Referenced by ARC_FRect_Render(), and ARC_FRect_RenderFill().

## ARC_FRect_CenterOn()

void ARC_FRect_CenterOn | ( | ARC_FRect * | rect,
|  | ARC_FRect * | bounds )

centers rect on given bounds

Parameters

  rect | ARC_FRect to be centered
  bounds | ARC_FRect area to center rect on

Definition at line 11 of file rectangle.c.

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

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

  rect | ARC_Rect that might collide with the wall
  velocity | the ammount ARC_Rect will move
  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

Definition at line 74 of file rectangle.c.

{
ARC_FRect nextRectPosition = {
.x = rect->x + velocity->x,
.y = rect->y + velocity->y,
.w = rect->w,
.h = rect->h
};
//there is no collision, return
if(!ARC_FRect_Intersects(&nextRectPosition, wall)){
return;
}
nextRectPosition.x = rect->x + velocity->x;
nextRectPosition.y = rect->y;
if(ARC_FRect_Intersects(&nextRectPosition, wall)){
velocity->x = 0;
}
nextRectPosition.x = rect->x;
nextRectPosition.y = rect->y + velocity->y;
if(ARC_FRect_Intersects(&nextRectPosition, wall)){
velocity->y = 0;
}
}
ARC_FRect_Intersects
int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2)
checks if two ARC_FRects intersect
Definition rectangle.c:42
ARC_FRect
Definition rectangle.h:26
ARC_Vector2::x
float x
Definition vector2.h:9
ARC_Vector2::y
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

  rect1 | ARC_FRect that will be checked against rect2
  rect2 | ARC_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.

{
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){
return 1;
}
return 0;
}

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

  rect | ARC_FRect that will be checked against point
  point | ARC_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.

{
if(rect->x <= point->x && rect->x + rect->w >= point->x &&
rect->y <= point->y && rect->y + rect->h >= point->y){
return 1;
}
return 0;
}
ARC_Point::y
int32_t y
Definition point.h:12
ARC_Point::x
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

  rect | ARC_Rect to be casted

Returns
  ARC_FRect

Definition at line 16 of file rectangle.c.

{
return (ARC_FRect){
.x = (float)rect->x,
.y = (float)rect->y,
.w = (float)rect->w,
.h = (float)rect->h,
};
}
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

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

  rect | ARC_Rect to be centered
  bounds | ARC_Rect area to center rect on

Definition at line 6 of file rectangle.c.

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

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

  rect1 | ARC_Rect that will be checked against rect2
  rect2 | ARC_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.

{
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){
return 1;
}
return 0;
}

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

  rect | ARC_Rect that will be checked against point
  point | ARC_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.

{
if(rect->x <= point->x && rect->x + rect->w >= point->x &&
rect->y <= point->y && rect->y + rect->h >= point->y){
return 1;
}
return 0;
}

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

  rect | ARC_Rect that will be checked against line
  x1 | first point's x value
  y1 | first point's y value
  y2 | second point's x value
  y2 | second point's y value

Returns
  1 if they intersect, 0 if they don't intersect

Definition at line 66 of file rectangle.c.

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