Follow raylib style

This commit is contained in:
Octave Crespel 2023-12-01 17:21:09 +01:00
parent d0b19199b3
commit fb75edb9b4

View File

@ -1546,16 +1546,20 @@ void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, fl
// Draw spline: linear, minimum 2 points // Draw spline: linear, minimum 2 points
void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color) void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
{ {
if (pointCount < 2) { if (pointCount < 2)
{
return; return;
} }
Vector2 prevNormal = (Vector2){-(points[1].y - points[0].y), (points[1].x - points[0].x)}; Vector2 prevNormal = (Vector2){-(points[1].y - points[0].y), (points[1].x - points[0].x)};
float prevLength = sqrtf(prevNormal.x*prevNormal.x + prevNormal.y*prevNormal.y); float prevLength = sqrtf(prevNormal.x*prevNormal.x + prevNormal.y*prevNormal.y);
if (prevLength > 0.0f) { if (prevLength > 0.0f)
{
prevNormal.x /= prevLength; prevNormal.x /= prevLength;
prevNormal.y /= prevLength; prevNormal.y /= prevLength;
} else { }
else
{
prevNormal.x = 0.0f; prevNormal.x = 0.0f;
prevNormal.y = 0.0f; prevNormal.y = 0.0f;
} }
@ -1566,36 +1570,48 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
{ {
Vector2 normal = {0}; Vector2 normal = {0};
if (i < pointCount - 2) { if (i < pointCount - 2)
{
normal = (Vector2){-(points[i+2].y - points[i+1].y), (points[i+2].x - points[i+1].x)}; normal = (Vector2){-(points[i+2].y - points[i+1].y), (points[i+2].x - points[i+1].x)};
float normalLength = sqrtf(normal.x*normal.x + normal.y*normal.y); float normalLength = sqrtf(normal.x*normal.x + normal.y*normal.y);
if (normalLength > 0.0f) { if (normalLength > 0.0f)
{
normal.x /= normalLength; normal.x /= normalLength;
normal.y /= normalLength; normal.y /= normalLength;
} else { }
else
{
normal.x = 0.0f; normal.x = 0.0f;
normal.y = 0.0f; normal.y = 0.0f;
} }
} else { }
else
{
normal = prevNormal; normal = prevNormal;
} }
Vector2 radius = {prevNormal.x + normal.x, prevNormal.y + normal.y}; Vector2 radius = {prevNormal.x + normal.x, prevNormal.y + normal.y};
float radiusLength = sqrtf(radius.x*radius.x + radius.y*radius.y); float radiusLength = sqrtf(radius.x*radius.x + radius.y*radius.y);
if (radiusLength > 0.0f) { if (radiusLength > 0.0f)
{
radius.x /= radiusLength; radius.x /= radiusLength;
radius.y /= radiusLength; radius.y /= radiusLength;
} else { }
else
{
radius.x = 0.0f; radius.x = 0.0f;
radius.y = 0.0f; radius.y = 0.0f;
} }
float cosTheta = radius.x * normal.x + radius.y * normal.y; float cosTheta = radius.x * normal.x + radius.y * normal.y;
if (cosTheta != 0.0f) { if (cosTheta != 0.0f)
{
radius.x *= thick * .5f / cosTheta; radius.x *= thick * .5f / cosTheta;
radius.y *= thick * .5f / cosTheta; radius.y *= thick * .5f / cosTheta;
} else { }
else
{
radius.x = 0.0f; radius.x = 0.0f;
radius.y = 0.0f; radius.y = 0.0f;
} }