File: Real_embeddable_traits.h

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (172 lines) | stat: -rw-r--r-- 4,839 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright (c) 2006-2007 Max-Planck-Institute Saarbruecken (Germany).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Algebraic_foundations/include/CGAL/Real_embeddable_traits.h $
// $Id: include/CGAL/Real_embeddable_traits.h 08b27d3db14 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Michael Hemmer    <hemmer@mpi-inf.mpg.de>
//
// =============================================================================


#ifndef CGAL_REAL_EMBEDDABLE_TRAITS_H
#define CGAL_REAL_EMBEDDABLE_TRAITS_H

#include <CGAL/Algebraic_structure_traits.h>

namespace CGAL {

namespace INTERN_RET {

template< class T, class AST_is_zero >
struct  Is_zero_selector{ typedef AST_is_zero Type; };

template< class T >
struct Is_zero_selector< T, Null_functor >
{
  struct Type : public CGAL::cpp98::unary_function< T, bool >{
    bool operator()( const T& x ) const {
      return x == T(0);
    }
  };
};

template < class Type_ , class Is_real_embeddable_  >
class Real_embeddable_traits_base{
public:
  typedef Type_                 Type;
  typedef Is_real_embeddable_   Is_real_embeddable;
  typedef Null_tag              Boolean;
  typedef Null_tag              Sign;
  typedef Null_tag              Comparison_result;

  typedef Null_functor Abs;
  typedef Null_functor Sgn;
  typedef Null_functor Is_finite;
  typedef Null_functor Is_positive;
  typedef Null_functor Is_negative;
  typedef Null_functor Is_zero;
  typedef Null_functor Compare;
  typedef Null_functor To_double;
  typedef Null_functor To_interval;
};

template< class Type_ >
class Real_embeddable_traits_base<Type_, CGAL::Tag_true> {
public:
  typedef Type_                    Type;
  typedef Tag_true                 Is_real_embeddable;
  typedef bool                     Boolean;
  typedef CGAL::Sign               Sign;
  typedef CGAL::Comparison_result  Comparison_result;

private:
  typedef typename Algebraic_structure_traits< Type >::Is_zero AST_Is_zero;
public:
  //! The generic \c Is_zero functor implementation uses one comparison
  typedef typename INTERN_RET::Is_zero_selector< Type, AST_Is_zero >::Type
  Is_zero;

  //! The generic \c Is_finite functor returns true
  class Is_finite : public CGAL::cpp98::unary_function< Type, Boolean > {
  public:
    Boolean operator()( const Type& ) const {
      return true;
    }
  };

  //! The generic \c Abs functor implementation
  //! uses one comparisons and the unary minus if necessary.
  class Abs
    : public CGAL::cpp98::unary_function< Type, Type > {
  public:
    //! the function call.
    Type  operator()( const Type& x ) const {
      return( x < Type(0) ) ? -x : x;
    }
  };

  //! The generic \c Sgn functor implementation uses two comparisons.
  class Sgn
    : public CGAL::cpp98::unary_function< Type, ::CGAL::Sign > {
  public:
    //! the function call.
    ::CGAL::Sign operator()( const Type& x ) const {
      if ( x < Type(0))
        return NEGATIVE;
      if ( x > Type(0))
        return POSITIVE;
      return ZERO;
    }
  };

  //! The generic \c Is_positive functor implementation uses one comparison.
  class Is_positive
    : public CGAL::cpp98::unary_function< Type, Boolean > {
  public:
    //! the function call.
    Boolean operator()( const Type& x ) const {
      return x > Type(0);
    }
  };

  //! The generic \c Is_negative functor implementation uses one comparison.
  class Is_negative
    : public CGAL::cpp98::unary_function< Type, Boolean > {
  public:
    //! the function call.
    Boolean operator()( const Type& x ) const {
      return x < Type(0);
    }
  };

  //! The generic \c Compare functor implementation uses two comparisons.
  class Compare
    : public CGAL::cpp98::binary_function< Type, Type,
                                Comparison_result > {
  public:
    //! the function call.
    Comparison_result operator()( const Type& x,
        const Type& y) const {
      if( x < y )
        return SMALLER;
      if( x > y )
        return LARGER;
      return EQUAL;
    }

    CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type,
        Comparison_result )
      };

  class To_double : public CGAL::cpp98::unary_function< Type, double > {
  public:
    double operator()( const Type& x ) const {
      return static_cast<double>(x);
    }
  };

  class To_interval
    : public CGAL::cpp98::unary_function< Type, std::pair<double,double> > {
  public:
    std::pair<double,double> operator()( const Type& x ) const {
      double dx(static_cast<double>(x));
      return std::make_pair(dx,dx);
    }
  };
};

} // INTERN_RET


template< class Type_ >
class Real_embeddable_traits
  : public INTERN_RET::Real_embeddable_traits_base<Type_,CGAL::Tag_false> {};

} //namespace CGAL

#endif  // CGAL_REAL_EMBEDDABLE_TRAITS_H