circle.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Harry Storbacka
00027 **    Mark Page
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "point.h"
00036 
00041 template<typename Type>
00042 class CL_Circlex
00043 {
00044 public:
00046         CL_Vec2<Type> position;
00047 
00049         Type radius;
00050         
00051         CL_Circlex(Type x, Type y, Type radius) : position(x,y), radius(radius) { }
00052         CL_Circlex(const CL_Vec2<Type> &p, Type radius) : position(p), radius(radius) { }
00053         CL_Circlex() : radius( (Type) 0 )  { }
00054         CL_Circlex(const CL_Circlex<Type> &copy) { position = copy.position; radius = copy.radius;}
00055 
00058 public:
00059 
00060         bool is_inside( const CL_Vec2<Type> &point ) {return radius >= position.distance(point);}
00061 
00065 public:
00067         CL_Circlex<Type> &operator = (const CL_Circlex<Type>& copy) { position = copy.position; radius = copy.radius; return *this; }
00068 
00070         bool operator == (const CL_Circlex<Type>& circle) const {return ((position == circle.position) && (radius == circle.radius));}
00071 
00073         bool operator != (const CL_Circlex<Type>& circle) const {return ((position != circle.position) || (radius != circle.radius));}
00075 };
00076 
00080 class CL_Circle : public CL_Circlex<int>
00081 {
00082 public:
00083         CL_Circle(int x, int y, int radius) : CL_Circlex<int>(x, y, radius) { }
00084         CL_Circle(const CL_Vec2<int> &p, int radius) : CL_Circlex<int>(p, radius) { }
00085         CL_Circle() : CL_Circlex<int>(){ }
00086         CL_Circle(const CL_Circlex<int> &copy) : CL_Circlex<int>(copy){ }
00087 };
00088 
00092 class CL_Circlef : public CL_Circlex<float>
00093 {
00094 public:
00095         CL_Circlef(float x, float y, float radius) : CL_Circlex<float>(x, y, radius) { }
00096         CL_Circlef(const CL_Vec2<float> &p, float radius) : CL_Circlex<float>(p, radius) { }
00097         CL_Circlef() : CL_Circlex<float>(){ }
00098         CL_Circlef(const CL_Circlex<float> &copy) : CL_Circlex<float>(copy){ }
00099 };
00100 
00104 class CL_Circled : public CL_Circlex<double>
00105 {
00106 public:
00107         CL_Circled(double x, double y, double radius) : CL_Circlex<double>(x, y, radius) { }
00108         CL_Circled(const CL_Vec2<double> &p, double radius) : CL_Circlex<double>(p, radius) { }
00109         CL_Circled() : CL_Circlex<double>(){ }
00110         CL_Circled(const CL_Circlex<double> &copy) : CL_Circlex<double>(copy){ }
00111 };
00112