-
Notifications
You must be signed in to change notification settings - Fork 534
/
C2BPComparers.cs
85 lines (81 loc) · 3.02 KB
/
C2BPComparers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Collections;
using System.Drawing;
namespace iSpyApplication
{
public class HeightComparer : IComparer
{
// Return -1, 0, or 1 to indicate whether
// x belongs before, the same as, or after y.
// Sort by height, width descending.
public int Compare(object x, object y)
{
Rectangle xrect = (Rectangle)x;
Rectangle yrect = (Rectangle)y;
if (xrect.Height < yrect.Height) return 1;
if (xrect.Height > yrect.Height) return -1;
if (xrect.Width < yrect.Width) return 1;
if (xrect.Width > yrect.Width) return -1;
return 0;
}
}
public class WidthComparer : IComparer
{
// Return -1, 0, or 1 to indicate whether
// x belongs before, the same as, or after y.
// Sort by height, width descending.
public int Compare(object x, object y)
{
Rectangle xrect = (Rectangle)x;
Rectangle yrect = (Rectangle)y;
if (xrect.Width < yrect.Width) return 1;
if (xrect.Width > yrect.Width) return -1;
if (xrect.Height < yrect.Height) return 1;
if (xrect.Height > yrect.Height) return -1;
return 0;
}
}
public class AreaComparer : IComparer
{
// Return -1, 0, or 1 to indicate whether
// x belongs before, the same as, or after y.
// Sort by area, height, width descending.
public int Compare(object x, object y)
{
Rectangle xrect = (Rectangle)x;
Rectangle yrect = (Rectangle)y;
int xarea = xrect.Width * xrect.Height;
int yarea = yrect.Width * yrect.Height;
if (xarea < yarea) return 1;
if (xarea > yarea) return -1;
if (xrect.Height < yrect.Height) return 1;
if (xrect.Height > yrect.Height) return -1;
if (xrect.Width < yrect.Width) return 1;
if (xrect.Width > yrect.Width) return -1;
return 0;
}
}
public class SquarenessComparer : IComparer
{
// Return -1, 0, or 1 to indicate whether
// x belongs before, the same as, or after y.
// Sort by squareness, area, height, width descending.
public int Compare(object x, object y)
{
Rectangle xrect = (Rectangle)x;
Rectangle yrect = (Rectangle)y;
int xsq = System.Math.Abs(xrect.Width - xrect.Height);
int ysq = System.Math.Abs(yrect.Width - yrect.Height);
if (xsq < ysq) return -1;
if (xsq > ysq) return 1;
int xarea = xrect.Width * xrect.Height;
int yarea = yrect.Width * yrect.Height;
if (xarea < yarea) return 1;
if (xarea > yarea) return -1;
if (xrect.Height < yrect.Height) return 1;
if (xrect.Height > yrect.Height) return -1;
if (xrect.Width < yrect.Width) return 1;
if (xrect.Width > yrect.Width) return -1;
return 0;
}
}
}