aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-03-29 19:43:27 +0100
committerRay <raysan5@gmail.com>2019-03-29 19:43:27 +0100
commit6f371dab0807ccc81038b3eccfb9c6090ec07d16 (patch)
tree91d83451be2c58fcadea67dc9b61f72aa100d5e9 /src
parentafab8b36ab9c7e199cbffe639b64fbd87c41bc05 (diff)
downloadraylib-6f371dab0807ccc81038b3eccfb9c6090ec07d16.tar.gz
raylib-6f371dab0807ccc81038b3eccfb9c6090ec07d16.zip
Some formatting review
Diffstat (limited to 'src')
-rw-r--r--src/shapes.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/shapes.c b/src/shapes.c
index 7e8c0f4b..8c1eb1f0 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -185,8 +185,8 @@ void DrawCircle(int centerX, int centerY, float radius, Color color)
// Draw a piece of a circle
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)
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)
{
- 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)
if (endAngle < startAngle)
@@ -308,12 +308,12 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end
// Hide the cap lines when the circle is full
bool showCapLines = true;
int limit = 2*(segments + 2);
- if((endAngle - startAngle) % 360 == 0) { limit = 2*segments; showCapLines = false; }
+ if ((endAngle - startAngle)%360 == 0) { limit = 2*segments; showCapLines = false; }
if (rlCheckBufferLimit(limit)) rlglDraw();
rlBegin(RL_LINES);
- if(showCapLines)
+ if (showCapLines)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(center.x, center.y);
@@ -330,7 +330,7 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end
angle += stepLength;
}
- if(showCapLines)
+ if (showCapLines)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(center.x, center.y);
@@ -384,15 +384,16 @@ void DrawCircleLines(int centerX, int centerY, float radius, Color color)
void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color)
{
- if(startAngle == endAngle) return;
+ if (startAngle == endAngle) return;
// Function expects (outerRadius > innerRadius)
- if(outerRadius < innerRadius)
+ if (outerRadius < innerRadius)
{
float tmp = outerRadius;
outerRadius = innerRadius;
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)
@@ -408,8 +409,9 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
{
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
#ifndef CIRCLE_ERROR_RATE
- #define CIRCLE_ERROR_RATE 0.5f
+ #define CIRCLE_ERROR_RATE 0.5f
#endif
+
// Calculate the maximum angle between segments based on the error rate.
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
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
- if(innerRadius == 0)
+ if (innerRadius <= 0.0f)
{
DrawCircleSector(center, outerRadius, startAngle, endAngle, segments, color);
return;
@@ -478,15 +480,16 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color)
{
- if(startAngle == endAngle) return;
+ if (startAngle == endAngle) return;
// Function expects (outerRadius > innerRadius)
- if(outerRadius < innerRadius)
+ if (outerRadius < innerRadius)
{
float tmp = outerRadius;
outerRadius = innerRadius;
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)
@@ -502,8 +505,9 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
{
// Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
#ifndef CIRCLE_ERROR_RATE
- #define CIRCLE_ERROR_RATE 0.5f
+ #define CIRCLE_ERROR_RATE 0.5f
#endif
+
// Calculate the maximum angle between segments based on the error rate.
float th = acosf(2*powf(1 - CIRCLE_ERROR_RATE/outerRadius, 2) - 1);
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(innerRadius == 0)
+ if (innerRadius <= 0.0f)
{
DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, color);
return;
@@ -522,12 +526,12 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
bool showCapLines = true;
int limit = 4*(segments + 1);
- if((endAngle - startAngle) % 360 == 0) { limit = 4*segments; showCapLines = false; }
+ if ((endAngle - startAngle)%360 == 0) { limit = 4*segments; showCapLines = false; }
if (rlCheckBufferLimit(limit)) rlglDraw();
rlBegin(RL_LINES);
- if(showCapLines)
+ if (showCapLines)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius);
@@ -547,7 +551,7 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
angle += stepLength;
}
- if(showCapLines)
+ if (showCapLines)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius);