@@ -11,55 +11,67 @@ namespace ReClassNET.Util
11
11
public static class Extensions
12
12
{
13
13
[ Pure ]
14
- public static bool IsNearlyEqual ( this float val , float other )
14
+ public static int ToRgb ( this Color color )
15
15
{
16
- return IsNearlyEqual ( val , other , float . Epsilon ) ;
16
+ return 0xFFFFFF & color . ToArgb ( ) ;
17
17
}
18
18
19
19
[ Pure ]
20
- public static bool IsNearlyEqual ( this float val , float other , float epsilon )
20
+ public static void FillWithZero ( this byte [ ] b )
21
21
{
22
- var diff = Math . Abs ( val - other ) ;
22
+ Contract . Requires ( b != null ) ;
23
23
24
- if ( val == other )
25
- {
26
- return true ;
27
- }
28
- else if ( val == 0 || other == 0 || diff < float . Epsilon )
29
- {
30
- return diff < epsilon ;
31
- }
32
- else
24
+ for ( var i = 0 ; i < b . Length ; ++ i )
33
25
{
34
- return diff / ( Math . Abs ( val ) + Math . Abs ( other ) ) < epsilon ;
26
+ b [ i ] = 0 ;
35
27
}
36
28
}
37
29
38
- [ Pure ]
39
- public static bool IsNearlyEqual ( this double val , double other )
30
+ public static void ShowDialog ( this Exception ex )
40
31
{
41
- return IsNearlyEqual ( val , other , double . Epsilon ) ;
32
+ Contract . Requires ( ex != null ) ;
33
+
34
+ // This doesn't look good...
35
+ ex . HelpLink = "https://github.com/KN4CK3R/ReClass.NET/issues" ;
36
+
37
+ var msg = new ExceptionMessageBox ( ex ) ;
38
+ msg . ShowToolBar = true ;
39
+ msg . Symbol = ExceptionMessageBoxSymbol . Error ;
40
+ msg . Show ( null ) ;
42
41
}
43
42
44
43
[ Pure ]
45
- public static bool IsNearlyEqual ( this double val , double other , double epsilon )
44
+ public static Point OffsetEx ( this Point p , int x , int y )
46
45
{
47
- var diff = Math . Abs ( val - other ) ;
46
+ var temp = p ;
47
+ temp . Offset ( x , y ) ;
48
+ return temp ;
49
+ }
48
50
49
- if ( val == other )
50
- {
51
- return true ;
52
- }
53
- else if ( val == 0 || other == 0 || diff < double . Epsilon )
54
- {
55
- return diff < epsilon ;
56
- }
57
- else
51
+ public static IEnumerable < BaseNode > Descendants ( this BaseNode root )
52
+ {
53
+ Contract . Requires ( root != null ) ;
54
+
55
+ var nodes = new Stack < BaseNode > ( ) ;
56
+ nodes . Push ( root ) ;
57
+ while ( nodes . Any ( ) )
58
58
{
59
- return diff / ( Math . Abs ( val ) + Math . Abs ( other ) ) < epsilon ;
59
+ var node = nodes . Pop ( ) ;
60
+ yield return node ;
61
+
62
+ var classNode = node as ClassNode ;
63
+ if ( classNode != null )
64
+ {
65
+ foreach ( var child in classNode . Nodes )
66
+ {
67
+ nodes . Push ( child ) ;
68
+ }
69
+ }
60
70
}
61
71
}
62
72
73
+ #region Pointer
74
+
63
75
[ Pure ]
64
76
public static bool IsNull ( this IntPtr ptr )
65
77
{
@@ -130,11 +142,9 @@ public static bool InRange(this IntPtr address, IntPtr start, IntPtr end)
130
142
#endif
131
143
}
132
144
133
- [ Pure ]
134
- public static int ToRgb ( this Color color )
135
- {
136
- return 0xFFFFFF & color . ToArgb ( ) ;
137
- }
145
+ #endregion
146
+
147
+ #region String
138
148
139
149
[ Pure ]
140
150
public static bool IsPrintable ( this char c )
@@ -194,14 +204,6 @@ public static float IsLikelyPrintableData(this IEnumerable<char> source)
194
204
return countValid / ( float ) countAll ;
195
205
}
196
206
197
- [ Pure ]
198
- public static Point OffsetEx ( this Point p , int x , int y )
199
- {
200
- var temp = p ;
201
- temp . Offset ( x , y ) ;
202
- return temp ;
203
- }
204
-
205
207
[ Pure ]
206
208
public static string LimitLength ( this string s , int length )
207
209
{
@@ -214,39 +216,64 @@ public static string LimitLength(this string s, int length)
214
216
return s . Substring ( 0 , length ) ;
215
217
}
216
218
219
+ #endregion
220
+
221
+ #region Floating Point
222
+
217
223
[ Pure ]
218
- public static void FillWithZero ( this byte [ ] b )
224
+ public static bool IsNearlyEqual ( this float val , float other )
219
225
{
220
- Contract . Requires ( b != null ) ;
226
+ return IsNearlyEqual ( val , other , float . Epsilon ) ;
227
+ }
221
228
222
- for ( var i = 0 ; i < b . Length ; ++ i )
229
+ [ Pure ]
230
+ public static bool IsNearlyEqual ( this float val , float other , float epsilon )
231
+ {
232
+ var diff = Math . Abs ( val - other ) ;
233
+
234
+ if ( val == other )
223
235
{
224
- b [ i ] = 0 ;
236
+ return true ;
237
+ }
238
+ else if ( val == 0 || other == 0 || diff < float . Epsilon )
239
+ {
240
+ return diff < epsilon ;
241
+ }
242
+ else
243
+ {
244
+ return diff / ( Math . Abs ( val ) + Math . Abs ( other ) ) < epsilon ;
225
245
}
226
246
}
227
247
228
- public static IEnumerable < BaseNode > Descendants ( this BaseNode root )
248
+ [ Pure ]
249
+ public static bool IsNearlyEqual ( this double val , double other )
229
250
{
230
- Contract . Requires ( root != null ) ;
251
+ return IsNearlyEqual ( val , other , double . Epsilon ) ;
252
+ }
231
253
232
- var nodes = new Stack < BaseNode > ( ) ;
233
- nodes . Push ( root ) ;
234
- while ( nodes . Any ( ) )
235
- {
236
- var node = nodes . Pop ( ) ;
237
- yield return node ;
254
+ [ Pure ]
255
+ public static bool IsNearlyEqual ( this double val , double other , double epsilon )
256
+ {
257
+ var diff = Math . Abs ( val - other ) ;
238
258
239
- var classNode = node as ClassNode ;
240
- if ( classNode != null )
241
- {
242
- foreach ( var child in classNode . Nodes )
243
- {
244
- nodes . Push ( child ) ;
245
- }
246
- }
259
+ if ( val == other )
260
+ {
261
+ return true ;
262
+ }
263
+ else if ( val == 0 || other == 0 || diff < double . Epsilon )
264
+ {
265
+ return diff < epsilon ;
266
+ }
267
+ else
268
+ {
269
+ return diff / ( Math . Abs ( val ) + Math . Abs ( other ) ) < epsilon ;
247
270
}
248
271
}
249
272
273
+ #endregion
274
+
275
+ #region Linq
276
+
250
277
public static int FindIndex < TSource > ( this IEnumerable < TSource > source , Func < TSource , bool > predicate )
251
278
{
252
279
Contract . Requires ( source != null ) ;
@@ -336,17 +363,6 @@ public static IEnumerable<TSource> TakeUntil<TSource>(this IEnumerable<TSource>
336
363
}
337
364
}
338
365
339
- public static void ShowDialog ( this Exception ex )
340
- {
341
- Contract . Requires ( ex != null ) ;
342
-
343
- // This doesn't look good...
344
- ex . HelpLink = "https://github.com/KN4CK3R/ReClass.NET/issues" ;
345
-
346
- var msg = new ExceptionMessageBox ( ex ) ;
347
- msg . ShowToolBar = true ;
348
- msg . Symbol = ExceptionMessageBoxSymbol . Error ;
349
- msg . Show ( null ) ;
350
- }
366
+ #endregion
351
367
}
352
368
}
0 commit comments