Browse Source

Clang-Tidy - bugprone-integer-division.

Yao Wei Tjong 姚伟忠 7 years ago
parent
commit
db2f6c9c33

+ 1 - 1
Source/Samples/07_Billboards/Billboards.cpp

@@ -174,7 +174,7 @@ void Billboards::CreateScene()
 
         float angle = 0.0f;
 
-        Vector3 position((i % 3) * 60.0f - 60.0f, 45.0f, (i / 3) * 60.0f - 60.0f);
+        Vector3 position((i % 3) * 60.0f - 60.0f, 45.0f, (i / 3.f) * 60.0f - 60.0f);
         Color color(((i + 1) & 1u) * 0.5f + 0.5f, (((i + 1) >> 1u) & 1u) * 0.5f + 0.5f, (((i + 1) >> 2u) & 1u) * 0.5f + 0.5f);
 
         lightNode->SetPosition(position);

+ 4 - 4
Source/Urho3D/Core/Profiler.cpp

@@ -112,9 +112,9 @@ void Profiler::PrintData(ProfilerBlock* block, String& output, unsigned depth, u
 
         if (!showTotal)
         {
-            float avg = block->intervalTime_ / block->intervalCount_ / 1000.0f;
+            float avg = (float)block->intervalTime_ / block->intervalCount_ / 1000.0f;
             float max = block->intervalMaxTime_ / 1000.0f;
-            float frame = block->intervalTime_ / (intervalFrames_ ? intervalFrames_ : 1) / 1000.0f;
+            float frame = (float)block->intervalTime_ / (intervalFrames_ ? intervalFrames_ : 1) / 1000.0f;
             float all = block->intervalTime_ / 1000.0f;
 
             sprintf(line, "%s %5u %8.3f %8.3f %8.3f %9.3f\n", indentedName, Min(block->intervalCount_, 99999U),
@@ -122,11 +122,11 @@ void Profiler::PrintData(ProfilerBlock* block, String& output, unsigned depth, u
         }
         else
         {
-            float avg = (block->frameCount_ ? block->frameTime_ / block->frameCount_ : 0.0f) / 1000.0f;
+            float avg = (block->frameCount_ ? (float)block->frameTime_ / block->frameCount_ : 0.0f) / 1000.0f;
             float max = block->frameMaxTime_ / 1000.0f;
             float all = block->frameTime_ / 1000.0f;
 
-            float totalAvg = block->totalTime_ / block->totalCount_ / 1000.0f;
+            float totalAvg = (float)block->totalTime_ / block->totalCount_ / 1000.0f;
             float totalMax = block->totalMaxTime_ / 1000.0f;
             float totalAll = block->totalTime_ / 1000.0f;
 

+ 2 - 2
Source/Urho3D/UI/Sprite.cpp

@@ -241,7 +241,7 @@ const Matrix3x4& Sprite::GetTransform() const
                 break;
 
             case HA_CENTER:
-                pos.x_ += (float)(parent_->GetSize().x_ / 2);
+                pos.x_ += (float)parent_->GetSize().x_ / 2.f;
                 break;
 
             case HA_RIGHT:
@@ -254,7 +254,7 @@ const Matrix3x4& Sprite::GetTransform() const
                 break;
 
             case VA_CENTER:
-                pos.y_ += (float)(parent_->GetSize().y_ / 2);
+                pos.y_ += (float)parent_->GetSize().y_ / 2.f;
                 break;
 
             case VA_BOTTOM:

+ 6 - 6
Source/Urho3D/Urho2D/SpriteSheet2D.cpp

@@ -182,8 +182,8 @@ bool SpriteSheet2D::EndLoadFromPListFile()
             offset.y_ = -sourceColorRect.top_;
 
             IntVector2 sourceSize = frameInfo["sourceSize"]->GetIntVector2();
-            hotSpot.x_ = ((float)offset.x_ + sourceSize.x_ / 2) / rectangle.Width();
-            hotSpot.y_ = 1.0f - ((float)offset.y_ + sourceSize.y_ / 2) / rectangle.Height();
+            hotSpot.x_ = (offset.x_ + sourceSize.x_ / 2.f) / rectangle.Width();
+            hotSpot.y_ = 1.0f - (offset.y_ + sourceSize.y_ / 2.f) / rectangle.Height();
         }
 
         DefineSprite(name, rectangle, hotSpot, offset);
@@ -254,8 +254,8 @@ bool SpriteSheet2D::EndLoadFromXMLFile()
             offset.y_ = subTextureElem.GetInt("frameY");
             int frameWidth = subTextureElem.GetInt("frameWidth");
             int frameHeight = subTextureElem.GetInt("frameHeight");
-            hotSpot.x_ = ((float)offset.x_ + frameWidth / 2) / width;
-            hotSpot.y_ = 1.0f - ((float)offset.y_ + frameHeight / 2) / height;
+            hotSpot.x_ = (offset.x_ + frameWidth / 2.f) / width;
+            hotSpot.y_ = 1.0f - (offset.y_ + frameHeight / 2.f) / height;
         }
 
         DefineSprite(name, rectangle, hotSpot, offset);
@@ -333,8 +333,8 @@ bool SpriteSheet2D::EndLoadFromJSONFile()
             offset.y_ = subTextureVal.Get("frameY").GetInt();
             int frameWidth = frameWidthVal.GetInt();
             int frameHeight = frameHeightVal.GetInt();
-            hotSpot.x_ = ((float)offset.x_ + frameWidth / 2) / width;
-            hotSpot.y_ = 1.0f - ((float)offset.y_ + frameHeight / 2) / height;
+            hotSpot.x_ = (offset.x_ + frameWidth / 2.f) / width;
+            hotSpot.y_ = 1.0f - (offset.y_ + frameHeight / 2.f) / height;
         }
 
         DefineSprite(name, rectangle, hotSpot, offset);