circle.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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
31 #pragma once
32
33 #include "point.h"
34
35 namespace clan
36 {
39
43 template<typename Type>
44 class Circlex
45 {
46 public:
48 Vec2<Type> position;
49
51 Type radius;
52
53 Circlex(Type x, Type y, Type radius) : position(x,y), radius(radius) { }
54 Circlex(const Vec2<Type> &p, Type radius) : position(p), radius(radius) { }
55 Circlex() : position(), radius( static_cast<Type> (0) ) { }
56 Circlex(const Circlex<Type> &copy) : position(copy.position), radius(copy.radius) {}
57
60 public:
61
62 bool is_inside( const Vec2<Type> &point ) {return radius >= position.distance(point);}
63
67 public:
69 Circlex<Type> &operator = (const Circlex<Type>& copy) { position = copy.position; radius = copy.radius; return *this; }
70
72 bool operator == (const Circlex<Type>& circle) const {return ((position == circle.position) && (radius == circle.radius));}
73
75 bool operator != (const Circlex<Type>& circle) const {return ((position != circle.position) || (radius != circle.radius));}
77 };
78
80 class Circle : public Circlex<int>
81 {
82 public:
83 Circle(int x, int y, int radius) : Circlex<int>(x, y, radius) { }
84 Circle(const Vec2<int> &p, int radius) : Circlex<int>(p, radius) { }
85 Circle() : Circlex<int>(){ }
86 Circle(const Circlex<int> &copy) : Circlex<int>(copy){ }
87 };
88
90 class Circlef : public Circlex<float>
91 {
92 public:
93 Circlef(float x, float y, float radius) : Circlex<float>(x, y, radius) { }
94 Circlef(const Vec2<float> &p, float radius) : Circlex<float>(p, radius) { }
95 Circlef() : Circlex<float>(){ }
96 Circlef(const Circlex<float> &copy) : Circlex<float>(copy){ }
97 };
98
100 class Circled : public Circlex<double>
101 {
102 public:
103 Circled(double x, double y, double radius) : Circlex<double>(x, y, radius) { }
104 Circled(const Vec2<double> &p, double radius) : Circlex<double>(p, radius) { }
105 Circled() : Circlex<double>(){ }
106 Circled(const Circlex<double> &copy) : Circlex<double>(copy){ }
107 };
108
109 }
110
clan
Definition: clanapp.h:35
clan::Circle::Circle
Circle(const Circlex< int > &copy)
Definition: circle.h:86
clan::Circled
Circle - Double.
Definition: circle.h:100
clan::Circled::Circled
Circled(const Vec2< double > &p, double radius)
Definition: circle.h:104
clan::Vec2::distance
Type distance(const Vec2< Type > &vector) const
Calculate the distance between this vector and an other vector.
clan::Circle::Circle
Circle(const Vec2< int > &p, int radius)
Definition: circle.h:84
clan::Key::x
clan::Circle
Circle - Integer.
Definition: circle.h:80
clan::Circlex::operator==
bool operator==(const Circlex< Type > &circle) const
== operator.
Definition: circle.h:72
clan::Circlex::Circlex
Circlex(Type x, Type y, Type radius)
Definition: circle.h:53
clan::Circlef::Circlef
Circlef(const Circlex< float > &copy)
Definition: circle.h:96
clan::Circled::Circled
Circled(const Circlex< double > &copy)
Definition: circle.h:106
clan::Circlex::operator=
Circlex< Type > & operator=(const Circlex< Type > &copy)
= operator.
Definition: circle.h:69
clan::Circlex::Circlex
Circlex(const Circlex< Type > &copy)
Definition: circle.h:56
clan::Circlex::operator!=
bool operator!=(const Circlex< Type > &circle) const
!= operator.
Definition: circle.h:75
clan::Circlef::Circlef
Circlef()
Definition: circle.h:95
clan::Circlef::Circlef
Circlef(float x, float y, float radius)
Definition: circle.h:93
clan::Circlef::Circlef
Circlef(const Vec2< float > &p, float radius)
Definition: circle.h:94
clan::Key::y
clan::Circlex::Circlex
Circlex(const Vec2< Type > &p, Type radius)
Definition: circle.h:54
clan::Circled::Circled
Circled()
Definition: circle.h:105
clan::Circlex::is_inside
bool is_inside(const Vec2< Type > &point)
Definition: circle.h:62
clan::Circlex::radius
Type radius
Circle radius.
Definition: circle.h:51
clan::Circlex
Circle.
Definition: circle.h:44
clan::Key::p
clan::Vec2
2D vector
Definition: line.h:48
clan::Circlex::Circlex
Circlex()
Definition: circle.h:55
clan::Circlef
Circle - Float.
Definition: circle.h:90
clan::Circlex::position
Vec2< Type > position
Circle center point.
Definition: circle.h:48
clan::Circle::Circle
Circle()
Definition: circle.h:85
clan::Circled::Circled
Circled(double x, double y, double radius)
Definition: circle.h:103
clan::Circle::Circle
Circle(int x, int y, int radius)
Definition: circle.h:83