/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ using UnityEngine; namespace Live2D.Cubism.Framework.Utils { public class CubismMath { /// /// Returns the remainder of the division of two numbers. /// If invalid dividend or divisor is passed, it returns . /// /// , and are not allowed. /// and Zero is not allowed. /// public static float ModF(float dividend, float divisor) { if (!float.IsFinite(dividend) || Mathf.Approximately(divisor, 0) || float.IsNaN(dividend) || float.IsNaN(divisor)) { Debug.LogWarning($"Invalid dividend or divisor. divided: {dividend}, divisor: {divisor} Mod() returns 'NaN'."); return float.NaN; } // Calculate the remainder of the division. return dividend % divisor; } /// /// Returns the value clamped within the specified range. /// /// Value to be checked within the range. /// Minimum value. /// Maximum value. /// Clamped value within the range. public static float ClampF(float val, float min, float max) { if (val < min) { return min; } else if (max < val) { return max; } return val; } } }