point centering functions added for rectangle and point
This commit is contained in:
parent
d89c95688e
commit
a829b656f3
4 changed files with 64 additions and 4 deletions
|
|
@ -27,8 +27,27 @@ typedef struct ARC_DPoint {
|
||||||
double y;
|
double y;
|
||||||
} ARC_DPoint;
|
} ARC_DPoint;
|
||||||
|
|
||||||
|
typedef struct ARC_Rect ARC_Rect;
|
||||||
|
typedef struct ARC_FRect ARC_FRect;
|
||||||
|
|
||||||
ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t);
|
ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief centers point on given bounds
|
||||||
|
*
|
||||||
|
* @param point ARC_Point to be centered
|
||||||
|
* @param bounds ARC_Rect area to center point on
|
||||||
|
*/
|
||||||
|
void ARC_Point_CenterOn(ARC_Point *point, ARC_Rect bounds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief centers fpoint on given bounds
|
||||||
|
*
|
||||||
|
* @param point ARC_FPoint to be centered
|
||||||
|
* @param bounds ARC_FRect area to center point on
|
||||||
|
*/
|
||||||
|
void ARC_FPoint_CenterOn(ARC_FPoint *point, ARC_FRect bounds);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,22 @@ void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect bounds);
|
||||||
*/
|
*/
|
||||||
void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect bounds);
|
void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect bounds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief centers rect on a given point
|
||||||
|
*
|
||||||
|
* @param rect ARC_Rect to be centered
|
||||||
|
* @param bounds ARC_Point point to center rect on
|
||||||
|
*/
|
||||||
|
void ARC_Rect_CenterOnPoint(ARC_Rect *rect, ARC_Point center);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief centers rect on a given point
|
||||||
|
*
|
||||||
|
* @param rect ARC_FRect to be centered
|
||||||
|
* @param bounds ARC_FPoint point to center rect on
|
||||||
|
*/
|
||||||
|
void ARC_FRect_CenterOnPoint(ARC_FRect *rect, ARC_FPoint center);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief casts Rect to FRect
|
* @brief casts Rect to FRect
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,26 @@
|
||||||
#include "arc/math/point.h"
|
#include "arc/math/point.h"
|
||||||
|
|
||||||
|
#include "arc/math/rectangle.h"
|
||||||
|
|
||||||
ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t){
|
ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t){
|
||||||
return (ARC_FPoint){
|
return (ARC_FPoint){
|
||||||
(1.0f - t) * start->x + t * end->x,
|
(1.0f - t) * start->x + t * end->x,
|
||||||
(1.0f - t) * start->y + t * end->y
|
(1.0f - t) * start->y + t * end->y
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ARC_Point_CenterOn(ARC_Point *point, ARC_Rect bounds){
|
||||||
|
*point = (ARC_Point){
|
||||||
|
(bounds.w / 2) + bounds.x,
|
||||||
|
(bounds.h / 2) + bounds.y
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARC_FPoint_CenterOn(ARC_FPoint *point, ARC_FRect bounds){
|
||||||
|
*point = (ARC_FPoint){
|
||||||
|
(bounds.w / 2.0f) + bounds.x,
|
||||||
|
(bounds.h / 2.0f) + bounds.y
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
#include "arc/math/rectangle.h"
|
#include "arc/math/rectangle.h"
|
||||||
#include "arc/std/bool.h"
|
#include "arc/std/bool.h"
|
||||||
|
|
||||||
//VERY TEMP
|
|
||||||
// #include <SDL.h>
|
|
||||||
|
|
||||||
void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect bounds){
|
void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect bounds){
|
||||||
rect->x = (bounds.x + (bounds.w / 2)) - (rect->w / 2);
|
rect->x = (bounds.x + (bounds.w / 2)) - (rect->w / 2);
|
||||||
rect->y = (bounds.y + (bounds.h / 2)) - (rect->h / 2);
|
rect->y = (bounds.y + (bounds.h / 2)) - (rect->h / 2);
|
||||||
|
|
@ -14,6 +11,16 @@ void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect bounds){
|
||||||
rect->y = (bounds.y + (bounds.h / 2.0f)) - (rect->h / 2.0f);
|
rect->y = (bounds.y + (bounds.h / 2.0f)) - (rect->h / 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ARC_Rect_CenterOnPoint(ARC_Rect *rect, ARC_Point center){
|
||||||
|
rect->x = center.x - (rect->w / 2);
|
||||||
|
rect->y = center.y - (rect->h / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARC_FRect_CenterOnPoint(ARC_FRect *rect, ARC_FPoint center){
|
||||||
|
rect->x = center.x - (rect->w / 2.0f);
|
||||||
|
rect->y = center.y - (rect->h / 2.0f);
|
||||||
|
}
|
||||||
|
|
||||||
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect rect){
|
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect rect){
|
||||||
return (ARC_FRect){
|
return (ARC_FRect){
|
||||||
.x = (float)rect.x,
|
.x = (float)rect.x,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue