Browse Source

Some formatting review

Ray 6 years ago
parent
commit
6f371dab08
1 changed files with 23 additions and 19 deletions
  1. 23 19
      src/shapes.c

+ 23 - 19
src/shapes.c

@@ -185,8 +185,8 @@ 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) 
@@ -308,12 +308,12 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end
     // Hide the cap lines when the circle is full
     // Hide the cap lines when the circle is full
     bool showCapLines = true;
     bool showCapLines = true;
     int limit = 2*(segments + 2);
     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();
     if (rlCheckBufferLimit(limit)) rlglDraw();
     
     
     rlBegin(RL_LINES);
     rlBegin(RL_LINES);
-        if(showCapLines)
+        if (showCapLines)
         {
         {
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlVertex2f(center.x, center.y);
             rlVertex2f(center.x, center.y);
@@ -330,7 +330,7 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end
             angle += stepLength;
             angle += stepLength;
         }
         }
         
         
-        if(showCapLines)
+        if (showCapLines)
         {
         {
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlVertex2f(center.x, center.y);
             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)
 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)
     // Function expects (outerRadius > innerRadius)
-    if(outerRadius < innerRadius)
+    if (outerRadius < innerRadius)
     {
     {
         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)
@@ -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
         // Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
         #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;
@@ -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)
 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)
     // Function expects (outerRadius > innerRadius)
-    if(outerRadius < innerRadius)
+    if (outerRadius < innerRadius)
     {
     {
         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)
@@ -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
         // Calculate how many segments we need to draw a smooth circle, taken from https://stackoverflow.com/a/2244088
         #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;
@@ -522,12 +526,12 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
     
     
     bool showCapLines = true;
     bool showCapLines = true;
     int limit = 4*(segments + 1);
     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();
     if (rlCheckBufferLimit(limit)) rlglDraw();
     
     
     rlBegin(RL_LINES);
     rlBegin(RL_LINES);
-        if(showCapLines)
+        if (showCapLines)
         {
         {
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius);
             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;
             angle += stepLength;
         }
         }
         
         
-        if(showCapLines)
+        if (showCapLines)
         {
         {
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius);
             rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius);