circle.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Harry Storbacka
27 ** Mark Page
28 */
29 
30 #pragma once
31 
32 #include "point.h"
33 
34 namespace clan
35 {
38 
42  template<typename Type>
43  class Circlex
44  {
45  public:
48 
50  Type radius;
51 
52  Circlex(Type x, Type y, Type radius) : position(x, y), radius(radius) { }
53  Circlex(const Vec2<Type> &p, Type radius) : position(p), radius(radius) { }
54  Circlex() : position(), radius(static_cast<Type> (0)) { }
55  Circlex(const Circlex<Type> &copy) : position(copy.position), radius(copy.radius) {}
56 
57  bool is_inside(const Vec2<Type> &point) { return radius >= position.distance(point); }
58 
59  Circlex<Type> &operator = (const Circlex<Type>& copy) { position = copy.position; radius = copy.radius; return *this; }
60  bool operator == (const Circlex<Type>& circle) const { return ((position == circle.position) && (radius == circle.radius)); }
61  bool operator != (const Circlex<Type>& circle) const { return ((position != circle.position) || (radius != circle.radius)); }
62  };
63 
65  class Circle : public Circlex<int>
66  {
67  public:
68  Circle(int x, int y, int radius) : Circlex<int>(x, y, radius) { }
69  Circle(const Vec2<int> &p, int radius) : Circlex<int>(p, radius) { }
70  Circle() : Circlex<int>(){ }
71  Circle(const Circlex<int> &copy) : Circlex<int>(copy){ }
72  };
73 
75  class Circlef : public Circlex<float>
76  {
77  public:
78  Circlef(float x, float y, float radius) : Circlex<float>(x, y, radius) { }
79  Circlef(const Vec2<float> &p, float radius) : Circlex<float>(p, radius) { }
80  Circlef() : Circlex<float>(){ }
81  Circlef(const Circlex<float> &copy) : Circlex<float>(copy){ }
82  };
83 
85  class Circled : public Circlex<double>
86  {
87  public:
88  Circled(double x, double y, double radius) : Circlex<double>(x, y, radius) { }
89  Circled(const Vec2<double> &p, double radius) : Circlex<double>(p, radius) { }
90  Circled() : Circlex<double>(){ }
91  Circled(const Circlex<double> &copy) : Circlex<double>(copy){ }
92  };
93 
95 }
bool is_inside(const Vec2< Type > &point)
Definition: circle.h:57
Definition: clanapp.h:35
Circle - Double.
Definition: circle.h:85
Circlef(const Vec2< float > &p, float radius)
Definition: circle.h:79
2D vector
Definition: line.h:46
Circle()
Definition: circle.h:70
Circle(const Vec2< int > &p, int radius)
Definition: circle.h:69
bool operator==(const Circlex< Type > &circle) const
Definition: circle.h:60
Circlex()
Definition: circle.h:54
Circlef(float x, float y, float radius)
Definition: circle.h:78
Circle - Integer.
Definition: circle.h:65
Circled(double x, double y, double radius)
Definition: circle.h:88
Type radius
Circle radius.
Definition: circle.h:50
Circlex(const Circlex< Type > &copy)
Definition: circle.h:55
Circle(const Circlex< int > &copy)
Definition: circle.h:71
bool operator!=(const Circlex< Type > &circle) const
Definition: circle.h:61
Circled(const Vec2< double > &p, double radius)
Definition: circle.h:89
Circlex(const Vec2< Type > &p, Type radius)
Definition: circle.h:53
Circled()
Definition: circle.h:90
Circlex< Type > & operator=(const Circlex< Type > &copy)
Definition: circle.h:59
Circle.
Definition: circle.h:43
Circled(const Circlex< double > &copy)
Definition: circle.h:91
Circle - Float.
Definition: circle.h:75
Circlex(Type x, Type y, Type radius)
Definition: circle.h:52
Vec2< Type > position
Circle center point.
Definition: circle.h:47
Circlef()
Definition: circle.h:80
Circlef(const Circlex< float > &copy)
Definition: circle.h:81
Type distance(const Vec2< Type > &vector) const
Calculate the distance between this vector and an other vector.
Circle(int x, int y, int radius)
Definition: circle.h:68