File indexing completed on 2025-12-16 10:04:53
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_POLYGON_POLYGON_SET_VIEW_HPP
0009 #define BOOST_POLYGON_POLYGON_SET_VIEW_HPP
0010 namespace boost { namespace polygon{
0011
0012
0013 template <typename coordinate_type>
0014 inline void polygon_set_data<coordinate_type>::clean() const {
0015 if(dirty_) {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 sort();
0034 arbitrary_boolean_op<coordinate_type> abo;
0035 polygon_set_data<coordinate_type> tmp2;
0036 abo.execute(tmp2, begin(), end(), end(), end(), 0);
0037 data_.swap(tmp2.data_);
0038 is_45_ = tmp2.is_45_;
0039 dirty_ = false;
0040
0041 }
0042 }
0043
0044 template <>
0045 inline void polygon_set_data<double>::clean() const {
0046 if(dirty_) {
0047 sort();
0048 arbitrary_boolean_op<double> abo;
0049 polygon_set_data<double> tmp2;
0050 abo.execute(tmp2, begin(), end(), end(), end(), 0);
0051 data_.swap(tmp2.data_);
0052 is_45_ = tmp2.is_45_;
0053 dirty_ = false;
0054 }
0055 }
0056
0057 template <typename value_type, typename arg_type>
0058 inline void insert_into_view_arg(value_type& dest, const arg_type& arg);
0059
0060 template <typename ltype, typename rtype, int op_type>
0061 class polygon_set_view;
0062
0063 template <typename ltype, typename rtype, int op_type>
0064 struct polygon_set_traits<polygon_set_view<ltype, rtype, op_type> > {
0065 typedef typename polygon_set_view<ltype, rtype, op_type>::coordinate_type coordinate_type;
0066 typedef typename polygon_set_view<ltype, rtype, op_type>::iterator_type iterator_type;
0067 typedef typename polygon_set_view<ltype, rtype, op_type>::operator_arg_type operator_arg_type;
0068
0069 static inline iterator_type begin(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
0070 static inline iterator_type end(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
0071
0072 static inline bool clean(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
0073
0074 static inline bool sort(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
0075 };
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 template <typename value_type, typename geometry_type_1, typename geometry_type_2, int op_type>
0093 void execute_boolean_op(value_type& output_, const geometry_type_1& lvalue_, const geometry_type_2& rvalue_) {
0094 typedef geometry_type_1 ltype;
0095
0096 typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
0097 value_type linput_;
0098 value_type rinput_;
0099 insert_into_view_arg(linput_, lvalue_);
0100 insert_into_view_arg(rinput_, rvalue_);
0101 polygon_45_set_data<coordinate_type> l45, r45, o45;
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 arbitrary_boolean_op<coordinate_type> abo;
0120 abo.execute(output_, linput_.begin(), linput_.end(),
0121 rinput_.begin(), rinput_.end(), op_type);
0122
0123 }
0124
0125 template <typename ltype, typename rtype, int op_type>
0126 class polygon_set_view {
0127 public:
0128 typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
0129 typedef polygon_set_data<coordinate_type> value_type;
0130 typedef typename value_type::iterator_type iterator_type;
0131 typedef polygon_set_view operator_arg_type;
0132 private:
0133 const ltype& lvalue_;
0134 const rtype& rvalue_;
0135 mutable value_type output_;
0136 mutable bool evaluated_;
0137 polygon_set_view& operator=(const polygon_set_view&);
0138 public:
0139 polygon_set_view(const ltype& lvalue,
0140 const rtype& rvalue ) :
0141 lvalue_(lvalue), rvalue_(rvalue), output_(), evaluated_(false) {}
0142
0143
0144 public:
0145 const value_type& value() const {
0146 if(!evaluated_) {
0147 evaluated_ = true;
0148 execute_boolean_op<value_type, ltype, rtype, op_type>(output_, lvalue_, rvalue_);
0149 }
0150 return output_;
0151 }
0152 public:
0153 iterator_type begin() const { return value().begin(); }
0154 iterator_type end() const { return value().end(); }
0155
0156 bool dirty() const { return false; }
0157 bool sorted() const { return true; }
0158
0159 void sort() const {}
0160 };
0161
0162 template <typename ltype, typename rtype, int op_type>
0163 typename polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::iterator_type
0164 polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
0165 begin(const polygon_set_view<ltype, rtype, op_type>& polygon_set) {
0166 return polygon_set.begin();
0167 }
0168 template <typename ltype, typename rtype, int op_type>
0169 typename polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::iterator_type
0170 polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
0171 end(const polygon_set_view<ltype, rtype, op_type>& polygon_set) {
0172 return polygon_set.end();
0173 }
0174 template <typename ltype, typename rtype, int op_type>
0175 bool polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
0176 clean(const polygon_set_view<ltype, rtype, op_type>& ) {
0177 return true; }
0178 template <typename ltype, typename rtype, int op_type>
0179 bool polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
0180 sort(const polygon_set_view<ltype, rtype, op_type>& ) {
0181 return true; }
0182
0183 template <typename value_type, typename arg_type>
0184 inline void insert_into_view_arg(value_type& dest, const arg_type& arg) {
0185 typedef typename polygon_set_traits<arg_type>::iterator_type literator;
0186 literator itr1, itr2;
0187 itr1 = polygon_set_traits<arg_type>::begin(arg);
0188 itr2 = polygon_set_traits<arg_type>::end(arg);
0189 dest.insert(itr1, itr2);
0190 }
0191
0192 template <typename geometry_type_1, typename geometry_type_2, int op_type>
0193 geometry_type_1& self_assignment_boolean_op(geometry_type_1& lvalue_, const geometry_type_2& rvalue_) {
0194 typedef geometry_type_1 ltype;
0195 typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
0196 typedef polygon_set_data<coordinate_type> value_type;
0197 value_type output_;
0198 execute_boolean_op<value_type, geometry_type_1, geometry_type_2, op_type>(output_, lvalue_, rvalue_);
0199 polygon_set_mutable_traits<geometry_type_1>::set(lvalue_, output_.begin(), output_.end());
0200 return lvalue_;
0201 }
0202
0203
0204 template <typename coordinate_type>
0205 template <typename ltype, typename rtype, int op_type>
0206 polygon_set_data<coordinate_type>::polygon_set_data(const polygon_set_view<ltype, rtype, op_type>& that) :
0207 data_(that.value().data_), dirty_(that.value().dirty_), unsorted_(that.value().unsorted_), is_45_(that.value().is_45_) {}
0208
0209
0210 template <typename coordinate_type>
0211 inline bool polygon_set_data<coordinate_type>::operator==(const polygon_set_data<coordinate_type>& p) const {
0212 typedef polygon_set_data<coordinate_type> value_type;
0213 value_type output_;
0214 execute_boolean_op<value_type, value_type, value_type, 2>(output_, (*this), p);
0215 return output_.data_.empty();
0216 }
0217
0218 template <typename ltype, typename rtype, int op_type>
0219 struct geometry_concept<polygon_set_view<ltype, rtype, op_type> > { typedef polygon_set_concept type; };
0220 }
0221 }
0222 #endif