annotate DEPENDENCIES/generic/include/boost/polygon/detail/polygon_set_view.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /*
Chris@16 2 Copyright 2008 Intel Corporation
Chris@16 3
Chris@16 4 Use, modification and distribution are subject to the Boost Software License,
Chris@16 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 http://www.boost.org/LICENSE_1_0.txt).
Chris@16 7 */
Chris@16 8 #ifndef BOOST_POLYGON_POLYGON_SET_VIEW_HPP
Chris@16 9 #define BOOST_POLYGON_POLYGON_SET_VIEW_HPP
Chris@16 10 namespace boost { namespace polygon{
Chris@16 11
Chris@16 12
Chris@16 13 template <typename coordinate_type>
Chris@16 14 inline void polygon_set_data<coordinate_type>::clean() const {
Chris@16 15 if(dirty_) {
Chris@16 16 //polygon_45_set_data<coordinate_type> tmp;
Chris@16 17 //very important:
Chris@16 18 //the 45 degree algorithm does not satisfy
Chris@16 19 //the precondition of arbitrary polygon formation
Chris@16 20 //that vertices be "linearly consistent"
Chris@16 21 //therefore it doesn't work to fall back on 45-degree
Chris@16 22 //booleans for arbitrary angle polygons
Chris@16 23 //if(0) { //downcast(tmp) ) {
Chris@16 24 // tmp.clean();
Chris@16 25 // data_.clear();
Chris@16 26 // is_45_ = true;
Chris@16 27 // polygon_set_data<coordinate_type> tmp2;
Chris@16 28 // tmp2.insert(tmp);
Chris@16 29 // data_.swap(tmp2.data_);
Chris@16 30 // dirty_ = false;
Chris@16 31 // sort();
Chris@16 32 //} else {
Chris@16 33 sort();
Chris@16 34 arbitrary_boolean_op<coordinate_type> abo;
Chris@16 35 polygon_set_data<coordinate_type> tmp2;
Chris@16 36 abo.execute(tmp2, begin(), end(), end(), end(), 0);
Chris@16 37 data_.swap(tmp2.data_);
Chris@16 38 is_45_ = tmp2.is_45_;
Chris@16 39 dirty_ = false;
Chris@16 40 //}
Chris@16 41 }
Chris@16 42 }
Chris@16 43
Chris@16 44 template <>
Chris@16 45 inline void polygon_set_data<double>::clean() const {
Chris@16 46 if(dirty_) {
Chris@16 47 sort();
Chris@16 48 arbitrary_boolean_op<double> abo;
Chris@16 49 polygon_set_data<double> tmp2;
Chris@16 50 abo.execute(tmp2, begin(), end(), end(), end(), 0);
Chris@16 51 data_.swap(tmp2.data_);
Chris@16 52 is_45_ = tmp2.is_45_;
Chris@16 53 dirty_ = false;
Chris@16 54 }
Chris@16 55 }
Chris@16 56
Chris@16 57 template <typename value_type, typename arg_type>
Chris@16 58 inline void insert_into_view_arg(value_type& dest, const arg_type& arg);
Chris@16 59
Chris@16 60 template <typename ltype, typename rtype, int op_type>
Chris@16 61 class polygon_set_view;
Chris@16 62
Chris@16 63 template <typename ltype, typename rtype, int op_type>
Chris@16 64 struct polygon_set_traits<polygon_set_view<ltype, rtype, op_type> > {
Chris@16 65 typedef typename polygon_set_view<ltype, rtype, op_type>::coordinate_type coordinate_type;
Chris@16 66 typedef typename polygon_set_view<ltype, rtype, op_type>::iterator_type iterator_type;
Chris@16 67 typedef typename polygon_set_view<ltype, rtype, op_type>::operator_arg_type operator_arg_type;
Chris@16 68
Chris@16 69 static inline iterator_type begin(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
Chris@16 70 static inline iterator_type end(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
Chris@16 71
Chris@16 72 static inline bool clean(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
Chris@16 73
Chris@16 74 static inline bool sort(const polygon_set_view<ltype, rtype, op_type>& polygon_set);
Chris@16 75 };
Chris@16 76
Chris@16 77 //template <typename value_type, typename geometry_type_1, typename geometry_type_2, int op_type>
Chris@16 78 //void execute_boolean_op(value_type& output_, const geometry_type_1& lvalue_, const geometry_type_2& rvalue_,
Chris@16 79 // double coord) {
Chris@16 80 // typedef geometry_type_1 ltype;
Chris@16 81 // typedef geometry_type_2 rtype;
Chris@16 82 // typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
Chris@16 83 // value_type linput_;
Chris@16 84 // value_type rinput_;
Chris@16 85 // insert_into_view_arg(linput_, lvalue_);
Chris@16 86 // insert_into_view_arg(rinput_, rvalue_);
Chris@16 87 // arbitrary_boolean_op<coordinate_type> abo;
Chris@16 88 // abo.execute(output_, linput_.begin(), linput_.end(),
Chris@16 89 // rinput_.begin(), rinput_.end(), op_type);
Chris@16 90 //}
Chris@16 91
Chris@16 92 template <typename value_type, typename geometry_type_1, typename geometry_type_2, int op_type>
Chris@16 93 void execute_boolean_op(value_type& output_, const geometry_type_1& lvalue_, const geometry_type_2& rvalue_) {
Chris@16 94 typedef geometry_type_1 ltype;
Chris@101 95 //typedef geometry_type_2 rtype;
Chris@16 96 typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
Chris@16 97 value_type linput_;
Chris@16 98 value_type rinput_;
Chris@16 99 insert_into_view_arg(linput_, lvalue_);
Chris@16 100 insert_into_view_arg(rinput_, rvalue_);
Chris@16 101 polygon_45_set_data<coordinate_type> l45, r45, o45;
Chris@16 102 // if(linput_.downcast(l45) && rinput_.downcast(r45)) {
Chris@16 103 // //the op codes are screwed up between 45 and arbitrary
Chris@16 104 //#ifdef BOOST_POLYGON_MSVC
Chris@16 105 //#pragma warning (push)
Chris@16 106 //#pragma warning (disable: 4127)
Chris@16 107 //#endif
Chris@16 108 // if(op_type < 2)
Chris@16 109 // l45.template applyAdaptiveBoolean_<op_type>(o45, r45);
Chris@16 110 // else if(op_type == 2)
Chris@16 111 // l45.template applyAdaptiveBoolean_<3>(o45, r45);
Chris@16 112 // else
Chris@16 113 // l45.template applyAdaptiveBoolean_<2>(o45, r45);
Chris@16 114 //#ifdef BOOST_POLYGON_MSVC
Chris@16 115 //#pragma warning (pop)
Chris@16 116 //#endif
Chris@16 117 // output_.insert(o45);
Chris@16 118 // } else {
Chris@16 119 arbitrary_boolean_op<coordinate_type> abo;
Chris@16 120 abo.execute(output_, linput_.begin(), linput_.end(),
Chris@16 121 rinput_.begin(), rinput_.end(), op_type);
Chris@16 122 // }
Chris@16 123 }
Chris@16 124
Chris@16 125 template <typename ltype, typename rtype, int op_type>
Chris@16 126 class polygon_set_view {
Chris@16 127 public:
Chris@16 128 typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
Chris@16 129 typedef polygon_set_data<coordinate_type> value_type;
Chris@16 130 typedef typename value_type::iterator_type iterator_type;
Chris@16 131 typedef polygon_set_view operator_arg_type;
Chris@16 132 private:
Chris@16 133 const ltype& lvalue_;
Chris@16 134 const rtype& rvalue_;
Chris@16 135 mutable value_type output_;
Chris@16 136 mutable bool evaluated_;
Chris@16 137 polygon_set_view& operator=(const polygon_set_view&);
Chris@16 138 public:
Chris@16 139 polygon_set_view(const ltype& lvalue,
Chris@16 140 const rtype& rvalue ) :
Chris@16 141 lvalue_(lvalue), rvalue_(rvalue), output_(), evaluated_(false) {}
Chris@16 142
Chris@16 143 // get iterator to begin vertex data
Chris@16 144 public:
Chris@16 145 const value_type& value() const {
Chris@16 146 if(!evaluated_) {
Chris@16 147 evaluated_ = true;
Chris@16 148 execute_boolean_op<value_type, ltype, rtype, op_type>(output_, lvalue_, rvalue_);
Chris@16 149 }
Chris@16 150 return output_;
Chris@16 151 }
Chris@16 152 public:
Chris@16 153 iterator_type begin() const { return value().begin(); }
Chris@16 154 iterator_type end() const { return value().end(); }
Chris@16 155
Chris@16 156 bool dirty() const { return false; } //result of a boolean is clean
Chris@16 157 bool sorted() const { return true; } //result of a boolean is sorted
Chris@16 158
Chris@16 159 void sort() const {} //is always sorted
Chris@16 160 };
Chris@16 161
Chris@16 162 template <typename ltype, typename rtype, int op_type>
Chris@16 163 typename polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::iterator_type
Chris@16 164 polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
Chris@16 165 begin(const polygon_set_view<ltype, rtype, op_type>& polygon_set) {
Chris@16 166 return polygon_set.begin();
Chris@16 167 }
Chris@16 168 template <typename ltype, typename rtype, int op_type>
Chris@16 169 typename polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::iterator_type
Chris@16 170 polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
Chris@16 171 end(const polygon_set_view<ltype, rtype, op_type>& polygon_set) {
Chris@16 172 return polygon_set.end();
Chris@16 173 }
Chris@16 174 template <typename ltype, typename rtype, int op_type>
Chris@16 175 bool polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
Chris@16 176 clean(const polygon_set_view<ltype, rtype, op_type>& ) {
Chris@16 177 return true; }
Chris@16 178 template <typename ltype, typename rtype, int op_type>
Chris@16 179 bool polygon_set_traits<polygon_set_view<ltype, rtype, op_type> >::
Chris@16 180 sort(const polygon_set_view<ltype, rtype, op_type>& ) {
Chris@16 181 return true; }
Chris@16 182
Chris@16 183 template <typename value_type, typename arg_type>
Chris@16 184 inline void insert_into_view_arg(value_type& dest, const arg_type& arg) {
Chris@16 185 typedef typename polygon_set_traits<arg_type>::iterator_type literator;
Chris@16 186 literator itr1, itr2;
Chris@16 187 itr1 = polygon_set_traits<arg_type>::begin(arg);
Chris@16 188 itr2 = polygon_set_traits<arg_type>::end(arg);
Chris@16 189 dest.insert(itr1, itr2);
Chris@16 190 }
Chris@16 191
Chris@16 192 template <typename geometry_type_1, typename geometry_type_2, int op_type>
Chris@16 193 geometry_type_1& self_assignment_boolean_op(geometry_type_1& lvalue_, const geometry_type_2& rvalue_) {
Chris@16 194 typedef geometry_type_1 ltype;
Chris@16 195 typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
Chris@16 196 typedef polygon_set_data<coordinate_type> value_type;
Chris@16 197 value_type output_;
Chris@16 198 execute_boolean_op<value_type, geometry_type_1, geometry_type_2, op_type>(output_, lvalue_, rvalue_);
Chris@16 199 polygon_set_mutable_traits<geometry_type_1>::set(lvalue_, output_.begin(), output_.end());
Chris@16 200 return lvalue_;
Chris@16 201 }
Chris@16 202
Chris@16 203 // copy constructor
Chris@16 204 template <typename coordinate_type>
Chris@16 205 template <typename ltype, typename rtype, int op_type>
Chris@16 206 polygon_set_data<coordinate_type>::polygon_set_data(const polygon_set_view<ltype, rtype, op_type>& that) :
Chris@16 207 data_(that.value().data_), dirty_(that.value().dirty_), unsorted_(that.value().unsorted_), is_45_(that.value().is_45_) {}
Chris@16 208
Chris@16 209 // equivalence operator
Chris@16 210 template <typename coordinate_type>
Chris@16 211 inline bool polygon_set_data<coordinate_type>::operator==(const polygon_set_data<coordinate_type>& p) const {
Chris@16 212 typedef polygon_set_data<coordinate_type> value_type;
Chris@16 213 value_type output_;
Chris@16 214 execute_boolean_op<value_type, value_type, value_type, 2>(output_, (*this), p);
Chris@16 215 return output_.data_.empty();
Chris@16 216 }
Chris@16 217
Chris@16 218 template <typename ltype, typename rtype, int op_type>
Chris@16 219 struct geometry_concept<polygon_set_view<ltype, rtype, op_type> > { typedef polygon_set_concept type; };
Chris@16 220 }
Chris@16 221 }
Chris@16 222 #endif