xc
Dir2d.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Dir2d.h
22 
23 #ifndef DIR2D_H
24 #define DIR2D_H
25 
26 #include "../cgal_types.h"
27 #include <iostream>
28 
29 class Vector2d;
30 class FT_matrix;
31 
32 
34 //
36 class Dir2d
37  {
38  CGDirection_2 cgd;
39  public:
40  explicit Dir2d(const CGDirection_2 d): cgd(d) {}
41  Dir2d(const GEOM_FT &x,const GEOM_FT &y);
42  explicit Dir2d(const double &ang);
43  explicit Dir2d(const Vector2d &v);
44  virtual bool operator==(const Dir2d &) const;
45  bool operator!=(const Dir2d &) const;
46  const CGDirection_2 &ToCGAL(void) const
47  { return cgd; }
48  inline int dimension(void) const
49  { return 2; }
50  void Neg(void)
51  { cgd= -cgd; }
52  inline GEOM_FT operator()(const size_t &i) const
53  { return cgd.delta(i-1); }
54  inline GEOM_FT dx(void) const
55  { return cgd.dx(); }
56  inline GEOM_FT dy(void) const
57  { return cgd.dy(); }
59  inline Dir2d Perpendicular(void) const
60  { return Dir2d(-dy(),dx()); }
61  FT_matrix getMatrix(void) const;
62  Vector2d GetVector(void) const;
63  friend std::ostream &operator << (std::ostream &stream,const Dir2d &n);
64  inline virtual ~Dir2d(void) {}
65  };
66 inline Dir2d operator-(const Dir2d &d)
67  {
68  Dir2d retval(d);
69  retval.Neg();
70  return retval;
71  }
72 
73 inline bool parallel(const Dir2d &v1,const Dir2d &v2)
74  { return ((v1==v2) || (v1==-v2)); }
75 
76 #endif
Vector2d GetVector(void) const
returns the x and y components in a vector.
Definition: Dir2d.cc:64
Dirección en dos dimensiones.
Definition: Dir2d.h:36
bool operator!=(const Dir2d &) const
Comparison operator.
Definition: Dir2d.cc:52
FT_matrix getMatrix(void) const
returns the x and y components in a row matrix.
Definition: Dir2d.cc:56
Vector en dos dimensiones.
Definition: Vector2d.h:40
friend std::ostream & operator<<(std::ostream &stream, const Dir2d &n)
insertion into an output operator.
Definition: Dir2d.cc:68
Dir2d Perpendicular(void) const
Return the perpendicular direction in counterclockwise sense.
Definition: Dir2d.h:59
Matrix which components are GEOM_FT numbers.
Definition: FT_matrix.h:40
virtual bool operator==(const Dir2d &) const
Comparison operator.
Definition: Dir2d.cc:41