1 module evael.utils.Rectangle;
2 
3 import evael.utils.Size;
4 import evael.utils.Math;
5 
6 /**
7  * Rectangle.
8  */
9 struct Rectangle(T = float, S = int)
10 {
11 	/// Rectangle bounds
12 	public T left, right, bottom, top;
13 	
14 	/// Rectangle size
15 	private Size!S m_size;
16 	
17 	public this(in T left, in T bottom, in S width, in S height)
18 	{
19 		this(Vector!(T, 2)(left, bottom), Size!S(width, height));
20 	}
21 
22 	public this()(in T left, in T bottom, in auto ref Size!S size)
23 	{
24 		this(Vector!(T, 2)(left, bottom), size);
25 	}
26 
27 	public this()(in auto ref Vector!(T, 2) position, in auto ref Size!S size)
28 	{
29 		this.left = position.x;
30 		this.bottom = position.y;
31 
32 		this.m_size = size;
33 
34 		this.right = this.left + this.m_size.width;
35 		this.top = this.bottom + this.m_size.height;
36 	}
37  	
38 	@nogc
39 	public bool isIn()(in auto ref ivec2 position) const nothrow
40 	{
41 		return position.x >= this.left && position.x <= this.right && 
42 		   position.y >= this.bottom && position.y <= this.top;
43 	}
44 
45 	@nogc
46 	public bool isIn()(in auto ref vec2 position) const nothrow
47 	{
48 		return position.x >= this.left && position.x <= this.right && 
49 		   position.y >= this.bottom && position.y <= this.top;
50 	}
51 
52 	@nogc
53 	@property nothrow
54 	{
55 		public ref const(Size!S) size() const
56 		{
57 			return this.m_size;
58 		}
59 	
60 		public void size()(in auto ref Size!S value)
61 		{
62 			this.m_size = value;
63 		}
64 	}
65 }
66 
67 alias Rectangle!float Rectanglef;