Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
include/CGAL/SimpleCartesian/PointS2.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: PointS2.h,v 1.3 2008/12/06 08:43:27 mtcampbe Exp $
24 
25 #ifndef CGAL_OPT_SIMPLE_CARTESIAN_POINT_2_H
26 #define CGAL_OPT_SIMPLE_CARTESIAN_POINT_2_H
27 
29 
30 template <class FT>
31 class PointS2 {
32  typedef PointS2<FT> Self;
35 public:
36  PointS2() {}
37  // PointS2(const Self &v); // use default copy
38  PointS2(const Origin &) : _x(0), _y(0) {}
39  PointS2(const FT &hx, const FT &hy, const FT &hw) : _x(hx/hw), _y(hy/hw) {}
40  PointS2(const FT &x, const FT &y) : _x(x), _y(y) {}
41  ~PointS2() {}
42 
43  Self &operator=(const Self &p) { _x = p._x; _y = p._y; return *this; }
44 
45  bool operator==(const Self &p) const { return x()==p.x() && y()==p.y(); }
46  bool operator==(const Origin &) const { return x()==FT(0) && y()==FT(0); }
47  bool operator<(const Self& p) const
48  { return lexicographically_xy_smaller(*this, p); }
49 
50  int id() const { return (int)this; }
51 
52  FT hx() const { return x(); }
53  FT hy() const { return y(); }
54  FT hw() const { return FT(1); }
55  FT homogeneous(int i) const { return (i == 2) ? FT(1) : cartesian(i); }
56 
57  const FT& x() const { return _x; }
58  const FT& y() const { return _y; }
59  FT& x() { return _x; }
60  FT& y() { return _y; }
61 
62  const FT& cartesian(int i) const {
63  CGAL_kernel_precondition( (i == 0) || (i == 1) );
64  return (i == 0) ? x() : y();
65  }
66 
67  FT& cartesian(int i) {
68  CGAL_kernel_precondition( (i == 0) || (i == 1) );
69  return (i == 0) ? x() : y();
70  }
71 
72  FT& operator[](int i) { return cartesian(i); }
73  const FT& operator[](int i) const { return cartesian(i); }
74 
75  int dimension() const { return 2; }
76 
77  Self& operator+=(const Vector &v) {
78  _x += v.x(); _y+=v.y();
79  return *this;
80  }
81  Self& operator-=(const Vector &v) {
82  _x -= v.x(); _y-=v.y();
83  return *this;
84  }
85 
86  Bbox_2 bbox() const { return Bbox_2(x(),y(),x(),y()); }
87 
89  { return t.transform(*this); }
90 
91 private:
92  FT _x,_y;
93 };
94 
96 
97 #include <CGAL/Origin.h>
98 #include <CGAL/SimpleCartesian/VectorS2.h>
100 #include <CGAL/Bbox_2.h>
101 #include <CGAL/number_utils.h>
102 
104 
105 template < class FT >
106 inline
109 { return PointS2<FT>(p.x() + v.x(), p.y() + v.y()) ; }
110 
111 template < class FT >
112 inline
115 { return PointS2<FT>(p.x() - v.x(), p.y() - v.y()) ; }
116 
117 template < class FT >
118 inline
120 operator+(const Origin& , const VectorS2<FT>& v)
121 { return PointS2<FT>(v) ; }
122 
123 template < class FT >
124 inline
126 { return PointS2<FT>(-v) ; }
127 
128 template < class FT >
129 inline
132 { return VectorS2<FT>(p.x() - q.x(), p.y() - q.y()) ; }
133 
134 template < class FT >
135 inline
137 operator-(const PointS2<FT>& p, const Origin& )
138 { return VectorS2<FT>(p) ; }
139 
140 template < class FT >
141 inline
143 operator-(const Origin& , const PointS2<FT>& p)
144 { return VectorS2<FT>(-p.x(), -p.y()) ; }
145 
146 
147 #ifndef CGAL_NO_OSTREAM_INSERT_POINTS2
148 template < class FT >
149 std::ostream&
150 operator<<(std::ostream& os, const PointS2<FT>& p)
151 {
152  switch(os.iword(IO::mode))
153  {
154  case IO::ASCII :
155  return os << p.x() << ' ' << p.y();
156  case IO::BINARY :
157  write(os, p.x());
158  write(os, p.y());
159  return os;
160  default:
161  return os << "PointS2(" << p.x() << ", " << p.y() << ')';
162  }
163 }
164 #endif // CGAL_NO_OSTREAM_INSERT_POINTS2
165 
166 #ifndef CGAL_NO_ISTREAM_EXTRACT_POINTS2
167 template < class FT >
168 std::istream&
169 operator>>(std::istream& is, PointS2<FT>& p)
170 {
171  FT x, y;
172  switch(is.iword(IO::mode))
173  {
174  case IO::ASCII :
175  is >> x >> y;
176  break;
177  case IO::BINARY :
178  read(is, x);
179  read(is, y);
180  break;
181  default:
182  CGAL_kernel_assertion_msg(false,"Stream must be in ascii or binary mode");
183  // throw ios_base::failure("Stream must be in ascii or binary mode");
184  }
185  p = PointS2<FT>(x, y);
186  return is;
187 }
188 #endif // CGAL_NO_ISTREAM_EXTRACT_POINTS2
189 
191 
192 #endif // CGAL_OPT_SIMPLE_CARTESIAN_POINT_2_H
193 
194 
195 
196 
197 
198 
Self & operator+=(const Vector &v)
Aff_transformationS2< FT > Aff_transformation
PointS2(const FT &hx, const FT &hy, const FT &hw)
void int int REAL REAL * y
Definition: read.cpp:74
#define CGAL_kernel_assertion_msg(EX, MSG)
bool lexicographically_xy_smaller(const Point_2< R > &p, const Point_2< R > &q)
Iterator_from_circulator< C, Ref, Ptr > operator+(Dist n, const Iterator_from_circulator< C, Ref, Ptr > &circ)
Definition: circulator.h:689
Self & operator=(const Self &p)
const FT & operator[](int i) const
bool operator<(const Self &p) const
*********************************************************************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
Self & operator-=(const Vector &v)
const FT & cartesian(int i) const
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
bool operator==(const Origin &) const
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
Self transform(const Aff_transformation &t) const
static int mode
Definition: io.h:63
Definition: io.h:64
PointS2< FT > transform(const PointS2< FT > &p) const
NT q
bool operator==(const Self &p) 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)
PointS2(const FT &x, const FT &y)
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
#define CGAL_kernel_precondition(EX)
Point_2< R > operator-(const Origin &o, const Vector_2< R > &v)