// Copyright (c) 1999 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), // and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Homogeneous_kernel/include/CGAL/Homogeneous/distance_predicatesH3.h $ // $Id: distance_predicatesH3.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // // Author(s) : Stefan Schirra #ifndef CGAL_DISTANCE_PREDICATESH3_H #define CGAL_DISTANCE_PREDICATESH3_H namespace CGAL { template Comparison_result compare_distance_to_point(const PointH3& , const PointH3& , const PointH3& ); template bool has_larger_distance_to_point(const PointH3& , const PointH3& , const PointH3& ); template bool has_smaller_distance_to_point(const PointH3& , const PointH3& , const PointH3& ); template Comparison_result compare_signed_distance_to_plane(const PlaneH3& , const PointH3& , const PointH3& ); template bool has_larger_signed_distance_to_plane(const PlaneH3& , const PointH3& , const PointH3& ); template bool has_smaller_signed_distance_to_plane(const PlaneH3&, const PointH3& , const PointH3& ); template Comparison_result compare_signed_distance_to_plane(const PointH3& , const PointH3& , const PointH3& , const PointH3& , const PointH3& ); template bool has_larger_signed_distance_to_plane(const PointH3& , const PointH3& , const PointH3& , const PointH3& , const PointH3& ); template bool has_smaller_signed_distance_to_plane(const PointH3& , const PointH3& , const PointH3& , const PointH3& , const PointH3& ); template CGAL_KERNEL_MEDIUM_INLINE Comparison_result compare_distance_to_point(const PointH3& p, const PointH3& q, const PointH3& r) { typedef typename R::RT RT; const RT phx = p.hx(); const RT phy = p.hy(); const RT phz = p.hz(); const RT phw = p.hw(); const RT qhx = q.hx(); const RT qhy = q.hy(); const RT qhz = q.hz(); const RT qhw = q.hw(); const RT rhx = r.hx(); const RT rhy = r.hy(); const RT rhz = r.hz(); const RT rhw = r.hw(); const RT RT0 = RT(0); const RT RT2 = RT(2); RT dosd = // difference of squared distances rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz ) - RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz ) ) - qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz ) - RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz ) ); if ( RT0 < dosd ) { return LARGER; } else { return (dosd < RT0) ? SMALLER : EQUAL; } } template < class R> CGAL_KERNEL_MEDIUM_INLINE bool has_larger_distance_to_point(const PointH3& p, const PointH3& q, const PointH3& r) { typedef typename R::RT RT; const RT phx = p.hx(); const RT phy = p.hy(); const RT phz = p.hz(); const RT phw = p.hw(); const RT qhx = q.hx(); const RT qhy = q.hy(); const RT qhz = q.hz(); const RT qhw = q.hw(); const RT rhx = r.hx(); const RT rhy = r.hy(); const RT rhz = r.hz(); const RT rhw = r.hw(); const RT RT0 = RT(0); const RT RT2 = RT(2); RT dosd = // difference of squared distances rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz ) - RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz ) ) - qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz ) - RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz ) ); return ( RT0 < dosd ); } template < class R> CGAL_KERNEL_MEDIUM_INLINE bool has_smaller_distance_to_point(const PointH3& p, const PointH3& q, const PointH3& r) { typedef typename R::RT RT; const RT phx = p.hx(); const RT phy = p.hy(); const RT phz = p.hz(); const RT phw = p.hw(); const RT qhx = q.hx(); const RT qhy = q.hy(); const RT qhz = q.hz(); const RT qhw = q.hw(); const RT rhx = r.hx(); const RT rhy = r.hy(); const RT rhz = r.hz(); const RT rhw = r.hw(); const RT RT0 = RT(0); const RT RT2 = RT(2); RT dosd = // difference of squared distances rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz ) - RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz ) ) - qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz ) - RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz ) ); return ( dosd < RT0 ); } template < class R> CGAL_KERNEL_INLINE Comparison_result compare_signed_distance_to_plane(const PlaneH3& pl, const PointH3& p, const PointH3& q) { typedef typename R::RT RT; const RT pla = pl.a(); const RT plb = pl.b(); const RT plc = pl.c(); const RT phx = p.hx(); const RT phy = p.hy(); const RT phz = p.hz(); const RT phw = p.hw(); const RT qhx = q.hx(); const RT qhy = q.hy(); const RT qhz = q.hz(); const RT qhw = q.hw(); const RT RT0 = RT(0); RT scaled_dist_p_minus_scaled_dist_q = pla*( phx*qhw - qhx*phw ) + plb*( phy*qhw - qhy*phw ) + plc*( phz*qhw - qhz*phw ); if ( scaled_dist_p_minus_scaled_dist_q < RT0 ) { return SMALLER; } else { return (RT0 < scaled_dist_p_minus_scaled_dist_q ) ? LARGER : EQUAL;} } template bool has_larger_signed_distance_to_plane(const PlaneH3& pl, const PointH3& p, const PointH3& q ) { typedef typename R::RT RT; const RT pla = pl.a(); const RT plb = pl.b(); const RT plc = pl.c(); const RT phx = p.hx(); const RT phy = p.hy(); const RT phz = p.hz(); const RT phw = p.hw(); const RT qhx = q.hx(); const RT qhy = q.hy(); const RT qhz = q.hz(); const RT qhw = q.hw(); const RT RT0 = RT(0); RT scaled_dist_p_minus_scaled_dist_q = pla*( phx*qhw - qhx*phw ) + plb*( phy*qhw - qhy*phw ) + plc*( phz*qhw - qhz*phw ); return ( RT0 < scaled_dist_p_minus_scaled_dist_q ); } template bool has_smaller_signed_distance_to_plane(const PlaneH3& pl, const PointH3& p, const PointH3& q ) { typedef typename R::RT RT; const RT pla = pl.a(); const RT plb = pl.b(); const RT plc = pl.c(); const RT phx = p.hx(); const RT phy = p.hy(); const RT phz = p.hz(); const RT phw = p.hw(); const RT qhx = q.hx(); const RT qhy = q.hy(); const RT qhz = q.hz(); const RT qhw = q.hw(); const RT RT0 = RT(0); RT scaled_dist_p_minus_scaled_dist_q = pla*( phx*qhw - qhx*phw ) + plb*( phy*qhw - qhy*phw ) + plc*( phz*qhw - qhz*phw ); return ( scaled_dist_p_minus_scaled_dist_q < RT0 ); } template inline Comparison_result compare_signed_distance_to_plane(const PointH3& p, const PointH3& q, const PointH3& r, const PointH3& s, const PointH3& t) { CGAL_kernel_precondition( !collinear(p,q,r) ); PlaneH3 P(p,q,r); return cmp_signed_dist_to_plane( P, s, t); } template inline bool has_larger_signed_distance_to_plane(const PointH3& p, const PointH3& q, const PointH3& r, const PointH3& s, const PointH3& t) { return cmp_signed_dist_to_plane(p,q,r,s,t) == LARGER; } template inline bool has_smaller_signed_distance_to_plane(const PointH3& p, const PointH3& q, const PointH3& r, const PointH3& s, const PointH3& t) { return cmp_signed_dist_to_plane(p,q,r,s,t) == SMALLER; } } //namespace CGAL #endif //CGAL_DISTANCE_PREDICATESH3_H