Use built-in Math.Clamp over MathExt.Clamp, remove MathExt.Clamp

This commit is contained in:
Chev 2021-05-30 19:04:27 -07:00
parent 3962cdb38c
commit 0052ebc5c5
3 changed files with 4 additions and 21 deletions

View file

@ -412,7 +412,7 @@ namespace BOTWToolset.Control
if (float.TryParse(textSender.Text, out float overrideValue))
{
// Clamp value between 0 and 1
overrideValue = MathExt.Clamp(overrideValue, 0.0f, 1.0f);
overrideValue = Math.Clamp(overrideValue, 0.0f, 1.0f);
BOTWConsole.Log($"Overriding {textSender.Name} with value {overrideValue}");

View file

@ -23,10 +23,10 @@ namespace BOTWToolset.IO.TSCB
public uint FileBaseOffset { get => _fileBaseOffset; set => _fileBaseOffset = value; }
private uint _fileBaseOffset;
public float WorldScale { get => _worldScale; set => _worldScale = value.Clamp(0f, 800.0f); }
public float WorldScale { get => _worldScale; set => _worldScale = Math.Clamp(value, 0f, 800.0f); }
private float _worldScale;
public float TerrainMaxHeight { get => _terrainMaxHeight; set => _terrainMaxHeight = value.Clamp(0f, 800.0f); }
public float TerrainMaxHeight { get => _terrainMaxHeight; set => _terrainMaxHeight = Math.Clamp(value, 0f, 800.0f); }
private float _terrainMaxHeight;
public byte[] MaterialInfoOffsets;

View file

@ -1,27 +1,10 @@
using System;
namespace BOTWToolset
namespace BOTWToolset
{
/// <summary>
/// Extensions for Math.
/// </summary>
static class MathExt
{
/// <summary>
/// Clamps a value into a minimum and maximum range.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val">Value to clamp.</param>
/// <param name="min">The minimum value to use.</param>
/// <param name="max">The maximum value to use.</param>
/// <returns></returns>
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
if (val.CompareTo(min) < 0) return min;
else if (val.CompareTo(max) > 0) return max;
else return val;
}
/// <summary>
/// Linearly interpolates a value.
/// </summary>