circle.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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 uicore
35 {
39  template<typename Type>
40  class Circlex
41  {
42  public:
45 
47  Type radius;
48 
49  Circlex(Type x, Type y, Type radius) : position(x, y), radius(radius) { }
50  Circlex(const Vec2<Type> &p, Type radius) : position(p), radius(radius) { }
51  Circlex() : position(), radius(static_cast<Type> (0)) { }
52  Circlex(const Circlex<Type> &copy) : position(copy.position), radius(copy.radius) {}
53 
54  bool is_inside(const Vec2<Type> &point) { return radius >= position.distance(point); }
55 
56  Circlex<Type> &operator = (const Circlex<Type>& copy) { position = copy.position; radius = copy.radius; return *this; }
57  bool operator == (const Circlex<Type>& circle) const { return ((position == circle.position) && (radius == circle.radius)); }
58  bool operator != (const Circlex<Type>& circle) const { return ((position != circle.position) || (radius != circle.radius)); }
59  };
60 
62  class Circle : public Circlex<int>
63  {
64  public:
65  Circle(int x, int y, int radius) : Circlex<int>(x, y, radius) { }
66  Circle(const Vec2<int> &p, int radius) : Circlex<int>(p, radius) { }
67  Circle() : Circlex<int>(){ }
68  Circle(const Circlex<int> &copy) : Circlex<int>(copy){ }
69  };
70 
72  class Circlef : public Circlex<float>
73  {
74  public:
75  Circlef(float x, float y, float radius) : Circlex<float>(x, y, radius) { }
76  Circlef(const Vec2<float> &p, float radius) : Circlex<float>(p, radius) { }
77  Circlef() : Circlex<float>(){ }
78  Circlef(const Circlex<float> &copy) : Circlex<float>(copy){ }
79  };
80 
82  class Circled : public Circlex<double>
83  {
84  public:
85  Circled(double x, double y, double radius) : Circlex<double>(x, y, radius) { }
86  Circled(const Vec2<double> &p, double radius) : Circlex<double>(p, radius) { }
87  Circled() : Circlex<double>(){ }
88  Circled(const Circlex<double> &copy) : Circlex<double>(copy){ }
89  };
90 }
Circlex< Type > & operator=(const Circlex< Type > &copy)
Definition: circle.h:56
Circlef(const Circlex< float > &copy)
Definition: circle.h:78
Circle.
Definition: circle.h:40
Circlef()
Definition: circle.h:77
Type radius
Circle radius.
Definition: circle.h:47
Circlex(const Vec2< Type > &p, Type radius)
Definition: circle.h:50
2D vector
Definition: line.h:43
Type distance(const Vec2< Type > &vector) const
Calculate the distance between this vector and an other vector.
Circle - Integer.
Definition: circle.h:62
Circlex(Type x, Type y, Type radius)
Definition: circle.h:49
Circled(const Vec2< double > &p, double radius)
Definition: circle.h:86
Circlef(const Vec2< float > &p, float radius)
Definition: circle.h:76
Vec2< Type > position
Circle center point.
Definition: circle.h:44
Circlex(const Circlex< Type > &copy)
Definition: circle.h:52
Circle - Double.
Definition: circle.h:82
Circled(const Circlex< double > &copy)
Definition: circle.h:88
Circle()
Definition: circle.h:67
bool operator==(const Circlex< Type > &circle) const
Definition: circle.h:57
Circled()
Definition: circle.h:87
Circled(double x, double y, double radius)
Definition: circle.h:85
Circlef(float x, float y, float radius)
Definition: circle.h:75
Circle(int x, int y, int radius)
Definition: circle.h:65
bool is_inside(const Vec2< Type > &point)
Definition: circle.h:54
Circle(const Circlex< int > &copy)
Definition: circle.h:68
Circle(const Vec2< int > &p, int radius)
Definition: circle.h:66
bool operator!=(const Circlex< Type > &circle) const
Definition: circle.h:58
Circle - Float.
Definition: circle.h:72
Circlex()
Definition: circle.h:51
Definition: Application/application.h:35