1 // Copyright (c) 2003, 2005 GeometryFactory
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/Interval_skip_list/include/CGAL/Level_interval.h $
7 // $Id: Level_interval.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)     : Andreas Fabri
12 
13 #ifndef CGAL_LEVEL_INTERVAL_H
14 #define CGAL_LEVEL_INTERVAL_H
15 
16 #include <CGAL/license/Interval_skip_list.h>
17 
18 
19 #include <CGAL/Kernel_traits.h>
20 #include <iostream>
21 
22 
23 namespace CGAL {
24 
25   template <class FaceHandle>
26   class Level_interval
27   {
28   public:
29     typedef typename FaceHandle::value_type Face;
30     typedef typename Face::Vertex_handle::value_type Vertex;
31     typedef typename Vertex::Point Point;
32     typedef typename Kernel_traits<Point>::Kernel K;
33     typedef typename K::FT Value;
34 
35 
36   private:
37     FaceHandle fh_;
38     Value inf_;
39     Value sup_;  // left and right boundary values
40   public:
41 
Level_interval()42     Level_interval(){}
43     Level_interval(FaceHandle fh);
inf()44     const Value& inf() const {return inf_;}
sup()45     const Value& sup() const {return sup_;}
face_handle()46     FaceHandle face_handle() const { return fh_;}
47     bool contains(const Value& V) const;
48 
49     // true iff this contains (l,r)
50     bool contains_interval(const Value& l, const Value& r) const;
51 
52     bool operator==(const Level_interval& I) const
53     {
54       // there is no need to compare inf and sup, as these are derived from the face
55       return face_handle() == I.face_handle();
56     }
57 
58     bool operator!=(const Level_interval& I) const
59     {
60       return face_handle() != I.face_handle();
61     }
62   };
63 
64 
65 
66   template <class V>
67   std::ostream& operator<<(std::ostream& os,
68                            const Level_interval<V>& i)
69   {
70     os << i.face_handle()->vertex(0)->point() << ", " <<
71       i.face_handle()->vertex(1)->point() << ", " <<
72       i.face_handle()->vertex(2)->point() << std::endl;
73     return os;
74   }
75 
76 
77   template <class FaceHandle>
Level_interval(FaceHandle fh)78   Level_interval<FaceHandle>::Level_interval(FaceHandle fh)
79     : fh_(fh), inf_(fh->vertex(0)->point().z()), sup_(inf_)
80   {
81     double z = fh->vertex(1)->point().z();
82     sup_= (z>sup_)? z : sup_;
83     inf_ = (z<inf_) ? z : inf_;
84     z = fh->vertex(2)->point().z();
85     sup_ = (z>sup_)? z : sup_;
86     inf_ = (z<inf_) ? z : inf_;
87   }
88 
89 
90   template <class FaceHandle>
91   bool
contains_interval(const Value & i,const Value & s)92   Level_interval<FaceHandle>::contains_interval(const Value& i,
93                                                const Value& s) const
94     // true iff this contains (l,r)
95   {
96     return( (inf() <= i) && (sup() >= s) );
97   }
98 
99 
100   template <class FaceHandle>
101   bool
contains(const Value & v)102   Level_interval<FaceHandle>::contains(const Value& v) const
103   {
104     // return true if this contains V, false otherwise
105     if((v >= inf()) && (v <= sup()))
106       return true;
107     else
108       return false;
109   }
110 
111 
112 
113 
114 } // namespace CGAL
115 
116 #endif // CGAL_LEVEL_INTERVAL_H
117