DGtal 1.4.0
Loading...
Searching...
No Matches
Point.h
1/* -*- mode: c++ -*- */
9/*
10 * \@copyright This File is part of the Board library which is
11 * licensed under the terms of the GNU Lesser General Public Licence.
12 * See the LICENCE file for further details.
13 */
14#ifndef _BOARD_POINT_H_
15#define _BOARD_POINT_H_
16
17#include <cmath>
18#include "DGtal/io/Color.h"
19
20namespace LibBoard {
21
22
27struct Point {
28
29 double x;
30 double y;
36 Point():x(0.0),y(0.0) { }
37
43 Point( const Point & other ):x(other.x),y(other.y) { }
44
50 Point &operator=( const Point & other ) = default;
51
58 Point( double xc, double yc ):x(xc),y(yc) { }
59
65 inline Point & rotate( double angle );
66
73 inline void get( double & xout, double & yout ) const;
74
82 inline Point rotated( double angle ) const;
83
84 inline Point & rotate( double angle, const Point & center );
85
86 inline Point rotated( double angle, const Point & center ) const;
87
88 inline Point & operator+=( const Point & other );
89
90 inline Point & operator-=( const Point & other );
91
92 inline Point & operator*=( double s );
93
94 inline Point & operator/=( double s );
95
96 inline Point operator-();
97
98 inline double norm() const;
99
100};
101
102inline void
103Point::get( double & xout, double & yout ) const
104{
105 xout = x;
106 yout = y;
107}
108
109inline Point
110operator+( const Point & a, const Point & b )
111{
112 return Point( a.x + b.x, a.y + b.y );
113}
114
115inline Point
116operator-( const Point & a, const Point & b )
117{
118 return Point( a.x - b.x, a.y - b.y );
119}
120
121inline double
122operator*( const Point & a, const Point & b )
123{
124 return a.x * b.x + a.y * b.y;
125}
126
127inline Point
128operator*( const Point & p, double s )
129{
130 return Point( p.x * s, p.y * s );
131}
132
133inline Point
134operator*( double s, const Point & p )
135{
136 return Point( s * p.x, s * p.y );
137}
138
139inline Point
140operator/( const Point & p, double s )
141{
142 return Point( p.x / s, p.y / s );
143}
144
145inline Point &
146Point::operator+=( const Point & other )
147{
148 x += other.x;
149 y += other.y;
150 return *this;
151}
152
153inline Point &
154Point::operator-=( const Point & other )
155{
156 x -= other.x;
157 y -= other.y;
158 return *this;
159}
160
161inline Point &
162Point::operator*=( double s )
163{
164 x *= s;
165 y *= s;
166 return *this;
167}
168
169inline Point &
170Point::operator/=( double s )
171{
172 x /= s;
173 y /= s;
174 return *this;
175}
176
177inline bool
178operator==( const Point & a, const Point & b )
179{
180 return ( a.x == b.x ) && ( a.y == b.y ) ;
181}
182
183inline bool
184operator!=( const Point & a, const Point & b )
185{
186 return ( a.x != b.x ) || ( a.y != b.y ) ;
187}
188
189Point &
190Point::rotate( double angle )
191{
192 double newx = cos( angle ) * Point::x - sin( angle ) * Point::y;
193 double newy = sin( angle ) * Point::x + cos( angle ) * Point::y;
194 x = newx;
195 y = newy;
196 return *this;
197}
198
199Point
200Point::rotated( double angle ) const
201{
202 return Point(*this).rotate( angle );
203}
204
205Point &
206Point::rotate( double angle, const Point & center )
207{
208 (*this) -= center;
209 (*this).rotate( angle );
210 (*this) += center;
211 return *this;
212}
213
214Point
215Point::rotated( double angle, const Point & center ) const
216{
217 return Point(*this).rotate( angle, center );
218}
219
220double
221Point::norm() const
222{
223 return sqrt( x*x + y*y );
224}
225
226Point Point::operator-()
227{
228 return Point( -x, -y );
229}
230
231} // mamespace BoardLib
232
233#endif // _POINT_H_
234
Point operator+(const Point &a, const Point &b)
Definition Point.h:110
Point operator-(const Point &a, const Point &b)
Definition Point.h:116
Point operator/(const Point &p, double s)
Definition Point.h:140
bool operator!=(const Point &a, const Point &b)
Definition Point.h:184
bool operator==(const Point &a, const Point &b)
Definition Point.h:178
double operator*(const Point &a, const Point &b)
Definition Point.h:122
Struct representing a 2D point.
Definition Point.h:27
Point & operator-=(const Point &other)
Definition Point.h:154
Point operator-()
Definition Point.h:226
Point & operator+=(const Point &other)
Definition Point.h:146
Point & operator/=(double s)
Definition Point.h:170
double y
Definition Point.h:30
void get(double &xout, double &yout) const
Definition Point.h:103
Point & operator*=(double s)
Definition Point.h:162
Point rotated(double angle) const
Definition Point.h:200
Point(double xc, double yc)
Definition Point.h:58
Point(const Point &other)
Definition Point.h:43
double x
Definition Point.h:29
Point & rotate(double angle)
Definition Point.h:190
double norm() const
Definition Point.h:221
Point & operator=(const Point &other)=default
MyPointD Point