Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:04:53

0001 /*
0002   Copyright 2008 Intel Corporation
0003 
0004   Use, modification and distribution are subject to the Boost Software License,
0005   Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006   http://www.boost.org/LICENSE_1_0.txt).
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       //polygon_45_set_data<coordinate_type> tmp;
0017       //very important:
0018       //the 45 degree algorithm does not satisfy
0019       //the precondition of arbitrary polygon formation
0020       //that vertices be "linearly consistent"
0021       //therefore it doesn't work to fall back on 45-degree
0022       //booleans for arbitrary angle polygons
0023       //if(0) { //downcast(tmp) ) {
0024       //  tmp.clean();
0025       //  data_.clear();
0026       //  is_45_ = true;
0027       //  polygon_set_data<coordinate_type> tmp2;
0028       //  tmp2.insert(tmp);
0029       //  data_.swap(tmp2.data_);
0030       //  dirty_ = false;
0031       //  sort();
0032       //} else {
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   //template <typename value_type, typename geometry_type_1, typename geometry_type_2, int op_type>
0078   //void execute_boolean_op(value_type& output_, const geometry_type_1& lvalue_, const geometry_type_2& rvalue_,
0079   //                        double coord) {
0080   //  typedef geometry_type_1 ltype;
0081   //  typedef geometry_type_2 rtype;
0082   //  typedef typename polygon_set_traits<ltype>::coordinate_type coordinate_type;
0083   //  value_type linput_;
0084   //  value_type rinput_;
0085   //  insert_into_view_arg(linput_, lvalue_);
0086   //  insert_into_view_arg(rinput_, rvalue_);
0087   //  arbitrary_boolean_op<coordinate_type> abo;
0088   //  abo.execute(output_, linput_.begin(), linput_.end(),
0089   //              rinput_.begin(), rinput_.end(), op_type);
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     //typedef geometry_type_2 rtype;
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 //    if(linput_.downcast(l45) && rinput_.downcast(r45)) {
0103 //      //the op codes are screwed up between 45 and arbitrary
0104 //#ifdef BOOST_POLYGON_MSVC
0105 //#pragma warning (push)
0106 //#pragma warning (disable: 4127)
0107 //#endif
0108 //      if(op_type < 2)
0109 //        l45.template applyAdaptiveBoolean_<op_type>(o45, r45);
0110 //      else if(op_type == 2)
0111 //        l45.template applyAdaptiveBoolean_<3>(o45, r45);
0112 //      else
0113 //        l45.template applyAdaptiveBoolean_<2>(o45, r45);
0114 //#ifdef BOOST_POLYGON_MSVC
0115 //#pragma warning (pop)
0116 //#endif
0117 //      output_.insert(o45);
0118 //    } else {
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     // get iterator to begin vertex data
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; } //result of a boolean is clean
0157     bool sorted() const { return true; } //result of a boolean is sorted
0158 
0159     void sort() const {} //is always sorted
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   // copy constructor
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     // equivalence operator
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