]> git.localhorst.tv Git - sdl-test7.git/blob - src/geometry/Circle.h
imported current version
[sdl-test7.git] / src / geometry / Circle.h
1 /*
2  * Circle.h
3  *
4  *  Created on: Apr 19, 2012
5  *      Author: holy
6  */
7
8 #ifndef GEOMETRY_CIRCLE_H_
9 #define GEOMETRY_CIRCLE_H_
10
11 #include "Shape.h"
12
13 #include "AABB.h"
14
15 #include <SDL/SDL.h>
16
17
18 namespace geometry {
19
20 class Circle
21 : public Shape {
22
23         public:
24                 Circle(void) : position(), radius() { };
25                 explicit Circle(Scalar radius) : position(), radius(radius) { };
26                 explicit Circle(const Vector &position, Scalar radius = Scalar()) : position(position), radius(radius) { };
27                 virtual ~Circle(void) { };
28
29         public:
30                 Scalar X(void) const { return position.X(); };
31                 Scalar Y(void) const { return position.Y(); };
32                 Scalar Radius(void) const { return radius; };
33                 Scalar Diameter(void) const { return 2 * Radius(); };
34
35                 Scalar Width(void) const { return Diameter(); };
36                 Scalar Height(void) const { return Diameter(); };
37
38                 Scalar Left(void) const { return X() - Radius(); };
39                 Scalar Top(void) const { return Y() - Radius(); };
40                 Scalar Right(void) const { return X() + Radius(); };
41                 Scalar Bottom(void) const { return Y() + Radius(); };
42
43         public:
44                 virtual bool Overlaps(const Shape &other, Vector &normal) const;
45                 virtual bool Overlaps(const AABB &other, Vector &normal) const;
46                 virtual bool Overlaps(const Circle &other, Vector &normal) const;
47                 virtual bool Overlaps(const FakeLens &, Vector &normal) const;
48
49                 bool VerticalOverlap(const AABB &other) const {
50                         if (Bottom() < other.Top()) return false;
51                         if (other.Bottom() < Top()) return false;
52                         return true;
53                 };
54                 bool HorizontalOverlap(const AABB &other) const {
55                         if (Right() < other.Left()) return false;
56                         if (other.Right() < Left()) return false;
57                         return true;
58                 };
59
60         public:
61                 void Move(const Vector &delta) {
62                         position += delta;
63                 };
64
65                 void SetPosition(const Vector &pos) {
66                         position = pos;
67                 };
68                 void SetRadius(Scalar r) {
69                         radius = r;
70                 };
71
72                 virtual Vector Center(void) const {
73                         return position;
74                 };
75
76                 virtual std::ostream &Write(std::ostream &out) const;
77
78         private:
79                 Vector position;
80                 Scalar radius;
81
82 };
83
84 }
85
86 #endif /* GEOMETRY_CIRCLE_H_ */