1 // Copyright (c) 1999
2 // Utrecht University (The Netherlands),
3 // ETH Zurich (Switzerland),
4 // INRIA Sophia-Antipolis (France),
5 // Max-Planck-Institute Saarbruecken (Germany),
6 // and Tel-Aviv University (Israel).  All rights reserved.
7 //
8 // This file is part of CGAL (www.cgal.org)
9 //
10 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Homogeneous_kernel/include/CGAL/Homogeneous/PointH2.h $
11 // $Id: PointH2.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
12 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
13 //
14 //
15 // Author(s)     : Stefan Schirra
16 
17 #ifndef CGAL_HOMOGENEOUS_POINT_2_H
18 #define CGAL_HOMOGENEOUS_POINT_2_H
19 
20 #include <CGAL/Origin.h>
21 #include <boost/utility/enable_if.hpp>
22 #include <boost/type_traits/is_convertible.hpp>
23 #include <boost/mpl/and.hpp>
24 #include <boost/mpl/logical.hpp>
25 
26 namespace CGAL {
27 
28 template < class R_ >
29 class PointH2
30 {
31   typedef typename R_::FT                   FT;
32   typedef typename R_::RT                   RT;
33   typedef typename R_::Vector_2             Vector_2;
34   typedef typename R_::Point_2              Point_2;
35   typedef typename R_::Direction_2          Direction_2;
36 
37   typedef Rational_traits<FT>  Rat_traits;
38 
39   // Reference-counting is handled in Vector_2.
40   Vector_2 base;
41 
42 public:
43 
44   typedef FT Cartesian_coordinate_type;
45   typedef const RT& Homogeneous_coordinate_type;
46   typedef typename Vector_2::Cartesian_const_iterator Cartesian_const_iterator;
47   typedef R_                                    R;
48 
PointH2()49     PointH2() {}
50 
PointH2(const Origin &)51     PointH2(const Origin &)
52       : base(NULL_VECTOR) {}
53 
54     template < typename Tx, typename Ty >
55     PointH2(const Tx & x, const Ty & y,
56             typename boost::enable_if< boost::mpl::and_<boost::is_convertible<Tx, RT>,
57                                                         boost::is_convertible<Ty, RT> > >::type* = 0)
base(x,y)58       : base(x, y) {}
59 
PointH2(const FT & x,const FT & y)60     PointH2(const FT& x, const FT& y)
61       : base(x, y) {}
62 
PointH2(const RT & hx,const RT & hy,const RT & hw)63     PointH2(const RT& hx, const RT& hy, const RT& hw)
64       : base(hx, hy, hw) {}
65 
66     bool    operator==( const PointH2<R>& p) const;
67     bool    operator!=( const PointH2<R>& p) const;
68 
hx()69     const RT & hx() const { return base.hx(); }
hy()70     const RT & hy() const { return base.hy(); }
hw()71     const RT & hw() const { return base.hw(); }
72 
x()73     FT      x()  const { return FT(hx()) / FT(hw()); }
y()74     FT      y()  const { return FT(hy()) / FT(hw()); }
75 
76     FT      cartesian(int i)   const;
77     FT      operator[](int i)  const;
78     const RT & homogeneous(int i) const;
79 
cartesian_begin()80     Cartesian_const_iterator cartesian_begin() const
81     {
82       return base.cartesian_begin();
83     }
84 
cartesian_end()85     Cartesian_const_iterator cartesian_end() const
86     {
87       return base.cartesian_end();
88     }
89 
90     int     dimension() const;
91 
92     Direction_2 direction() const;
93 };
94 
95 template < class R >
96 inline
97 bool
98 PointH2<R>::operator==( const PointH2<R>& p) const
99 {
100   return base == p.base;
101 }
102 
103 template < class R >
104 inline
105 bool
106 PointH2<R>::operator!=( const PointH2<R>& p) const
107 { return !(*this == p); }
108 
109 template < class R >
110 inline
111 typename PointH2<R>::FT
cartesian(int i)112 PointH2<R>::cartesian(int i) const
113 {
114   return base.cartesian(i);
115 }
116 
117 template < class R >
118 inline
119 const typename PointH2<R>::RT &
homogeneous(int i)120 PointH2<R>::homogeneous(int i) const
121 {
122   return base.homogeneous(i);
123 }
124 
125 template < class R >
126 inline
127 typename PointH2<R>::FT
128 PointH2<R>::operator[](int i) const
129 { return base[i]; }
130 
131 
132 template < class R >
133 inline
134 int
dimension()135 PointH2<R>::dimension() const
136 { return base.dimension(); }
137 
138 template < class R >
139 inline
140 typename PointH2<R>::Direction_2
direction()141 PointH2<R>::direction() const
142 { return typename PointH2<R>::Direction_2(*this); }
143 
144 } //namespace CGAL
145 
146 #endif // CGAL_HOMOGENEOUS_POINT_2_H
147