Merge MathHelper and FloatMath

Requires  space-wizards/RobustToolbox#1234
This commit is contained in:
Visne
2020-08-16 14:54:52 +02:00
parent 745f028b89
commit 0b448b500d
18 changed files with 27 additions and 27 deletions

View File

@@ -106,13 +106,13 @@ namespace Content.Client.Chat
}
// Lerp to our new vertical offset if it's been modified.
if (FloatMath.CloseTo(_verticalOffsetAchieved - VerticalOffset, 0, 0.1))
if (MathHelper.CloseTo(_verticalOffsetAchieved - VerticalOffset, 0, 0.1))
{
_verticalOffsetAchieved = VerticalOffset;
}
else
{
_verticalOffsetAchieved = FloatMath.Lerp(_verticalOffsetAchieved, VerticalOffset, 10 * args.DeltaSeconds);
_verticalOffsetAchieved = MathHelper.Lerp(_verticalOffsetAchieved, VerticalOffset, 10 * args.DeltaSeconds);
}
var worldPos = _senderEntity.Transform.WorldPosition;
@@ -122,7 +122,7 @@ namespace Content.Client.Chat
var screenPos = lowerCenter - (Width / 2, ContentHeight + _verticalOffsetAchieved);
LayoutContainer.SetPosition(this, screenPos);
var height = FloatMath.Clamp(lowerCenter.Y - screenPos.Y, 0, ContentHeight);
var height = MathHelper.Clamp(lowerCenter.Y - screenPos.Y, 0, ContentHeight);
LayoutContainer.SetSize(this, (Size.X, height));
}

View File

@@ -113,12 +113,12 @@ namespace Content.Client.GameObjects.Components.Disposal
if (normalized <= leftSideSize)
{
normalized /= leftSideSize; // Adjust range to 0.0 to 1.0
finalHue = FloatMath.Lerp(leftHue, middleHue, normalized);
finalHue = MathHelper.Lerp(leftHue, middleHue, normalized);
}
else
{
normalized = (normalized - leftSideSize) / rightSideSize; // Adjust range to 0.0 to 1.0.
finalHue = FloatMath.Lerp(middleHue, rightHue, normalized);
finalHue = MathHelper.Lerp(middleHue, rightHue, normalized);
}
// Check if null first to avoid repeatedly creating this.

View File

@@ -78,7 +78,7 @@ namespace Content.Client.GameObjects.Components
int level;
if (FloatMath.CloseTo(charge, 0))
if (MathHelper.CloseTo(charge, 0))
{
level = 0;
}

View File

@@ -243,7 +243,7 @@ namespace Content.Client.GameObjects.Components
if (int.TryParse(ev.Text, out var result))
{
result = FloatMath.Clamp(result, 0, byte.MaxValue);
result = MathHelper.Clamp(result, 0, byte.MaxValue);
_ignoreEvents = true;
_colorValue = (byte) result;

View File

@@ -87,7 +87,7 @@ namespace Content.Client.GameObjects.Components.Mobs
// Continually restore camera to 0.
var normalized = _currentKick.Normalized;
_lastKickTime += frameTime;
var restoreRate = FloatMath.Lerp(RestoreRateMin, RestoreRateMax, Math.Min(1, _lastKickTime/RestoreRateRamp));
var restoreRate = MathHelper.Lerp(RestoreRateMin, RestoreRateMax, Math.Min(1, _lastKickTime/RestoreRateRamp));
var restore = normalized * restoreRate * frameTime;
var (x, y) = _currentKick - restore;
if (Math.Sign(x) != Math.Sign(_currentKick.X))

View File

@@ -152,7 +152,7 @@ namespace Content.Client.GameObjects.Components.Mobs
var progress = (_gameTiming.CurTime - start).TotalSeconds / length;
var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5);
cooldownGraphic.Progress = FloatMath.Clamp((float)ratio, -1, 1);
cooldownGraphic.Progress = MathHelper.Clamp((float)ratio, -1, 1);
cooldownGraphic.Visible = ratio > -1f;
}
}

View File

@@ -86,12 +86,12 @@ namespace Content.Client.GameObjects.Components.Power
if (normalizedCharge <= leftSideSize)
{
normalizedCharge /= leftSideSize; // Adjust range to 0.0 to 1.0
finalHue = FloatMath.Lerp(leftHue, middleHue, normalizedCharge);
finalHue = MathHelper.Lerp(leftHue, middleHue, normalizedCharge);
}
else
{
normalizedCharge = (normalizedCharge - leftSideSize) / rightSideSize; // Adjust range to 0.0 to 1.0.
finalHue = FloatMath.Lerp(middleHue, rightHue, normalizedCharge);
finalHue = MathHelper.Lerp(middleHue, rightHue, normalizedCharge);
}
// Check if null first to avoid repeatedly creating this.

View File

@@ -141,7 +141,7 @@ namespace Content.Client.GameObjects.Components.Weapons
const float xOffset = 0.0f;
// Overkill but easy to adjust if you want to mess around with the design
var result = (float) FloatMath.Clamp(slope * (float) Math.Pow(ratio - xOffset, exponent) + yOffset, 0.0, 1.0);
var result = (float) MathHelper.Clamp(slope * (float) Math.Pow(ratio - xOffset, exponent) + yOffset, 0.0, 1.0);
DebugTools.Assert(!float.IsNaN(result));
return result;
}

View File

@@ -41,7 +41,7 @@ namespace Content.Client.UserInterface
}
else
{
var alpha = FloatMath.Clamp(0.5f * lerp, 0f, 0.5f);
var alpha = MathHelper.Clamp(0.5f * lerp, 0f, 0.5f);
color = new Color(1f, 1f, 1f, alpha);
}

View File

@@ -107,7 +107,7 @@ namespace Content.Client.UserInterface
var progress = (_gameTiming.CurTime - start).TotalSeconds / length;
var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5);
cooldownDisplay.Progress = FloatMath.Clamp((float)ratio, -1, 1);
cooldownDisplay.Progress = MathHelper.Clamp((float)ratio, -1, 1);
if (ratio > -1f)
{

View File

@@ -17,7 +17,7 @@ namespace Content.Server.AI.Utility.Considerations
var modificationFactor = 1.0f - 1.0f / considerationsCount;
var makeUpValue = (1.0f - score) * modificationFactor;
var adjustedScore = score + makeUpValue * score;
return FloatMath.Clamp(adjustedScore, 0.0f, 1.0f);
return MathHelper.Clamp(adjustedScore, 0.0f, 1.0f);
}
[Pure]
@@ -59,7 +59,7 @@ namespace Content.Server.AI.Utility.Considerations
[Pure]
private static float LogisticCurve(float x, float slope, float exponent, float yOffset, float xOffset)
{
return FloatMath.Clamp(
return MathHelper.Clamp(
exponent * (1 / (1 + (float) Math.Pow(Math.Log(1000) * slope, -1 * x + xOffset))) + yOffset, 0.0f, 1.0f);
}
@@ -77,7 +77,7 @@ namespace Content.Server.AI.Utility.Considerations
[Pure]
private static float QuadraticCurve(float x, float slope, float exponent, float yOffset, float xOffset)
{
return FloatMath.Clamp(slope * (float) Math.Pow(x - xOffset, exponent) + yOffset, 0.0f, 1.0f);
return MathHelper.Clamp(slope * (float) Math.Pow(x - xOffset, exponent) + yOffset, 0.0f, 1.0f);
}
public Func<float> QuadraticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset)

View File

@@ -53,14 +53,14 @@ namespace Content.Server.Atmos
{
if (throwTarget != GridCoordinates.InvalidGrid)
{
var moveForce = maxForce * FloatMath.Clamp(moveProb, 0, 100) / 150f;
var moveForce = maxForce * MathHelper.Clamp(moveProb, 0, 100) / 150f;
var pos = ((throwTarget.Position - transform.GridPosition.Position).Normalized + direction.ToVec()).Normalized;
LinearVelocity = pos * moveForce;
}
else
{
var moveForce = MathF.Min(maxForce * FloatMath.Clamp(moveProb, 0, 100) / 2500f, 20f);
var moveForce = MathF.Min(maxForce * MathHelper.Clamp(moveProb, 0, 100) / 2500f, 20f);
LinearVelocity = direction.ToVec() * moveForce;
}

View File

@@ -171,7 +171,7 @@ namespace Content.Server.Atmos
{
if(_soundCooldown == 0)
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Effects/space_wind.ogg",
GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(FloatMath.Clamp(PressureDifference / 10, 10, 100)));
GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(PressureDifference / 10, 10, 100)));
}
@@ -1021,7 +1021,7 @@ namespace Content.Server.Atmos
private void HandleDecompressionFloorRip(float sum)
{
var chance = FloatMath.Clamp(sum / 500, 0.005f, 0.5f);
var chance = MathHelper.Clamp(sum / 500, 0.005f, 0.5f);
if (sum > 20 && _robustRandom.Prob(chance))
_gridAtmosphereComponent.PryTile(GridIndices);
}

View File

@@ -100,7 +100,7 @@ namespace Content.Server.GameObjects.Components.Power
private void SetCurrentCharge(float newChargeAmount)
{
_currentCharge = FloatMath.Clamp(newChargeAmount, 0, MaxCharge);
_currentCharge = MathHelper.Clamp(newChargeAmount, 0, MaxCharge);
UpdateStorageState();
OnChargeChanged();
}

View File

@@ -178,7 +178,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
var currentTime = _gameTiming.CurTime;
var timeSinceLastFire = (currentTime - _lastFire).TotalSeconds;
var newTheta = FloatMath.Clamp(_currentAngle.Theta + _angleIncrease - _angleDecay * timeSinceLastFire, _minAngle.Theta, _maxAngle.Theta);
var newTheta = MathHelper.Clamp(_currentAngle.Theta + _angleIncrease - _angleDecay * timeSinceLastFire, _minAngle.Theta, _maxAngle.Theta);
_currentAngle = new Angle(newTheta);
var random = (_robustRandom.NextDouble() - 0.5) * 2;

View File

@@ -647,7 +647,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
var additionalVector = (centerGrid.Position - entityGridCoords.Position);
var distance = additionalVector.Length;
// If we're too far no point, if we're close then cap it at the normalized vector
distance = FloatMath.Clamp(2.5f - distance, 0.0f, 1.0f);
distance = MathHelper.Clamp(2.5f - distance, 0.0f, 1.0f);
additionalVector = new Angle(90 * distance).RotateVec(additionalVector);
avoidanceVector += additionalVector;
// if we do need to avoid that means we'll have to lookahead for the next tile

View File

@@ -56,7 +56,7 @@ namespace Content.Server.GameTicking.GamePresets
}
}
var numTraitors = FloatMath.Clamp(readyPlayers.Count % PlayersPerTraitor,
var numTraitors = MathHelper.Clamp(readyPlayers.Count % PlayersPerTraitor,
MinTraitors, readyPlayers.Count);
for (var i = 0; i < numTraitors; i++)

View File

@@ -60,7 +60,7 @@ namespace Content.Server.Preferences
await _prefsSemaphore.WaitAsync();
try
{
index = FloatMath.Clamp(index, 0, _maxCharacterSlots - 1);
index = MathHelper.Clamp(index, 0, _maxCharacterSlots - 1);
await _prefsDb.SaveSelectedCharacterIndex(username, index);
}
finally