-
Notifications
You must be signed in to change notification settings - Fork 8
/
ClassHierarchy.cs
50 lines (43 loc) · 1.11 KB
/
ClassHierarchy.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
namespace Generics;
public class Shape
{
public required Rect BoundingBox { get; set; }
}
public class RoundedRectangle : Shape
{
public required double CornerRadius { get; set; }
}
public class BoxAreaComparer : IComparer<Shape>
{
public int Compare(Shape? x, Shape? y)
{
if (x is null)
{
return y is null ? 0 : -1;
}
if (y is null)
{
return 1;
}
double xArea = x.BoundingBox.Width * x.BoundingBox.Height;
double yArea = y.BoundingBox.Width * y.BoundingBox.Height;
return Math.Sign(xArea - yArea);
}
}
public class CornerSharpnessComparer : IComparer<RoundedRectangle>
{
public int Compare(RoundedRectangle? x, RoundedRectangle? y)
{
if (x is null)
{
return y is null ? 0 : -1;
}
if (y is null)
{
return 1;
}
// Smaller corners are sharper, so smaller radius is "greater" for
// the purpose of this comparison, hence the backward subtraction.
return Math.Sign(y.CornerRadius - x.CornerRadius);
}
}