refactor(Core/Misc): sqrt/log/exp() to std::sqrt/log/exp() (#9792)

This commit is contained in:
Kitzunu
2022-02-09 11:59:30 +01:00
committed by GitHub
parent 65a1fbfd35
commit cf65cd6baf
15 changed files with 24 additions and 24 deletions
+1 -1
View File
@@ -41,7 +41,7 @@
[[nodiscard]] inline float getSlopeAngle(float startX, float startY, float startZ, float destX, float destY, float destZ) [[nodiscard]] inline float getSlopeAngle(float startX, float startY, float startZ, float destX, float destY, float destZ)
{ {
float floorDist = sqrt(pow(startY - destY, 2.0f) + pow(startX - destX, 2.0f)); float floorDist = std::sqrt(pow(startY - destY, 2.0f) + pow(startX - destX, 2.0f));
return atan(std::abs(destZ - startZ) / std::abs(floorDist)); return atan(std::abs(destZ - startZ) / std::abs(floorDist));
} }
+2 -2
View File
@@ -664,7 +664,7 @@ uint32 ArenaTeam::GetPoints(uint32 memberRating)
points = 344; points = 344;
} }
else else
points = 1511.26f / (1.0f + 1639.28f * exp(-0.00412f * (float)rating)); points = 1511.26f / (1.0f + 1639.28f * std::exp(-0.00412f * (float)rating));
// Type penalties for teams < 5v5 // Type penalties for teams < 5v5
if (Type == ARENA_TEAM_2v2) if (Type == ARENA_TEAM_2v2)
@@ -713,7 +713,7 @@ float ArenaTeam::GetChanceAgainst(uint32 ownRating, uint32 opponentRating)
{ {
// Returns the chance to win against a team with the given rating, used in the rating adjustment calculation // Returns the chance to win against a team with the given rating, used in the rating adjustment calculation
// ELO system // ELO system
return 1.0f / (1.0f + exp(log(10.0f) * (float)((float)opponentRating - (float)ownRating) / 650.0f)); return 1.0f / (1.0f + (std::exp(std::log(10.0f) * (float)((float)opponentRating - (float)ownRating) / 650.0f)));
} }
int32 ArenaTeam::GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won /*, float& confidence_factor*/) int32 ArenaTeam::GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won /*, float& confidence_factor*/)
@@ -808,7 +808,7 @@ GraveyardStruct const* BattlegroundSA::GetClosestGraveyard(Player* player)
continue; continue;
} }
float dist = sqrt(pow(ret->x - x, 2) * pow(ret->y - y, 2)); float dist = std::sqrt(pow(ret->x - x, 2) * pow(ret->y - y, 2));
if (dist < mindist) if (dist < mindist)
{ {
mindist = dist; mindist = dist;
+1 -1
View File
@@ -648,7 +648,7 @@ G3D::Vector3 TranslateLocation(G3D::Vector4 const* DBCPosition, G3D::Vector3 con
float x = basePosition->x + splineVector->x; float x = basePosition->x + splineVector->x;
float y = basePosition->y + splineVector->y; float y = basePosition->y + splineVector->y;
float z = basePosition->z + splineVector->z; float z = basePosition->z + splineVector->z;
float const distance = sqrt((x * x) + (y * y)); float const distance = std::sqrt((x * x) + (y * y));
float angle = std::atan2(x, y) - DBCPosition->w; float angle = std::atan2(x, y) - DBCPosition->w;
if (angle < 0) if (angle < 0)
@@ -2088,7 +2088,7 @@ bool GameObject::IsInRange(float x, float y, float z, float radius) const
float dx = x - GetPositionX(); float dx = x - GetPositionX();
float dy = y - GetPositionY(); float dy = y - GetPositionY();
float dz = z - GetPositionZ(); float dz = z - GetPositionZ();
float dist = sqrt(dx * dx + dy * dy); float dist = std::sqrt(dx * dx + dy * dy);
//! Check if the distance between the 2 objects is 0, can happen if both objects are on the same position. //! Check if the distance between the 2 objects is 0, can happen if both objects are on the same position.
//! The code below this check wont crash if dist is 0 because 0/0 in float operations is valid, and returns infinite //! The code below this check wont crash if dist is 0 because 0/0 in float operations is valid, and returns infinite
if (G3D::fuzzyEq(dist, 0.0f)) if (G3D::fuzzyEq(dist, 0.0f))
+1 -1
View File
@@ -1481,7 +1481,7 @@ bool WorldObject::IsInBetween(const WorldObject* obj1, const WorldObject* obj2,
float A = (obj2->GetPositionY() - obj1->GetPositionY()) / (obj2->GetPositionX() - obj1->GetPositionX()); float A = (obj2->GetPositionY() - obj1->GetPositionY()) / (obj2->GetPositionX() - obj1->GetPositionX());
float B = -1; float B = -1;
float C = obj1->GetPositionY() - A * obj1->GetPositionX(); float C = obj1->GetPositionY() - A * obj1->GetPositionX();
float dist = std::fabs(A * GetPositionX() + B * GetPositionY() + C) / sqrt(A * A + B * B); float dist = std::fabs(A * GetPositionX() + B * GetPositionY() + C) / std::sqrt(A * A + B * B);
return dist <= size; return dist <= size;
} }
+1 -1
View File
@@ -918,7 +918,7 @@ void Player::UpdateManaRegen()
float Intellect = GetStat(STAT_INTELLECT); float Intellect = GetStat(STAT_INTELLECT);
// Mana regen from spirit and intellect // Mana regen from spirit and intellect
float power_regen = sqrt(Intellect) * OCTRegenMPPerSpirit(); float power_regen = std::sqrt(Intellect) * OCTRegenMPPerSpirit();
// Apply PCT bonus from SPELL_AURA_MOD_POWER_REGEN_PERCENT aura on spirit base regen // Apply PCT bonus from SPELL_AURA_MOD_POWER_REGEN_PERCENT aura on spirit base regen
power_regen *= GetTotalAuraMultiplierByMiscValue(SPELL_AURA_MOD_POWER_REGEN_PERCENT, POWER_MANA); power_regen *= GetTotalAuraMultiplierByMiscValue(SPELL_AURA_MOD_POWER_REGEN_PERCENT, POWER_MANA);
+5 -5
View File
@@ -283,22 +283,22 @@ void TransportMgr::GeneratePath(GameObjectTemplate const* goInfo, TransportTempl
if (keyFrames[i].DistSinceStop < keyFrames[i].DistUntilStop) // is still accelerating if (keyFrames[i].DistSinceStop < keyFrames[i].DistUntilStop) // is still accelerating
{ {
// calculate accel+brake time for this short segment // calculate accel+brake time for this short segment
float segment_time = 2.0f * sqrt((keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / accel); float segment_time = 2.0f * std::sqrt((keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / accel);
// substract acceleration time // substract acceleration time
keyFrames[i].TimeTo = segment_time - sqrt(2 * keyFrames[i].DistSinceStop / accel); keyFrames[i].TimeTo = segment_time - std::sqrt(2 * keyFrames[i].DistSinceStop / accel);
} }
else // slowing down else // slowing down
keyFrames[i].TimeTo = sqrt(2 * keyFrames[i].DistUntilStop / accel); keyFrames[i].TimeTo = std::sqrt(2 * keyFrames[i].DistUntilStop / accel);
} }
else if (keyFrames[i].DistSinceStop < accel_dist) // still accelerating (but will reach full speed) else if (keyFrames[i].DistSinceStop < accel_dist) // still accelerating (but will reach full speed)
{ {
// calculate accel + cruise + brake time for this long segment // calculate accel + cruise + brake time for this long segment
float segment_time = (keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / speed + (speed / accel); float segment_time = (keyFrames[i].DistUntilStop + keyFrames[i].DistSinceStop) / speed + (speed / accel);
// substract acceleration time // substract acceleration time
keyFrames[i].TimeTo = segment_time - sqrt(2 * keyFrames[i].DistSinceStop / accel); keyFrames[i].TimeTo = segment_time - std::sqrt(2 * keyFrames[i].DistSinceStop / accel);
} }
else if (keyFrames[i].DistUntilStop < accel_dist) // already slowing down (but reached full speed) else if (keyFrames[i].DistUntilStop < accel_dist) // already slowing down (but reached full speed)
keyFrames[i].TimeTo = sqrt(2 * keyFrames[i].DistUntilStop / accel); keyFrames[i].TimeTo = std::sqrt(2 * keyFrames[i].DistUntilStop / accel);
else // at full speed else // at full speed
keyFrames[i].TimeTo = (keyFrames[i].DistUntilStop / speed) + (0.5f * speed / accel); keyFrames[i].TimeTo = (keyFrames[i].DistUntilStop / speed) + (0.5f * speed / accel);
} }
@@ -105,7 +105,7 @@ class PathGenerator
dx = _pathPoints[0].x - _startPosition.x; dx = _pathPoints[0].x - _startPosition.x;
dy = _pathPoints[0].y - _startPosition.y; dy = _pathPoints[0].y - _startPosition.y;
dz = _pathPoints[0].z - _startPosition.z; dz = _pathPoints[0].z - _startPosition.z;
len += sqrt( dx * dx + dy * dy + dz * dz ); len += std::sqrt( dx * dx + dy * dy + dz * dz );
} }
else else
{ {
@@ -117,7 +117,7 @@ class PathGenerator
dx = _pathPoints[i].x - _pathPoints[i - 1].x; dx = _pathPoints[i].x - _pathPoints[i - 1].x;
dy = _pathPoints[i].y - _pathPoints[i - 1].y; dy = _pathPoints[i].y - _pathPoints[i - 1].y;
dz = _pathPoints[i].z - _pathPoints[i - 1].z; dz = _pathPoints[i].z - _pathPoints[i - 1].z;
len += sqrt( dx * dx + dy * dy + dz * dz ); len += std::sqrt( dx * dx + dy * dy + dz * dz );
} }
return len; return len;
} }
@@ -153,7 +153,7 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
for (; itrNext != finalPath.end(); ++itr, ++itrNext) for (; itrNext != finalPath.end(); ++itr, ++itrNext)
{ {
distDiff = sqrt(((*itr).x - (*itrNext).x) * ((*itr).x - (*itrNext).x) + ((*itr).y - (*itrNext).y) * ((*itr).y - (*itrNext).y)); distDiff = std::sqrt(((*itr).x - (*itrNext).x) * ((*itr).x - (*itrNext).x) + ((*itr).y - (*itrNext).y) * ((*itr).y - (*itrNext).y));
zDiff = std::fabs((*itr).z - (*itrNext).z); zDiff = std::fabs((*itr).z - (*itrNext).z);
// Xinef: tree climbing, cut as much as we can // Xinef: tree climbing, cut as much as we can
+3 -3
View File
@@ -1758,7 +1758,7 @@ void Spell::SelectImplicitTrajTargets(SpellEffIndex effIndex, SpellImplicitTarge
float sqrt1 = b * b + 4 * a * height; float sqrt1 = b * b + 4 * a * height;
if (sqrt1 > 0) if (sqrt1 > 0)
{ {
sqrt1 = sqrt(sqrt1); sqrt1 = std::sqrt(sqrt1);
dist = (sqrt1 - b) / (2 * a); dist = (sqrt1 - b) / (2 * a);
CHECK_DIST; CHECK_DIST;
} }
@@ -1767,7 +1767,7 @@ void Spell::SelectImplicitTrajTargets(SpellEffIndex effIndex, SpellImplicitTarge
float sqrt2 = b * b + 4 * a * height; float sqrt2 = b * b + 4 * a * height;
if (sqrt2 > 0) if (sqrt2 > 0)
{ {
sqrt2 = sqrt(sqrt2); sqrt2 = std::sqrt(sqrt2);
dist = (sqrt2 - b) / (2 * a); dist = (sqrt2 - b) / (2 * a);
CHECK_DIST; CHECK_DIST;
@@ -1796,7 +1796,7 @@ void Spell::SelectImplicitTrajTargets(SpellEffIndex effIndex, SpellImplicitTarge
LOG_ERROR("spells", "Initial {} {} {} {} {}", x, y, z, distSq, sizeSq); LOG_ERROR("spells", "Initial {} {} {} {} {}", x, y, z, distSq, sizeSq);
if (distSq > sizeSq) if (distSq > sizeSq)
{ {
float factor = 1 - sqrt(sizeSq / distSq); float factor = 1 - std::sqrt(sizeSq / distSq);
x += factor * ((*itr)->GetPositionX() - x); x += factor * ((*itr)->GetPositionX() - x);
y += factor * ((*itr)->GetPositionY() - y); y += factor * ((*itr)->GetPositionY() - y);
z += factor * ((*itr)->GetPositionZ() - z); z += factor * ((*itr)->GetPositionZ() - z);
@@ -116,7 +116,7 @@ public:
float dist(float xa, float ya, float xb, float yb) // auxiliary method for distance float dist(float xa, float ya, float xb, float yb) // auxiliary method for distance
{ {
return sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); return std::sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
} }
void Reset() override void Reset() override
@@ -246,7 +246,7 @@ struct boss_twin_valkyrAI : public ScriptedAI
if (!victim || !victim->IsInWorld()) if (!victim || !victim->IsInWorld())
return; return;
float allowedDist = sqrt(MELEE_RANGE * MELEE_RANGE + 6.0f * 6.0f); float allowedDist = std::sqrt(MELEE_RANGE * MELEE_RANGE + 6.0f * 6.0f);
if (!me->IsWithinMeleeRange(victim, allowedDist)) if (!me->IsWithinMeleeRange(victim, allowedDist))
return; return;
+1 -1
View File
@@ -170,7 +170,7 @@ Vector3 Utils::GetLiquidVert(const IDefinition& def, Vector3 basePosition, float
float Utils::Distance( float x, float y ) float Utils::Distance( float x, float y )
{ {
return sqrt(x * x + y * y); return std::sqrt(x * x + y * y);
} }
std::string Utils::Replace( std::string str, const std::string& oldStr, const std::string& newStr ) std::string Utils::Replace( std::string str, const std::string& oldStr, const std::string& newStr )
+2 -2
View File
@@ -103,7 +103,7 @@ public:
[[nodiscard]] float length() const [[nodiscard]] float length() const
{ {
return sqrt(x * x + y * y + z * z); return std::sqrt(x * x + y * y + z * z);
} }
Vec3D& normalize() Vec3D& normalize()
@@ -216,7 +216,7 @@ public:
[[nodiscard]] float length() const [[nodiscard]] float length() const
{ {
return sqrt(x * x + y * y); return std::sqrt(x * x + y * y);
} }
Vec2D& normalize() Vec2D& normalize()