Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CGAL/include/CGAL/SimpleCartesian/VectorS2.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 1999 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 // release : CGAL-2.2
33 // release_date : 2000, September 30
34 //
35 // source : webS2/S2.lw
36 // file : include/CGAL/SimpleCartesian/VectorS2.h
37 // package : S2 (1.7)
38 // revision : 1.6
39 // revision_date : 27 Jun 2000
40 // author(s) : Stefan Schirra
41 // based on code by
42 // Andreas Fabri and
43 // Herve Brönnimann
44 //
45 // coordinator : MPI, Saarbrücken
46 // email : contact@cgal.org
47 // www : http://www.cgal.org
48 //
49 // ======================================================================
50 
51 #ifndef CGAL_VECTORS2_H
52 #define CGAL_VECTORS2_H
53 
54 #include <CGAL/SimpleCartesian/PointS2.h>
55 
57 
58 template < class FT >
59 class VectorS2
60 {
61 friend class DirectionS2<FT>;
62 
63 public:
64  VectorS2();
65  VectorS2(const Null_vector& );
66  VectorS2(const FT& hx, const FT &hy, const FT &hw);
67  VectorS2(const FT& x, const FT &y);
68 
69 
70  bool operator==(const VectorS2<FT>& v) const;
71  bool operator!=(const VectorS2<FT>& v) const;
72 
73  bool operator==(const Null_vector& ) const;
74  bool operator!=(const Null_vector& p) const;
75 
76  int id() const;
77 
78  FT hx() const;
79  FT hy() const;
80  FT hw() const;
81 
82  FT x() const;
83  FT y() const;
84  FT cartesian(int i) const;
85  FT operator[](int i) const;
86 
87  FT homogeneous(int i) const;
88 
89  int dimension() const;
90 
91  VectorS2<FT> operator+(const VectorS2<FT>& w) const;
92  VectorS2<FT> operator-(const VectorS2<FT>& w) const;
93  VectorS2<FT> operator-() const;
94  FT operator*(const VectorS2<FT>& w) const;
95  VectorS2<FT> operator/(const FT& c) const;
96  DirectionS2<FT> direction() const;
97 
98  VectorS2<FT> perpendicular(const Orientation& o) const;
100 
101 protected:
102  VectorS2(const PointS2<FT>& p);
103  VectorS2(const DirectionS2<FT>& d);
104 public:
105  FT e0;
106  FT e1;
107 };
108 
109 
111 
113 
115 
116 template < class FT >
118 
119 template < class FT >
121 VectorS2<FT>::VectorS2(const Null_vector& ) : e0(FT(0)), e1(FT(0)) {}
122 
123 template < class FT >
125 VectorS2<FT>::VectorS2(const FT& hx, const FT &hy, const FT &hw)
126 {
127  if( hw != FT(1))
128  { e0 = hx/hw; e1 = hy/hw; }
129  else
130  { e0 = hx; e1 = hy; }
131 }
132 
133 template < class FT >
135 VectorS2<FT>::VectorS2(const FT& x, const FT &y) : e0(x), e1(y) {}
136 
137 template < class FT >
140 { e0 = d.e0; e1 = d.e1; }
141 
142 template < class FT >
145 { e0 = d.e0; e1 = d.e1; }
146 
147 template < class FT >
150 { return (x() == v.x()) && (y() == v.y()); }
151 
152 template < class FT >
153 inline
155 { return !(*this == v); }
156 
157 template < class FT >
158 inline
160 { return (x() == FT(0)) && (y() == FT(0)); }
161 
162 template < class FT >
163 inline
165 { return !(*this == v); }
166 
167 template < class FT >
168 inline
169 FT VectorS2<FT>::x() const
170 {
171  return e0;
172 }
173 
174 template < class FT >
175 inline
176 FT VectorS2<FT>::y() const
177 {
178  return e1;
179 }
180 
181 template < class FT >
184 {
185  CGAL_kernel_precondition( (i == 0) || (i == 1) );
186  return (i == 0) ? x() : y();
187 }
188 
189 template < class FT >
190 inline
192 { return cartesian(i); }
193 
194 template < class FT >
195 inline
197 { return 2; }
198 
199 template < class FT >
200 inline
202 { return e0; }
203 
204 template < class FT >
205 inline
207 { return e1; }
208 
209 template < class FT >
210 inline
212 { return FT(1); }
213 
214 template < class FT >
217 { return (i == 2) ? FT(1) : cartesian(i); }
218 
219 template < class FT >
222 { return VectorS2<FT>(x() + w.x(), y() + w.y()) ; }
223 
224 template < class FT >
227 { return VectorS2<FT>(x() - w.x(), y() - w.y()) ; }
228 
229 template < class FT >
232 { return VectorS2<FT>(-x(), -y()) ; }
233 
234 template < class FT >
237 { return x() * w.x() + y() * w.y() ; }
238 
239 template < class FT >
241 VectorS2<FT> operator*(const FT& c, const VectorS2<FT> &w)
242 { return VectorS2<FT>( c* w.x(), c * w.y()) ; }
243 
244 template < class FT >
247 { return VectorS2<FT>( x()/c, y()/c) ; }
248 
249 template < class FT >
250 inline
252 { return DirectionS2<FT>(*this) ; }
253 
254 template < class FT >
257 {
259  if (o == COUNTERCLOCKWISE)
260  return VectorS2<FT>(-y(), x());
261  else
262  return VectorS2<FT>(y(), -x());
263 }
264 
265 template < class FT >
266 inline
268 { return t.transform(*this); }
269 
270 
271 
272 #ifndef CGAL_NO_OSTREAM_INSERT_VECTORS2
273 template < class FT >
274 std::ostream& operator<<(std::ostream &os, const VectorS2<FT> &v)
275 {
276  switch(os.iword(IO::mode)) {
277  case IO::ASCII :
278  return os << v.x() << ' ' << v.y();
279  case IO::BINARY :
280  write(os, v.x());
281  write(os, v.y());
282  return os;
283  default:
284  return os << "VectorS2(" << v.x() << ", " << v.y() << ')';
285  }
286 }
287 #endif // CGAL_NO_OSTREAM_INSERT_VECTORS2
288 
289 #ifndef CGAL_NO_ISTREAM_EXTRACT_VECTORS2
290 template < class FT >
291 std::istream& operator>>(std::istream &is, VectorS2<FT> &p)
292 {
293  FT x, y;
294  switch(is.iword(IO::mode)) {
295  case IO::ASCII :
296  is >> x >> y;
297  break;
298  case IO::BINARY :
299  read(is, x);
300  read(is, y);
301  break;
302  default:
303  std::cerr << "" << std::endl;
304  std::cerr << "Stream must be in ascii or binary mode" << std::endl;
305  break;
306  }
307  p = VectorS2<FT>(x, y);
308  return is;
309 }
310 #endif // CGAL_NO_ISTREAM_EXTRACT_VECTORS2
311 
312 
313 
315 
316 #endif
VectorS2< FT > operator+(const VectorS2< FT > &w) const
#define CGAL_KERNEL_CTOR_INLINE
Definition: kernel_basic.h:57
int id() const
Vector_3< T > operator*(T t, const Vector_3< T > &v)
Definition: mapbasic.h:139
bool operator!=(const VectorS2< FT > &v) const
const NT & d
void int int REAL REAL * y
Definition: read.cpp:74
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
const Orientation COUNTERCLOCKWISE
Definition: enum.h:70
VectorS2< FT > transform(const Aff_transformationS2< FT > &) const
bool operator==(const VectorS2< FT > &v) const
#define CGAL_KERNEL_MEDIUM_INLINE
Definition: kernel_basic.h:55
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
Definition: io.h:64
Sign
Definition: enum.h:57
VectorS2< FT > operator/(const FT &c) const
DirectionS2< FT > direction() const
FT operator*(const VectorS2< FT > &w) const
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
static int mode
Definition: io.h:63
#define CGAL_KERNEL_CTOR_MEDIUM_INLINE
Definition: kernel_basic.h:58
Definition: io.h:64
PointS2< FT > transform(const PointS2< FT > &p) const
VectorS2< FT > perpendicular(const Orientation &o) const
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
VectorS2< FT > operator-() const
const Orientation COLLINEAR
Definition: enum.h:72
#define CGAL_kernel_precondition(EX)
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87