1 module prova.attachables.colliders.rectcollider;
2 
3 import prova.attachables;
4 import prova.collision.intersects;
5 import prova.collision.resolve;
6 import prova.core;
7 import prova.graphics;
8 import prova.math;
9 
10 ///
11 class RectCollider : Collider2D
12 {
13   private float _width;
14   private float _height;
15 
16   ///
17   this(float width, float height)
18   {
19     super(Shape.RECTANGLE);
20     this._width = width;
21     this._height = height;
22   }
23 
24   ///
25   @property float width()
26   {
27     return _width;
28   }
29 
30   ///
31   @property void width(float width)
32   {
33     this._width = width;
34     updateSize();
35   }
36 
37   ///
38   @property float height()
39   {
40     return _height;
41   }
42 
43   ///
44   @property void height(float height)
45   {
46     this._height = height;
47     updateSize();
48   }
49 
50   ///
51   void resize(float width, float height)
52   {
53     this._width = width;
54     this._height = height;
55     updateSize();
56   }
57 
58   ///
59   override Vector2 getSize()
60   {
61     return Vector2(_width, _height);
62   }
63 
64   ///
65   override bool intersects(RectCollider collider)
66   {
67     return rectIntersectsRect(this, collider);
68   }
69 
70   ///
71   override bool intersects(CircleCollider collider)
72   {
73     return circleIntersectsRect(collider, this);
74   }
75 
76   ///
77   override bool intersects(PointCollider collider)
78   {
79     return pointIntersectsRect(collider, this);
80   }
81 
82   alias intersects = Collider2D.intersects;
83 
84   ///
85   override Vector2 resolve(PointCollider collider)
86   {
87     return -resolvePointRect(collider, this);
88   }
89 
90   ///
91   override Vector2 resolve(CircleCollider collider)
92   {
93     return -resolveCircleRect(collider, this);
94   }
95 
96   ///
97   override Vector2 resolve(RectCollider collider)
98   {
99     return resolveRectRect(this, collider);
100   }
101 
102   alias resolve = Collider2D.resolve;
103 }