public static string ToShortTimeString( this TimeSpan timeSpan) { if (timeSpan.TotalMinutes <= 1) { int seconds = HDMath.Round(timeSpan.TotalSeconds); return(string.Format("{0} sec{1}", seconds, seconds > 1 ? "s" : "")); } else if (timeSpan.TotalHours <= 1) { int mins = (int)timeSpan.TotalMinutes; int secs = timeSpan.Seconds; return(string.Format("{0} min{1} {2} sec{3}", mins, mins > 1 ? "s" : "", secs, secs > 1 ? "s" : "")); } else if (timeSpan.TotalDays <= 1) { int hours = (int)timeSpan.TotalHours; int mins = timeSpan.Minutes; return(string.Format("{0} hour{1} {2} min{3}", hours, hours > 1 ? "s" : "", mins, mins > 1 ? "s" : "")); } else { int days = (int)timeSpan.TotalDays; int hours = timeSpan.Hours; return(string.Format("{0} day{1} {2} hour{3}", days, days > 1 ? "s" : "", hours, hours > 1 ? "s" : "")); } }
public static float Sample(this float[] fArr, float t) { int count = fArr.Length; if (count == 0) { Debug.Fail("Unable to sample array - it has no elements"); return(0); } if (count == 1) { return(fArr[0]); } float iFloat = t * (count - 1); int idLower = HDMath.Floor(iFloat); int idUpper = HDMath.Floor(iFloat + 1); if (idUpper >= count) { return(fArr[count - 1]); } if (idLower < 0) { return(fArr[0]); } return(HDMath.Lerp(fArr[idLower], fArr[idUpper], iFloat - idLower)); }
public static bool IsApprox( this float a, float b) { return(HDMath.Abs(a - b) < 0.0001f); }
public static float Round128(this float value) { return(HDMath.Round(value * 128f) * (1f / 128f)); }