Additional static functions used to extend existing Validation support inside of Unity.
More...
|
static float | ColorPercentage (this Color sourceColor, Color targetColor) |
| Calculate the percentage of similarity between two colors. More...
|
|
static bool | IsColorApproximatelySame (this Color sourceColor, Color targetColor) |
| Are the colors approximately equal? More...
|
|
static bool | IsDictionaryEqual< TKey, TValue > (this IDictionary< TKey, TValue > first, IDictionary< TKey, TValue > second) |
| Determines if dictionaries are equal. More...
|
|
static bool | IsNumericType (this object value) |
| Determines whether the specified value is of numeric type. More...
|
|
static bool | IsPositive (this object value, bool zeroIsPositive=true) |
| Determines whether the specified value is positive. More...
|
|
static bool | ScrambledEquals< T > (IEnumerable< T > list1, IEnumerable< T > list2) |
| Determines whether the two scrambled enumerable objects are equal. More...
|
|
Additional static functions used to extend existing Validation support inside of Unity.
Definition at line 39 of file Validate.cs.
static float Hydrogen.Validate.ColorPercentage |
( |
this Color |
sourceColor, |
|
|
Color |
targetColor |
|
) |
| |
|
static |
Calculate the percentage of similarity between two colors.
- Returns
- The percentage of similarity (0-1)
- Parameters
-
sourceColor | Left Side Color |
targetColor | Right Side Color |
Definition at line 47 of file Validate.cs.
49 return ((targetColor.r / sourceColor.r) +
50 (targetColor.g / sourceColor.g) +
51 (targetColor.b / sourceColor.b) +
52 (targetColor.a / sourceColor.a) / 4f);
static bool Hydrogen.Validate.IsColorApproximatelySame |
( |
this Color |
sourceColor, |
|
|
Color |
targetColor |
|
) |
| |
|
static |
Are the colors approximately equal?
- Returns
true
, if colors are approximately equal, false
otherwise.
- Parameters
-
sourceColor | Left Side Color |
targetColor | Right Side Color |
Definition at line 61 of file Validate.cs.
63 return (Mathf.Approximately (sourceColor.r, targetColor.r) &&
64 Mathf.Approximately (sourceColor.g, targetColor.g) &&
65 Mathf.Approximately (sourceColor.b, targetColor.b) &&
66 Mathf.Approximately (sourceColor.a, targetColor.a));
static bool Hydrogen.Validate.IsDictionaryEqual< TKey, TValue > |
( |
this IDictionary< TKey, TValue > |
first, |
|
|
IDictionary< TKey, TValue > |
second |
|
) |
| |
|
static |
Determines if dictionaries are equal.
- Returns
true
if the left side equals the right side; otherwise, false
.
- Parameters
-
first | Left Side Dictionary. |
second | Right Side Dictionary. |
- Template Parameters
-
TKey | The 1st type parameter. |
TValue | The 2nd type parameter. |
Definition at line 77 of file Validate.cs.
82 if ((first == null) || (second == null))
84 if (first.Count != second.Count)
87 var comparer = EqualityComparer<TValue>.Default;
89 foreach (KeyValuePair<TKey, TValue> kvp
in first) {
91 if (!second.TryGetValue (kvp.Key, out secondValue))
93 if (!comparer.Equals (kvp.Value, secondValue))
static bool Hydrogen.Validate.IsNumericType |
( |
this object |
value | ) |
|
|
static |
Determines whether the specified value is of numeric type.
- Returns
true
if value is a numeric type; otherwise, false
.
- Parameters
-
value | The object to check. |
Definition at line 107 of file Validate.cs.
109 return (value is byte ||
static bool Hydrogen.Validate.IsPositive |
( |
this object |
value, |
|
|
bool |
zeroIsPositive = true |
|
) |
| |
|
static |
Determines whether the specified value is positive.
- Returns
true
if the specified value is positive; otherwise, false
.
- Parameters
-
value | The value. |
zeroIsPositive | if set to true treats 0 as positive. Defaults to true. |
Definition at line 130 of file Validate.cs.
132 switch (Type.GetTypeCode (value.GetType ())) {
134 return (zeroIsPositive ? (sbyte)value >= 0 : (sbyte)value > 0);
136 return (zeroIsPositive ? (
short)value >= 0 : (short)value > 0);
138 return (zeroIsPositive ? (
int)value >= 0 : (int)value > 0);
140 return (zeroIsPositive ? (
long)value >= 0 : (long)value > 0);
141 case TypeCode.Single:
142 return (zeroIsPositive ? (
float)value >= 0 : (float)value > 0);
143 case TypeCode.Double:
144 return (zeroIsPositive ? (
double)value >= 0 : (double)value > 0);
145 case TypeCode.Decimal:
146 return (zeroIsPositive ? (decimal)value >= 0 : (decimal)value > 0);
148 return (zeroIsPositive || (byte)value > 0);
149 case TypeCode.UInt16:
150 return (zeroIsPositive || (ushort)value > 0);
151 case TypeCode.UInt32:
152 return (zeroIsPositive || (uint)value > 0);
153 case TypeCode.UInt64:
154 return (zeroIsPositive || (ulong)value > 0);
156 return (zeroIsPositive || (
char)value !=
'\0');
static bool Hydrogen.Validate.ScrambledEquals< T > |
( |
IEnumerable< T > |
list1, |
|
|
IEnumerable< T > |
list2 |
|
) |
| |
|
static |
Determines whether the two scrambled enumerable objects are equal.
- Returns
true
, if they are equal, false
otherwise.
- Parameters
-
- Template Parameters
-
Definition at line 169 of file Validate.cs.
171 var cnt =
new Dictionary<T, int> ();
173 foreach (T s
in list1) {
174 if (cnt.ContainsKey (s)) {
181 foreach (T s
in list2) {
182 if (cnt.ContainsKey (s)) {
189 return cnt.Values.All (c => c == 0);