33using System.Xml.Serialization;
40#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE && !NETFX_CORE
44 [AdvBrowsableOrder(
"Min,Value,Max")]
46#if !(WINDOWS_PHONE || XBOX || NETFX_CORE)
49 IComparable<Clamped>, IEquatable<Clamped>
56 throw new ArgumentNullException(
"s");
58#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT
60 string[] vals = s.Split(
new char[] {
'<',
'(',
')' }, StringSplitOptions.RemoveEmptyEntries);
62 string[] temp = s.Split(
new char[] {
'<',
'(',
')' });
64 for (
int index1 = 0; index1 < temp.Length; ++index1)
66 if (temp[index1].Length > 0)
68 temp[index2++] = temp[index1];
71 string[] vals =
new string[index2];
72 Array.Copy(temp, vals, vals.Length);
76 throw new FormatException();
83#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT
88 string[] vals = s.Split(
new char[] {
'<',
'(',
')' }, StringSplitOptions.RemoveEmptyEntries);
140 this.value = copy.
value;
150 get {
return this.
value; }
165 if (
value >
max) {
throw new ArgumentOutOfRangeException(
"value"); }
179 if (
value <
min) {
throw new ArgumentOutOfRangeException(
"value"); }
215 get {
return this.value ==
max; }
222 get {
return this.value ==
min; }
249 return newValue -
max;
251 else if (newValue <
min)
254 return newValue -
min;
258 this.value = newValue;
273 result = newValue -
max;
275 else if (newValue <
min)
278 result = newValue -
min;
282 this.value = newValue;
294 if (
min >
max) {
throw new ArgumentOutOfRangeException(
"min"); }
302 return string.Format(
"({0} < {1} < {2})",
min,
value,
max);
306 return this.value.GetHashCode();
311 return other !=
null &&
Equals(other);
315 return this.value.Equals(other.
value);
319 return this.value.CompareTo(other.
value);
A class that keeps a value clamped.
Scalar Percent
Gets and Sets the percent with Min being 0 (0%) and Max being 1 (100%)
Clamped(Scalar value, Scalar min, Scalar max)
Creates a new Clamped instance.
Scalar Min
Gets and Sets the minimum value.
bool IsMax
Gets if the value is at its maximum value;
override int GetHashCode()
Clamped(Scalar value)
Creates a new Clamped instance with zero being either the max or min.
void Maximize()
Sets it to its maximum value;
static Clamped Parse(string s)
Scalar Max
Gets and Sets the maximum value.
void SetValues(Scalar value, Scalar min, Scalar max)
Sets all the values at once.
void Add(ref Scalar value, out Scalar result)
Adds a value to the clamped vaule and returns the overflow/underflow.
void Minimize()
Sets it to its minimum value;
Clamped()
Creates a new Clamped instance all values being zero.
override bool Equals(object obj)
static bool TryParse(string s, out Clamped result)
int CompareTo(Clamped other)
bool Equals(Clamped other)
Scalar Add(Scalar value)
Adds a value to the clamped vaule and returns the overflow/underflow.
Scalar Value
Gets and Sets the current value.
override string ToString()
bool IsMin
Gets if the value is at its minimum value;
static Scalar Clamp(Scalar value, Scalar min, Scalar max)
static Scalar Lerp(Scalar left, Scalar right, Scalar amount)