Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
include/CGAL/SimpleCartesian/VectorS2.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: VectorS2.h,v 1.4 2008/12/06 08:43:27 mtcampbe Exp $
24 
25 #ifndef CGAL_OPT_SIMPLE_CARTESIAN_VECTOR_2_H
26 #define CGAL_OPT_SIMPLE_CARTESIAN_VECTOR_2_H
27 
29 
30 template <class FT>
31 class VectorS2 {
32 public:
33  typedef VectorS2<FT> Self;
36 
37  VectorS2() {}
38  // VectorS2(const Self &v); // use default copy
39  VectorS2(const Null_vector &) : _x(0), _y(0) {}
40  VectorS2(const FT &hx, const FT &hy, const FT &hw) : _x(hx/hw), _y(hy/hw) {}
41  VectorS2(const FT &x, const FT &y) : _x(x), _y(y) {}
42  ~VectorS2() {}
43 
44  Self &operator=(const Self &v) { _x=v._x; _y=v._y; return *this; }
45 
46  bool operator==(const Self &v) const { return _x==v._x && _y==v._y; }
47  bool operator==(const Null_vector &) const { return _x==FT(0) && _y==FT(0); }
48 
49  int id() const { return (int)this; }
50 
51  FT hx() const { return _x; }
52  FT hy() const { return _y; }
53  FT hw() const { return FT(1); }
54  FT homogeneous(int i) const { return (i == 2) ? FT(1) : cartesian(i); }
55 
56  const FT& x() const { return _x; }
57  const FT& y() const { return _y; }
58  FT& x() { return _x; }
59  FT& y() { return _y; }
60 
61  const FT& cartesian(int i) const {
62  CGAL_kernel_precondition( (i == 0) || (i == 1) );
63  return (i == 0) ? _x : _y;
64  }
65 
66  FT& cartesian(int i) {
67  CGAL_kernel_precondition( (i == 0) || (i == 1) );
68  return (i == 0) ? _x : _y;
69  }
70 
71  FT& operator[](int i) { return cartesian(i); }
72  const FT& operator[](int i) const { return cartesian(i); }
73 
74  int dimension() const { return 2; }
75 
76  Self operator+(const Self &v) const { return Self(_x + v._x, _y + v._y); }
77  Self operator-(const Self &v) const { return Self(_x - v._x, _y - v._y); }
78  Self operator-(const Null_vector&) const { return *this; }
79  Self operator-() const { return Self(-_x, -_y); }
80 
81  FT operator*(const Self &v) const { return _x * v._x + _y * v._y; }
82  Self operator/(const FT &c) const { return Self( _x/c, _y/c); }
83 
84 
85  Self& operator+=(const Self &v) {
86  _x += v._x; _y+=v._y;
87  return *this;
88  }
89  Self& operator-=(const Self &v) {
90  _x -= v._x; _y-=v._y;
91  return *this;
92  }
93  Self& operator*=(const FT c)
94  { _x *= c; _y *=c; return *this; }
95  Self& operator/=(const FT c)
96  { _x /= c; _y /=c; return *this; }
97 
98  Self& operator*=(const Self &v)
99  { _x *= v._x; _y *=v._y; return *this; }
100  Self& operator/=(const Self &v)
101  { _x /= v._x; _y /=v._y; return *this; }
102 
103  Self perpendicular(const Orientation &o) const {
105  if (o == COUNTERCLOCKWISE) return Self(-_y, _x);
106  else return Self(_y, -_x);
107  }
109  { return t.transform(*this); }
110 
111  friend class DirectionS2<FT>;
112  const Direction& direction() const
113  { return reinterpret_cast<const Direction&>(*this); }
114 private:
115  FT _x,_y;
116 };
117 
118 template < class _RR >
119 inline VectorS2<_RR> operator*(const _RR &c, const VectorS2<_RR> &v) {
120  return VectorS2<_RR>( c* v.x(), c * v.y());
121 }
122 
123 template < class _RR >
124 std::ostream &operator<<(std::ostream &os, const VectorS2<_RR> &v) {
125  switch(os.iword(IO::mode)) {
126  case IO::ASCII :
127  return os << v.x() << ' ' << v.y();
128  case IO::BINARY :
129  write(os, v.x());
130  write(os, v.y());
131  return os;
132  default:
133  return os << "VectorS2(" << v.x() << ", " << v.y() << ')';
134  }
135 }
136 
137 template < class _RR >
138 std::istream &operator>>(std::istream &is, VectorS2<_RR > &v) {
139  switch(is.iword(IO::mode)) {
140  case IO::ASCII :
141  is >> v.x() >> v.y();
142  break;
143  case IO::BINARY :
144  read(is, v.x());
145  read(is, v.y());
146  break;
147  default:
148  std::cerr << "\nStream must be in ascii or binary mode\n";
149  break;
150  }
151  return is;
152 }
153 
155 
156 #endif // CGAL_OPT_SIMPLE_CARTESIAN_VECTOR_2_H
157 
158 
159 
160 
161 
162 
Vector_3< T > operator*(T t, const Vector_3< T > &v)
Definition: mapbasic.h:139
Self operator-(const Null_vector &) const
const Orientation COUNTERCLOCKWISE
Definition: enum.h:70
Self & operator+=(const Self &v)
Aff_transformationS2< FT > Aff_transformation
Self & operator=(const Self &v)
Self & operator/=(const Self &v)
const FT & cartesian(int i) const
const FT & operator[](int i) const
Self operator/(const FT &c) const
Self operator-(const Self &v) const
const Direction & direction() const
Self & operator-=(const Self &v)
*********************************************************************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
Self perpendicular(const Orientation &o) const
Self transform(const Aff_transformation &t) const
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
VectorS2(const FT &x, const FT &y)
bool operator==(const Null_vector &) const
blockLoc i
Definition: read.cpp:79
VectorS2(const FT &hx, const FT &hy, const FT &hw)
Self operator+(const Self &v) const
static int mode
Definition: io.h:63
Definition: io.h:64
FT operator*(const Self &v) const
VectorS2(const Null_vector &)
Self & operator*=(const Self &v)
PointS2< FT > transform(const PointS2< FT > &p) const
bool operator==(const Self &v) 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)
const Orientation COLLINEAR
Definition: enum.h:72
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
#define CGAL_kernel_precondition(EX)