iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Circle.H
Go to the documentation of this file.
1 /*! @file
2  @author Randolph Voorhies
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_CORE_GEOMETRY_CIRCLE_H
37 #define INCLUDE_NRT_CORE_GEOMETRY_CIRCLE_H
38 
41 #include <nrt/External/cereal/access.hpp>
42 
43 namespace nrt
44 {
45  //! A simple representation of a circle
46  /*! \ingroup geometry */
47  template <class T>
48  class Circle
49  {
50  public:
51  //! Default constructor - creates a Circle with both ends at (0,0)
52  explicit Circle();
53 
54  //! Construct a Circle from the center and the radius
55  explicit Circle(Point2D<T> const & center, T const & radius);
56 
57  //! Construct a Circle from the given x and y coordinates and radius
58  explicit Circle(T cx, T cy, T radius);
59 
60  //! Copy Constructor
61  Circle(Circle<T> const & other) = default;
62 
63  //! Move constructor
64  Circle(Circle<T> && other) = default;
65 
66  //! Conversion copy constructor, uses nrt::clamped_convert<T,U> internally
67  template <class U>
68  explicit Circle(Circle<U> const & other);
69 
70  //! Assignment
71  Circle<T> & operator=(Circle<T> const & other) = default;
72 
73  //! Move assignment
74  Circle<T> & operator=(Circle<T> && other) = default;
75 
76  //! Get the center
77  Point2D<T> const& center() const;
78 
79  //! Get the radius
80  T const & radius() const;
81 
82  //! Calculate the area
83  double area() const;
84 
85  //! Calculate the circumference
86  double circumference() const;
87 
88  //! Calculate whether the given point lies within this circle
89  /*! This test is inclusive, such that points that are "radius" away from the center if the circle are considered
90  to be contained in the circle */
91  template <class U>
92  bool contains(Point2D<U> const & p) const;
93 
94  protected:
95  template <class Archive>
96  void serialize(Archive& ar)
97  {
98  ar( itsCenter, itsRadius );
99  }
100  friend class cereal::access;
101 
102  private:
103  Point2D<T> itsCenter;
104  T itsRadius;
105  };
106 
107  // ######################################################################
108  // Free functions for Circle<T>
109  // ######################################################################
110 
111  //! Human-readable output to a stream: outputs "c:<center> r:<radius>"
112  /*! \relates Circle */
113  template <class T>
114  std::ostream & operator<<(std::ostream &out, Circle<T> const & circle);
115 
116  //! Return a scaled version of the source object
117  /*! \note This does \e not have the same effect as the multiplication or division operators, which scale everything,
118  while here we only scale the object size without scaling its center coordinates.
119  \relates Circle */
120  template <class T>
121  Circle<T> scale(Circle<T> const & src, double const factor);
122 
123  //! Return a rotated version of the source object, about its center by a given angle in radians
124  /*! For circle this operation is a no-op. It is provided for compatibility with other geometric primitives
125  \relates Circle */
126  template <class T>
127  Circle<T> rotate(Circle<T> const & src, double const angle);
128 
129  //! Return a rotated version of the source object, about the given point and by a given angle in radians
130  /*! \relates Circle */
131  template <class T>
132  Circle<T> rotateAbout(Circle<T> const & src, Point2D<T> const & p, double const angle);
133 
134  //! Operator overload for Circle<T> == Circle<T>
135  /*! \relates Circle */
136  template <class T>
137  bool operator==(Circle<T> const & lhs, Circle<T> const & rhs);
138 
139  //! Operator overload for Circle<T> != Circle<T>
140  /*! \relates Circle */
141  template <class T>
142  bool operator!=(Circle<T> const & lhs, Circle<T> const & rhs);
143 
144  //! Operator overload for Circle<T> + Point2D<T>
145  /*! \relates Circle */
146  template <class T>
147  Circle<T> operator+(Circle<T> const & lhs, Point2D<T> const & rhs);
148 
149  //! Operator overload for Point2D<T> + Circle<T>
150  /*! \relates Circle */
151  template <class T>
152  Circle<T> operator+(Point2D<T> const & lhs, Circle<T> const & rhs);
153 
154  //! Operator overload for Circle<T> - Point2D<T>
155  /*! \relates Circle */
156  template <class T>
157  Circle<T> operator-(Circle<T> const & lhs, Point2D<T> const & rhs);
158 
159  //! Operator overload for Point2D<T> - Circle<T>
160  /*! \relates Circle */
161  template <class T>
162  Circle<T> operator-(Point2D<T> const & lhs, Circle<T> const & rhs);
163 
164  //! Operator overload for Circle<T> * double
165  /*! \relates Circle */
166  template <class T>
167  Circle<T> operator*(Circle<T> const & lhs, double const rhs);
168 
169  //! Operator overload for double * Circle<T>
170  /*! \relates Circle */
171  template <class T>
172  Circle<T> operator*(double const lhs, Circle<T> const & rhs);
173 
174  //! Operator overload for Circle<T> / double
175  /*! \relates Circle */
176  template <class T>
177  Circle<T> operator/(Circle<T> const & lhs, double const rhs);
178 
179  //! Operator overload for Circle<T> *= double
180  /*! \relates Circle */
181  template <class T>
182  Circle<T> & operator*=(Circle<T> & lhs, double const rhs);
183 
184  //! Operator overload for Circle<T> /= double
185  /*! \relates Circle */
186  template <class T>
187  Circle<T> & operator/=(Circle<T> & lhs, double const rhs);
188 
189 }
190 
191 // Include incircled implementation details that are of no interest to the end user
193 
194 #endif // INCLUDE_NRT_CORE_GEOMETRY_CIRCLE_H
195