1 // Copyright (c) 1999,2016
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/predicates_on_pointsH3.h $
11 // $Id: predicates_on_pointsH3.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, Olivier Devillers, Mariette Yvinec
16
17
18 #ifndef CGAL_PREDICATES_ON_POINTSH3_H
19 #define CGAL_PREDICATES_ON_POINTSH3_H
20
21 #include <CGAL/Homogeneous/PointH3.h>
22 #include <CGAL/predicates/kernel_ftC3.h>
23
24 namespace CGAL {
25
26 template < class R >
27 CGAL_KERNEL_MEDIUM_INLINE
lexicographically_xy_smaller(const PointH3<R> & p,const PointH3<R> & q)28 bool lexicographically_xy_smaller(const PointH3<R> &p,
29 const PointH3<R> &q)
30 {
31 typedef typename R::RT RT;
32 RT pV = p.hx()*q.hw();
33 RT qV = q.hx()*p.hw();
34 if ( pV < qV )
35 {
36 return true;
37 }
38 if ( qV < pV )
39 {
40 return false;
41 }
42 // same x
43 pV = p.hy()*q.hw();
44 qV = q.hy()*p.hw();
45 if ( pV < qV )
46 {
47 return true;
48 }
49 return false;
50 }
51
52 template < class R>
53 CGAL_KERNEL_MEDIUM_INLINE
54 Comparison_result
compare_xy(const PointH3<R> & p,const PointH3<R> & q)55 compare_xy(const PointH3<R>& p, const PointH3<R>& q)
56 {
57 typedef typename R::RT RT;
58 RT pV = p.hx()*q.hw();
59 RT qV = q.hx()*p.hw();
60 if ( pV < qV )
61 {
62 return SMALLER;
63 }
64 if ( qV < pV ) // ( pV > qV )
65 {
66 return LARGER;
67 }
68 // same x
69 pV = p.hy()*q.hw();
70 qV = q.hy()*p.hw();
71 if ( pV < qV )
72 {
73 return SMALLER;
74 }
75 if ( qV < pV ) // ( pV > qV )
76 {
77 return LARGER;
78 }
79 // same x and y
80 return EQUAL;
81 }
82
83 template < class R >
84 CGAL_KERNEL_INLINE
85 bool
equal_xy(const PointH3<R> & p,const PointH3<R> & q)86 equal_xy(const PointH3<R> &p, const PointH3<R> &q)
87 {
88 return (p.hx() * q.hw() == q.hx() * p.hw() )
89 && (p.hy() * q.hw() == q.hy() * p.hw() );
90 }
91
92 template < class R > // ??? -> ==
93 CGAL_KERNEL_INLINE
94 bool
equal_xyz(const PointH3<R> & p,const PointH3<R> & q)95 equal_xyz(const PointH3<R> &p, const PointH3<R> &q)
96 {
97 return (p.hx() * q.hw() == q.hx() * p.hw() )
98 && (p.hy() * q.hw() == q.hy() * p.hw() )
99 && (p.hz() * q.hw() == q.hz() * p.hw() );
100 }
101
102 template < class R >
103 CGAL_KERNEL_INLINE
104 bool
less_x(const PointH3<R> & p,const PointH3<R> & q)105 less_x(const PointH3<R> &p, const PointH3<R> &q)
106 { return (p.hx() * q.hw() < q.hx() * p.hw() ); }
107
108
109 template < class R >
110 CGAL_KERNEL_INLINE
111 bool
less_y(const PointH3<R> & p,const PointH3<R> & q)112 less_y(const PointH3<R> &p, const PointH3<R> &q)
113 { return (p.hy() * q.hw() < q.hy() * p.hw() ); }
114
115 template < class R >
116 CGAL_KERNEL_INLINE
117 bool
less_z(const PointH3<R> & p,const PointH3<R> & q)118 less_z(const PointH3<R> &p, const PointH3<R> &q)
119 { return (p.hz() * q.hw() < q.hz() * p.hw() ); }
120
121
122
123 template <class RT>
124 Oriented_side
power_side_of_oriented_power_sphereH3(const RT & phx,const RT & phy,const RT & phz,const RT & phw,const Quotient<RT> & pwt,const RT & qhx,const RT & qhy,const RT & qhz,const RT & qhw,const Quotient<RT> & qwt,const RT & rhx,const RT & rhy,const RT & rhz,const RT & rhw,const Quotient<RT> & rwt,const RT & shx,const RT & shy,const RT & shz,const RT & shw,const Quotient<RT> & swt,const RT & thx,const RT & thy,const RT & thz,const RT & thw,const Quotient<RT> & twt)125 power_side_of_oriented_power_sphereH3(
126 const RT &phx, const RT &phy, const RT &phz, const RT &phw, const Quotient<RT> &pwt,
127 const RT &qhx, const RT &qhy, const RT &qhz, const RT &qhw, const Quotient<RT> &qwt,
128 const RT &rhx, const RT &rhy, const RT &rhz, const RT &rhw, const Quotient<RT> &rwt,
129 const RT &shx, const RT ­, const RT &shz, const RT &shw, const Quotient<RT> &swt,
130 const RT &thx, const RT &thy, const RT &thz, const RT &thw, const Quotient<RT> &twt)
131 {
132 RT npwt = pwt.numerator();
133 RT dpwt = pwt.denominator();
134 RT nqwt = qwt.numerator();
135 RT dqwt = qwt.denominator();
136 RT nrwt = rwt.numerator();
137 RT drwt = rwt.denominator();
138 RT nswt = swt.numerator();
139 RT dswt = swt.denominator();
140 RT ntwt = twt.numerator();
141 RT dtwt = twt.denominator();
142
143 RT dphx = phx*phw;
144 RT dphy = phy*phw;
145 RT dphz = phz*phw;
146 RT dphw = CGAL_NTS square(phw);
147 RT dpz = (CGAL_NTS square(phx) + CGAL_NTS square(phy) +
148 CGAL_NTS square(phz))*dpwt - npwt*dphw;
149
150 RT dqhx = qhx*qhw;
151 RT dqhy = qhy*qhw;
152 RT dqhz = qhz*qhw;
153 RT dqhw = CGAL_NTS square(qhw);
154 RT dqz = (CGAL_NTS square(qhx) + CGAL_NTS square(qhy) +
155 CGAL_NTS square(qhz))*dqwt - nqwt*dqhw;
156
157 RT drhx = rhx*rhw;
158 RT drhy = rhy*rhw;
159 RT drhz = rhz*rhw;
160 RT drhw = CGAL_NTS square(rhw);
161 RT drz = (CGAL_NTS square(rhx) + CGAL_NTS square(rhy) +
162 CGAL_NTS square(rhz))*drwt - nrwt*drhw;
163
164 RT dshx = shx*shw;
165 RT dshy = shy*shw;
166 RT dshz = shz*shw;
167 RT dshw = CGAL_NTS square(shw);
168 RT dsz = (CGAL_NTS square(shx) + CGAL_NTS square(shy) +
169 CGAL_NTS square(shz))*dswt - nswt*dshw;
170
171 RT dthx = thx*thw;
172 RT dthy = thy*thw;
173 RT dthz = thz*thw;
174 RT dthw = CGAL_NTS square(thw);
175 RT dtz = (CGAL_NTS square(thx) + CGAL_NTS square(thy) +
176 CGAL_NTS square(thz))*dtwt - ntwt*dthw;
177
178 dthx *= dtwt;
179 dthy *= dtwt;
180 dthz *= dtwt;
181 dthw *= dtwt;
182
183 return - sign_of_determinant(dphx, dphy, dphz, dpz, dphw,
184 dqhx, dqhy, dqhz, dqz, dqhw,
185 drhx, drhy, drhz, drz, drhw,
186 dshx, dshy, dshz, dsz, dshw,
187 dthx, dthy, dthz, dtz, dthw);
188 }
189
190 // The 2 degenerate are not speed critical, and they are quite boring and error
191 // prone to write, so we use the Cartesian version, using FT.
192
193 } //namespace CGAL
194
195 #endif // CGAL_PREDICATES_ON_POINTSH3_H
196