-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rect.cs
61 lines (57 loc) · 1.85 KB
/
Rect.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
using System.Runtime.InteropServices;
namespace PiGameSharp
{
/// <summary>
/// A rectangle with integer parameters
/// </summary>
[StructLayout(LayoutKind.Explicit, Size=16, Pack=0)]
public struct Rect
{
/// <summary>
/// The upper left corner position of the rectangle
/// </summary>
[FieldOffset(0)]
public readonly Vector2 pos;
/// <summary>
/// The size of the rectangle
/// </summary>
[FieldOffset(8)]
public readonly Vector2 size;
/// <summary>
/// Initializes a new instance of the <see cref="PiGameSharp.Rect"/> struct.
/// </summary>
/// <param name="origin">Upper left position of the rectangle</param>
/// <param name="size">Size of the rectangle</param>
public Rect(Vector2 origin, Vector2 size)
{
this.pos = origin;
this.size = size;
}
/// <summary>
/// Shift left all integer parameters of a rectangle.
/// </summary>
/// <remarks>
/// In some cases rectangles are denoted using fixed point math, for example the source rectangles in dispmanx elements.
/// Bitshifting makes dealing with this much easier
/// </remarks>
/// <param name="item">The rectangle to shift left</param>
/// <param name="bits">How many bits to shift left</param>
public static Rect operator << (Rect item, int bits)
{
return new Rect(item.pos << bits, item.size << bits);
}
/// <summary>
/// Shift right all integer parameters of a rectangle.
/// </summary>
/// <remarks>
/// In some cases rectangles are denoted using fixed point math, for example the source rectangles in dispmanx elements.
/// Bitshifting makes dealing with this much easier
/// </remarks>
/// <param name="item">The rectangle to shift right</param>
/// <param name="bits">How many bits to shift right</param>
public static Rect operator >> (Rect item, int bits)
{
return new Rect(item.pos >> bits, item.size >> bits);
}
}
}