migrate to new c djstdlib

This commit is contained in:
Daniel Ledda
2025-11-14 10:37:18 +01:00
parent 344056744d
commit 7ec69b3067
21 changed files with 392 additions and 366 deletions

View File

@@ -117,7 +117,7 @@
typedef struct RLVector2 {
float x;
float y;
} RMVector2;
} RLVector2;
#define RL_VECTOR2_TYPE
#endif
@@ -233,55 +233,55 @@ RMAPI int FloatEquals(float x, float y)
//----------------------------------------------------------------------------------
// Vector with components value 0.0f
RMAPI RMVector2 Vector2Zero(void)
RMAPI RLVector2 Vector2Zero(void)
{
RMVector2 result = { 0.0f, 0.0f };
RLVector2 result = { 0.0f, 0.0f };
return result;
}
// Vector with components value 1.0f
RMAPI RMVector2 Vector2One(void)
RMAPI RLVector2 Vector2One(void)
{
RMVector2 result = { 1.0f, 1.0f };
RLVector2 result = { 1.0f, 1.0f };
return result;
}
// Add two vectors (v1 + v2)
RMAPI RMVector2 Vector2Add(RMVector2 v1, RMVector2 v2)
RMAPI RLVector2 Vector2Add(RLVector2 v1, RLVector2 v2)
{
RMVector2 result = { v1.x + v2.x, v1.y + v2.y };
RLVector2 result = { v1.x + v2.x, v1.y + v2.y };
return result;
}
// Add vector and float value
RMAPI RMVector2 Vector2AddValue(RMVector2 v, float add)
RMAPI RLVector2 Vector2AddValue(RLVector2 v, float add)
{
RMVector2 result = { v.x + add, v.y + add };
RLVector2 result = { v.x + add, v.y + add };
return result;
}
// Subtract two vectors (v1 - v2)
RMAPI RMVector2 Vector2Subtract(RMVector2 v1, RMVector2 v2)
RMAPI RLVector2 Vector2Subtract(RLVector2 v1, RLVector2 v2)
{
RMVector2 result = { v1.x - v2.x, v1.y - v2.y };
RLVector2 result = { v1.x - v2.x, v1.y - v2.y };
return result;
}
// Subtract vector by float value
RMAPI RMVector2 Vector2SubtractValue(RMVector2 v, float sub)
RMAPI RLVector2 Vector2SubtractValue(RLVector2 v, float sub)
{
RMVector2 result = { v.x - sub, v.y - sub };
RLVector2 result = { v.x - sub, v.y - sub };
return result;
}
// Calculate vector length
RMAPI float Vector2Length(RMVector2 v)
RMAPI float Vector2Length(RLVector2 v)
{
float result = sqrtf((v.x*v.x) + (v.y*v.y));
@@ -289,7 +289,7 @@ RMAPI float Vector2Length(RMVector2 v)
}
// Calculate vector square length
RMAPI float Vector2LengthSqr(RMVector2 v)
RMAPI float Vector2LengthSqr(RLVector2 v)
{
float result = (v.x*v.x) + (v.y*v.y);
@@ -297,7 +297,7 @@ RMAPI float Vector2LengthSqr(RMVector2 v)
}
// Calculate two vectors dot product
RMAPI float Vector2DotProduct(RMVector2 v1, RMVector2 v2)
RMAPI float Vector2DotProduct(RLVector2 v1, RLVector2 v2)
{
float result = (v1.x*v2.x + v1.y*v2.y);
@@ -305,7 +305,7 @@ RMAPI float Vector2DotProduct(RMVector2 v1, RMVector2 v2)
}
// Calculate two vectors cross product
RMAPI float Vector2CrossProduct(RMVector2 v1, RMVector2 v2)
RMAPI float Vector2CrossProduct(RLVector2 v1, RLVector2 v2)
{
float result = (v1.x*v2.y - v1.y*v2.x);
@@ -313,7 +313,7 @@ RMAPI float Vector2CrossProduct(RMVector2 v1, RMVector2 v2)
}
// Calculate distance between two vectors
RMAPI float Vector2Distance(RMVector2 v1, RMVector2 v2)
RMAPI float Vector2Distance(RLVector2 v1, RLVector2 v2)
{
float result = sqrtf((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
@@ -321,7 +321,7 @@ RMAPI float Vector2Distance(RMVector2 v1, RMVector2 v2)
}
// Calculate square distance between two vectors
RMAPI float Vector2DistanceSqr(RMVector2 v1, RMVector2 v2)
RMAPI float Vector2DistanceSqr(RLVector2 v1, RLVector2 v2)
{
float result = ((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
@@ -331,7 +331,7 @@ RMAPI float Vector2DistanceSqr(RMVector2 v1, RMVector2 v2)
// Calculate the signed angle from v1 to v2, relative to the origin (0, 0)
// NOTE: Coordinate system convention: positive X right, positive Y down
// positive angles appear clockwise, and negative angles appear counterclockwise
RMAPI float Vector2Angle(RMVector2 v1, RMVector2 v2)
RMAPI float Vector2Angle(RLVector2 v1, RLVector2 v2)
{
float result = 0.0f;
@@ -346,7 +346,7 @@ RMAPI float Vector2Angle(RMVector2 v1, RMVector2 v2)
// Calculate angle defined by a two vectors line
// NOTE: Parameters need to be normalized
// Current implementation should be aligned with glm::angle
RMAPI float Vector2LineAngle(RMVector2 start, RMVector2 end)
RMAPI float Vector2LineAngle(RLVector2 start, RLVector2 end)
{
float result = 0.0f;
@@ -357,41 +357,41 @@ RMAPI float Vector2LineAngle(RMVector2 start, RMVector2 end)
}
// Scale vector (multiply by value)
RMAPI RMVector2 Vector2Scale(RMVector2 v, float scale)
RMAPI RLVector2 Vector2Scale(RLVector2 v, float scale)
{
RMVector2 result = { v.x*scale, v.y*scale };
RLVector2 result = { v.x*scale, v.y*scale };
return result;
}
// Multiply vector by vector
RMAPI RMVector2 Vector2Multiply(RMVector2 v1, RMVector2 v2)
RMAPI RLVector2 Vector2Multiply(RLVector2 v1, RLVector2 v2)
{
RMVector2 result = { v1.x*v2.x, v1.y*v2.y };
RLVector2 result = { v1.x*v2.x, v1.y*v2.y };
return result;
}
// Negate vector
RMAPI RMVector2 Vector2Negate(RMVector2 v)
RMAPI RLVector2 Vector2Negate(RLVector2 v)
{
RMVector2 result = { -v.x, -v.y };
RLVector2 result = { -v.x, -v.y };
return result;
}
// Divide vector by vector
RMAPI RMVector2 Vector2Divide(RMVector2 v1, RMVector2 v2)
RMAPI RLVector2 Vector2Divide(RLVector2 v1, RLVector2 v2)
{
RMVector2 result = { v1.x/v2.x, v1.y/v2.y };
RLVector2 result = { v1.x/v2.x, v1.y/v2.y };
return result;
}
// Normalize provided vector
RMAPI RMVector2 Vector2Normalize(RMVector2 v)
RMAPI RLVector2 Vector2Normalize(RLVector2 v)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
float length = sqrtf((v.x*v.x) + (v.y*v.y));
if (length > 0)
@@ -405,9 +405,9 @@ RMAPI RMVector2 Vector2Normalize(RMVector2 v)
}
// Transforms a Vector2 by a given Matrix
RMAPI RMVector2 Vector2Transform(RMVector2 v, Matrix mat)
RMAPI RLVector2 Vector2Transform(RLVector2 v, Matrix mat)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
float x = v.x;
float y = v.y;
@@ -420,9 +420,9 @@ RMAPI RMVector2 Vector2Transform(RMVector2 v, Matrix mat)
}
// Calculate linear interpolation between two vectors
RMAPI RMVector2 Vector2Lerp(RMVector2 v1, RMVector2 v2, float amount)
RMAPI RLVector2 Vector2Lerp(RLVector2 v1, RLVector2 v2, float amount)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
result.x = v1.x + amount*(v2.x - v1.x);
result.y = v1.y + amount*(v2.y - v1.y);
@@ -431,9 +431,9 @@ RMAPI RMVector2 Vector2Lerp(RMVector2 v1, RMVector2 v2, float amount)
}
// Calculate reflected vector to normal
RMAPI RMVector2 Vector2Reflect(RMVector2 v, RMVector2 normal)
RMAPI RLVector2 Vector2Reflect(RLVector2 v, RLVector2 normal)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
float dotProduct = (v.x*normal.x + v.y*normal.y); // Dot product
@@ -444,9 +444,9 @@ RMAPI RMVector2 Vector2Reflect(RMVector2 v, RMVector2 normal)
}
// Get min value for each pair of components
RMAPI RMVector2 Vector2Min(RMVector2 v1, RMVector2 v2)
RMAPI RLVector2 Vector2Min(RLVector2 v1, RLVector2 v2)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
result.x = fminf(v1.x, v2.x);
result.y = fminf(v1.y, v2.y);
@@ -455,9 +455,9 @@ RMAPI RMVector2 Vector2Min(RMVector2 v1, RMVector2 v2)
}
// Get max value for each pair of components
RMAPI RMVector2 Vector2Max(RMVector2 v1, RMVector2 v2)
RMAPI RLVector2 Vector2Max(RLVector2 v1, RLVector2 v2)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
result.x = fmaxf(v1.x, v2.x);
result.y = fmaxf(v1.y, v2.y);
@@ -466,9 +466,9 @@ RMAPI RMVector2 Vector2Max(RMVector2 v1, RMVector2 v2)
}
// Rotate vector by angle
RMAPI RMVector2 Vector2Rotate(RMVector2 v, float angle)
RMAPI RLVector2 Vector2Rotate(RLVector2 v, float angle)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
float cosres = cosf(angle);
float sinres = sinf(angle);
@@ -480,9 +480,9 @@ RMAPI RMVector2 Vector2Rotate(RMVector2 v, float angle)
}
// Move Vector towards target
RMAPI RMVector2 Vector2MoveTowards(RMVector2 v, RMVector2 target, float maxDistance)
RMAPI RLVector2 Vector2MoveTowards(RLVector2 v, RLVector2 target, float maxDistance)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
float dx = target.x - v.x;
float dy = target.y - v.y;
@@ -499,18 +499,18 @@ RMAPI RMVector2 Vector2MoveTowards(RMVector2 v, RMVector2 target, float maxDista
}
// Invert the given vector
RMAPI RMVector2 Vector2Invert(RMVector2 v)
RMAPI RLVector2 Vector2Invert(RLVector2 v)
{
RMVector2 result = { 1.0f/v.x, 1.0f/v.y };
RLVector2 result = { 1.0f/v.x, 1.0f/v.y };
return result;
}
// Clamp the components of the vector between
// min and max values specified by the given vectors
RMAPI RMVector2 Vector2Clamp(RMVector2 v, RMVector2 min, RMVector2 max)
RMAPI RLVector2 Vector2Clamp(RLVector2 v, RLVector2 min, RLVector2 max)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
result.x = fminf(max.x, fmaxf(min.x, v.x));
result.y = fminf(max.y, fmaxf(min.y, v.y));
@@ -519,9 +519,9 @@ RMAPI RMVector2 Vector2Clamp(RMVector2 v, RMVector2 min, RMVector2 max)
}
// Clamp the magnitude of the vector between two min and max values
RMAPI RMVector2 Vector2ClampValue(RMVector2 v, float min, float max)
RMAPI RLVector2 Vector2ClampValue(RLVector2 v, float min, float max)
{
RMVector2 result = v;
RLVector2 result = v;
float length = (v.x*v.x) + (v.y*v.y);
if (length > 0.0f)
@@ -546,7 +546,7 @@ RMAPI RMVector2 Vector2ClampValue(RMVector2 v, float min, float max)
}
// Check whether two given vectors are almost equal
RMAPI int Vector2Equals(RMVector2 p, RMVector2 q)
RMAPI int Vector2Equals(RLVector2 p, RLVector2 q)
{
#if !defined(EPSILON)
#define EPSILON 0.000001f
@@ -563,9 +563,9 @@ RMAPI int Vector2Equals(RMVector2 p, RMVector2 q)
// n: normalized normal vector of the interface of two optical media
// r: ratio of the refractive index of the medium from where the ray comes
// to the refractive index of the medium on the other side of the surface
RMAPI RMVector2 Vector2Refract(RMVector2 v, RMVector2 n, float r)
RMAPI RLVector2 Vector2Refract(RLVector2 v, RLVector2 n, float r)
{
RMVector2 result = { 0 };
RLVector2 result = { 0 };
float dot = v.x*n.x + v.y*n.y;
float d = 1.0f - r*r*(1.0f - dot*dot);