1 // Boost.Polygon library interval_data.hpp header file
2 
3 // Copyright (c) Intel Corporation 2008.
4 // Copyright (c) 2008-2012 Simonson Lucanus.
5 // Copyright (c) 2012-2012 Andrii Sydorchuk.
6 
7 // See http://www.boost.org for updates, documentation, and revision history.
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 
12 #ifndef BOOST_POLYGON_INTERVAL_DATA_HPP
13 #define BOOST_POLYGON_INTERVAL_DATA_HPP
14 
15 #include "isotropy.hpp"
16 #include "interval_concept.hpp"
17 
18 namespace boost {
19 namespace polygon {
20 
21 template <typename T>
22 class interval_data {
23  public:
24   typedef T coordinate_type;
25 
interval_data()26   interval_data()
27 #ifndef BOOST_POLYGON_MSVC
28     : coords_()
29 #endif
30   {}
31 
interval_data(coordinate_type low,coordinate_type high)32   interval_data(coordinate_type low, coordinate_type high) {
33     coords_[LOW] = low;
34     coords_[HIGH] = high;
35   }
36 
interval_data(const interval_data & that)37   interval_data(const interval_data& that) {
38     coords_[0] = that.coords_[0];
39     coords_[1] = that.coords_[1];
40   }
41 
operator =(const interval_data & that)42   interval_data& operator=(const interval_data& that) {
43     coords_[0] = that.coords_[0];
44     coords_[1] = that.coords_[1];
45     return *this;
46   }
47 
48   template <typename IntervalType>
operator =(const IntervalType & that)49   interval_data& operator=(const IntervalType& that) {
50     assign(*this, that);
51     return *this;
52   }
53 
get(direction_1d dir) const54   coordinate_type get(direction_1d dir) const {
55     return coords_[dir.to_int()];
56   }
57 
set(direction_1d dir,coordinate_type value)58   void set(direction_1d dir, coordinate_type value) {
59     coords_[dir.to_int()] = value;
60   }
61 
low() const62   coordinate_type low() const {
63     return coords_[0];
64   }
65 
low(coordinate_type value)66   interval_data& low(coordinate_type value) {
67     coords_[LOW] = value;
68     return *this;
69   }
70 
high() const71   coordinate_type high() const {
72     return coords_[1];
73   }
74 
high(coordinate_type value)75   interval_data& high(coordinate_type value) {
76     coords_[HIGH] = value;
77     return *this;
78   }
79 
operator ==(const interval_data & that) const80   bool operator==(const interval_data& that) const {
81     return low() == that.low() && high() == that.high();
82   }
83 
operator !=(const interval_data & that) const84   bool operator!=(const interval_data& that) const {
85     return low() != that.low() || high() != that.high();
86   }
87 
operator <(const interval_data & that) const88   bool operator<(const interval_data& that) const {
89     if (coords_[0] != that.coords_[0]) {
90       return coords_[0] < that.coords_[0];
91     }
92     return coords_[1] < that.coords_[1];
93   }
94 
operator <=(const interval_data & that) const95   bool operator<=(const interval_data& that) const {
96     return !(that < *this);
97   }
98 
operator >(const interval_data & that) const99   bool operator>(const interval_data& that) const {
100     return that < *this;
101   }
102 
operator >=(const interval_data & that) const103   bool operator>=(const interval_data& that) const {
104     return !((*this) < that);
105   }
106 
107  private:
108   coordinate_type coords_[2];
109 };
110 
111 template <typename CType>
112 struct geometry_concept< interval_data<CType> > {
113   typedef interval_concept type;
114 };
115 }  // polygon
116 }  // boost
117 
118 #endif  // BOOST_POLYGON_INTERVAL_DATA_HPP
119