wasSharp – Blame information for rev 27

Subversion Repositories:
Rev:
Rev Author Line No. Line
5 eva 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. //
5 ///////////////////////////////////////////////////////////////////////////
6  
7 namespace wasSharp
8 {
7 office 9 public static class Numerics
5 eva 10 {
11 ///////////////////////////////////////////////////////////////////////////
12 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 //
13 ///////////////////////////////////////////////////////////////////////////
14 /// <summary>
15 /// Given a value in a source value range and a target range, map
16 /// the value from the source range into the target range.
17 /// </summary>
6 eva 18 /// <remarks>
19 /// value - the value to map
20 /// xMin - the lower bound of the source range
21 /// xMax - the upper bound of the source range
22 /// yMin - the lower bound of the target range
23 /// yMax - the upper bound of the target range
24 /// </remarks>
25 /// <returns>a value in x mapped in the range of y</returns>
7 office 26 public static double MapValueToRange(double value, double xMin, double xMax, double yMin, double yMax)
27 {
27 office 28 return yMin + (yMax - yMin) * (value - xMin) / (xMax - xMin);
7 office 29 }
24 office 30  
31 public static bool IsNullOrDefault<T>(T value)
32 {
33 return Equals(value, default(T));
34 }
35  
36 public static T DefaultOrValue<T>(this T initial, T value)
37 {
38 return Equals(initial, default(T)) ? value : initial;
39 }
5 eva 40 }
27 office 41 }