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