mirror of
https://github.com/raysan5/raylib.git
synced 2025-11-17 07:41:14 +00:00
Some formatting review
This commit is contained in:
16
src/shapes.c
16
src/shapes.c
@@ -185,7 +185,7 @@ void DrawCircle(int centerX, int centerY, float radius, Color color)
|
|||||||
// Draw a piece of a circle
|
// Draw a piece of a circle
|
||||||
void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
|
void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
|
||||||
{
|
{
|
||||||
if(radius == 0) return; // Check this or we'll get a div by zero error otherwise
|
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero
|
||||||
|
|
||||||
// Function expects (endAngle > startAngle)
|
// Function expects (endAngle > startAngle)
|
||||||
if (endAngle < startAngle)
|
if (endAngle < startAngle)
|
||||||
@@ -277,7 +277,7 @@ void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle
|
|||||||
|
|
||||||
void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
|
void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
|
||||||
{
|
{
|
||||||
if(radius == 0) return; // Check this or we'll get a div by zero error otherwise
|
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero issue
|
||||||
|
|
||||||
// Function expects (endAngle > startAngle)
|
// Function expects (endAngle > startAngle)
|
||||||
if (endAngle < startAngle)
|
if (endAngle < startAngle)
|
||||||
@@ -392,7 +392,8 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
|
|||||||
float tmp = outerRadius;
|
float tmp = outerRadius;
|
||||||
outerRadius = innerRadius;
|
outerRadius = innerRadius;
|
||||||
innerRadius = tmp;
|
innerRadius = tmp;
|
||||||
if(outerRadius == 0) return; // Check this or we'll get a div by zero error otherwise
|
|
||||||
|
if (outerRadius <= 0.0f) outerRadius = 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function expects (endAngle > startAngle)
|
// Function expects (endAngle > startAngle)
|
||||||
@@ -410,6 +411,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
|
|||||||
#ifndef CIRCLE_ERROR_RATE
|
#ifndef CIRCLE_ERROR_RATE
|
||||||
#define CIRCLE_ERROR_RATE 0.5f
|
#define CIRCLE_ERROR_RATE 0.5f
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Calculate the maximum angle between segments based on the error rate.
|
// Calculate the maximum angle between segments based on the error rate.
|
||||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
|
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
|
||||||
segments = (endAngle - startAngle)*ceilf(2*PI/th)/360;
|
segments = (endAngle - startAngle)*ceilf(2*PI/th)/360;
|
||||||
@@ -418,7 +420,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Not a ring
|
// Not a ring
|
||||||
if(innerRadius == 0)
|
if (innerRadius <= 0.0f)
|
||||||
{
|
{
|
||||||
DrawCircleSector(center, outerRadius, startAngle, endAngle, segments, color);
|
DrawCircleSector(center, outerRadius, startAngle, endAngle, segments, color);
|
||||||
return;
|
return;
|
||||||
@@ -486,7 +488,8 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
|
|||||||
float tmp = outerRadius;
|
float tmp = outerRadius;
|
||||||
outerRadius = innerRadius;
|
outerRadius = innerRadius;
|
||||||
innerRadius = tmp;
|
innerRadius = tmp;
|
||||||
if(outerRadius == 0) return; // Check this or we'll get a div by zero error otherwise
|
|
||||||
|
if (outerRadius <= 0.0f) outerRadius = 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function expects (endAngle > startAngle)
|
// Function expects (endAngle > startAngle)
|
||||||
@@ -504,6 +507,7 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
|
|||||||
#ifndef CIRCLE_ERROR_RATE
|
#ifndef CIRCLE_ERROR_RATE
|
||||||
#define CIRCLE_ERROR_RATE 0.5f
|
#define CIRCLE_ERROR_RATE 0.5f
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Calculate the maximum angle between segments based on the error rate.
|
// Calculate the maximum angle between segments based on the error rate.
|
||||||
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
|
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
|
||||||
segments = (endAngle - startAngle)*ceilf(2*PI/th)/360;
|
segments = (endAngle - startAngle)*ceilf(2*PI/th)/360;
|
||||||
@@ -511,7 +515,7 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
|
|||||||
if (segments <= 0) segments = 4;
|
if (segments <= 0) segments = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(innerRadius == 0)
|
if (innerRadius <= 0.0f)
|
||||||
{
|
{
|
||||||
DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, color);
|
DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, color);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user