1 // Copyright (c) 1997-2000 Max-Planck-Institute Saarbruecken (Germany). 2 // All rights reserved. 3 // 4 // This file is part of CGAL (www.cgal.org). 5 // 6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Nef_2/include/CGAL/Nef_2/Line_to_epoint.h $ 7 // $Id: Line_to_epoint.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot 8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial 9 // 10 // 11 // Author(s) : Michael Seel <seel@mpi-sb.mpg.de> 12 13 #ifndef CGAL_LINE_TO_EPOINT_H 14 #define CGAL_LINE_TO_EPOINT_H 15 16 #include <CGAL/license/Nef_2.h> 17 18 19 namespace CGAL { 20 21 template <class Kernel_> 22 struct Line_to_epoint { 23 typedef Kernel_ Kernel; 24 typedef typename Kernel::RT RT; 25 typedef typename Kernel::FT FT; 26 typedef typename Kernel::Line_2 Line_2; 27 enum Point_type { SWCORNER=1, LEFTFRAME, NWCORNER, 28 BOTTOMFRAME, STANDARD, TOPFRAME, 29 SECORNER, RIGHTFRAME, NECORNER }; 30 31 dxLine_to_epoint32 static RT dx(const Line_2& l) { return l.b(); } dyLine_to_epoint33 static RT dy(const Line_2& l) { return -l.a(); } 34 ordinate_distanceLine_to_epoint35 static FT ordinate_distance(const Line_2& l) { 36 return FT(-l.c()) / l.b(); 37 } 38 determine_typeLine_to_epoint39 static Point_type determine_type(const Line_2& l) 40 { 41 RT adx = CGAL_NTS abs(dx(l)), ady = CGAL_NTS abs(dy(l)); 42 int sdx = CGAL_NTS sign(dx(l)), sdy = CGAL_NTS sign(dy(l)); 43 int cmp_dx_dy = CGAL_NTS compare(adx,ady), s(1); 44 if ( (sdx < 0) && ( (cmp_dx_dy > 0) || ( (cmp_dx_dy == 0) && 45 (sdy != (s = CGAL_NTS sign(ordinate_distance(l))))))) { 46 if (0 == s) return ( sdy < 0 ? SWCORNER : NWCORNER ); 47 else return LEFTFRAME; 48 } else if ( (sdx > 0) && ( (cmp_dx_dy > 0) || ( (cmp_dx_dy == 0) && 49 (sdy != (s = CGAL_NTS sign(ordinate_distance(l))))))) { 50 if (0 == s) return ( sdy < 0 ? SECORNER : NECORNER ); 51 else return RIGHTFRAME; 52 } else if ( (sdy < 0) && ( (cmp_dx_dy < 0) || ( (cmp_dx_dy == 0) && 53 (ordinate_distance(l) < FT(0))))) { 54 return BOTTOMFRAME; 55 } else if ( (sdy > 0) && ( (cmp_dx_dy < 0) || ( (cmp_dx_dy == 0) && 56 (ordinate_distance(l) > FT(0))))) { 57 return TOPFRAME; 58 } 59 CGAL_error_msg(" determine_type: degenerate line."); 60 return (Point_type)-1; // never come here 61 } 62 63 64 }; 65 66 } //namespace CGAL 67 #endif //CGAL_LINE_TO_EPOINT_H 68