/* Copyright 2008 Intel Corporation Use, modification and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). */ #ifndef BOOST_POLYGON_POLYGON_90_SET_VIEW_HPP #define BOOST_POLYGON_POLYGON_90_SET_VIEW_HPP namespace boost { namespace polygon{ struct operator_provides_storage {}; struct operator_requires_copy {}; template inline void insert_into_view_arg(value_type& dest, const arg_type& arg, orientation_2d orient); template class polygon_90_set_view; template struct polygon_90_set_traits > { typedef typename polygon_90_set_view::coordinate_type coordinate_type; typedef typename polygon_90_set_view::iterator_type iterator_type; typedef typename polygon_90_set_view::operator_arg_type operator_arg_type; static inline iterator_type begin(const polygon_90_set_view& polygon_set); static inline iterator_type end(const polygon_90_set_view& polygon_set); static inline orientation_2d orient(const polygon_90_set_view& polygon_set); static inline bool clean(const polygon_90_set_view& polygon_set); static inline bool sorted(const polygon_90_set_view& polygon_set); }; template struct compute_90_set_value { static void value(value_type& output_, const ltype& lvalue_, const rtype& rvalue_, orientation_2d orient_) { value_type linput_(orient_); value_type rinput_(orient_); insert_into_view_arg(linput_, lvalue_, orient_); insert_into_view_arg(rinput_, rvalue_, orient_); output_.applyBooleanBinaryOp(linput_.begin(), linput_.end(), rinput_.begin(), rinput_.end(), boolean_op::BinaryCount()); } }; template struct compute_90_set_value, polygon_90_set_data, op_type> { static void value(value_type& output_, const polygon_90_set_data& lvalue_, const polygon_90_set_data& rvalue_, orientation_2d) { lvalue_.sort(); rvalue_.sort(); output_.applyBooleanBinaryOp(lvalue_.begin(), lvalue_.end(), rvalue_.begin(), rvalue_.end(), boolean_op::BinaryCount()); } }; template struct compute_90_set_value, rtype, op_type> { static void value(value_type& output_, const polygon_90_set_data& lvalue_, const rtype& rvalue_, orientation_2d orient_) { value_type rinput_(orient_); lvalue_.sort(); insert_into_view_arg(rinput_, rvalue_, orient_); output_.applyBooleanBinaryOp(lvalue_.begin(), lvalue_.end(), rinput_.begin(), rinput_.end(), boolean_op::BinaryCount()); } }; template struct compute_90_set_value, op_type> { static void value(value_type& output_, const ltype& lvalue_, const polygon_90_set_data& rvalue_, orientation_2d orient_) { value_type linput_(orient_); insert_into_view_arg(linput_, lvalue_, orient_); rvalue_.sort(); output_.applyBooleanBinaryOp(linput_.begin(), linput_.end(), rvalue_.begin(), rvalue_.end(), boolean_op::BinaryCount()); } }; template class polygon_90_set_view { public: typedef typename polygon_90_set_traits::coordinate_type coordinate_type; typedef polygon_90_set_data value_type; typedef typename value_type::iterator_type iterator_type; typedef polygon_90_set_view operator_arg_type; private: const ltype& lvalue_; const rtype& rvalue_; orientation_2d orient_; op_type op_; mutable value_type output_; mutable bool evaluated_; polygon_90_set_view& operator=(const polygon_90_set_view&); public: polygon_90_set_view(const ltype& lvalue, const rtype& rvalue, orientation_2d orient, op_type op) : lvalue_(lvalue), rvalue_(rvalue), orient_(orient), op_(op), output_(orient), evaluated_(false) {} // get iterator to begin vertex data private: const value_type& value() const { if(!evaluated_) { evaluated_ = true; compute_90_set_value::value(output_, lvalue_, rvalue_, orient_); } return output_; } public: iterator_type begin() const { return value().begin(); } iterator_type end() const { return value().end(); } orientation_2d orient() const { return orient_; } bool dirty() const { return false; } //result of a boolean is clean bool sorted() const { return true; } //result of a boolean is sorted // template // void set(input_iterator_type input_begin, input_iterator_type input_end, // orientation_2d orient) const { // orient_ = orient; // output_.clear(); // output_.insert(output_.end(), input_begin, input_end); // std::sort(output_.begin(), output_.end()); // } void sort() const {} //is always sorted }; template struct geometry_concept > { typedef polygon_90_set_concept type; }; template typename polygon_90_set_traits >::iterator_type polygon_90_set_traits >:: begin(const polygon_90_set_view& polygon_set) { return polygon_set.begin(); } template typename polygon_90_set_traits >::iterator_type polygon_90_set_traits >:: end(const polygon_90_set_view& polygon_set) { return polygon_set.end(); } // template // template // void polygon_90_set_traits >:: // set(polygon_90_set_view& polygon_set, // input_iterator_type input_begin, input_iterator_type input_end, // orientation_2d orient) { // polygon_set.set(input_begin, input_end, orient); // } template orientation_2d polygon_90_set_traits >:: orient(const polygon_90_set_view& polygon_set) { return polygon_set.orient(); } template bool polygon_90_set_traits >:: clean(const polygon_90_set_view& polygon_set) { return true; } template bool polygon_90_set_traits >:: sorted(const polygon_90_set_view& polygon_set) { return true; } template inline void insert_into_view_arg(value_type& dest, const arg_type& arg, orientation_2d orient) { typedef typename polygon_90_set_traits::iterator_type literator; literator itr1, itr2; itr1 = polygon_90_set_traits::begin(arg); itr2 = polygon_90_set_traits::end(arg); dest.insert(itr1, itr2, orient); dest.sort(); } template template inline polygon_90_set_data& polygon_90_set_data::operator=(const polygon_90_set_view& that) { set(that.begin(), that.end(), that.orient()); dirty_ = false; unsorted_ = false; return *this; } template template inline polygon_90_set_data::polygon_90_set_data(const polygon_90_set_view& that) : orient_(that.orient()), data_(that.begin(), that.end()), dirty_(false), unsorted_(false) {} template struct self_assign_operator_lvalue { typedef geometry_type_1& type; }; template struct by_value_binary_operator { typedef type_1 type; }; template geometry_type_1& self_assignment_boolean_op(geometry_type_1& lvalue_, const geometry_type_2& rvalue_) { typedef geometry_type_1 ltype; typedef geometry_type_2 rtype; typedef typename polygon_90_set_traits::coordinate_type coordinate_type; typedef polygon_90_set_data value_type; orientation_2d orient_ = polygon_90_set_traits::orient(lvalue_); value_type linput_(orient_); value_type rinput_(orient_); value_type output_(orient_); insert_into_view_arg(linput_, lvalue_, orient_); insert_into_view_arg(rinput_, rvalue_, orient_); output_.applyBooleanBinaryOp(linput_.begin(), linput_.end(), rinput_.begin(), rinput_.end(), boolean_op::BinaryCount()); polygon_90_set_mutable_traits::set(lvalue_, output_.begin(), output_.end(), orient_); return lvalue_; } namespace operators { struct y_ps90_b : gtl_yes {}; template typename enable_if< typename gtl_and_3< y_ps90_b, typename is_polygon_90_set_type::type, typename is_polygon_90_set_type::type>::type, polygon_90_set_view >::type operator|(const geometry_type_1& lvalue, const geometry_type_2& rvalue) { return polygon_90_set_view (lvalue, rvalue, polygon_90_set_traits::orient(lvalue), boolean_op::BinaryOr()); } struct y_ps90_p : gtl_yes {}; template typename enable_if< typename gtl_and_3< y_ps90_p, typename gtl_if::type>::type, typename gtl_if::type>::type>::type, polygon_90_set_view >::type operator+(const geometry_type_1& lvalue, const geometry_type_2& rvalue) { return polygon_90_set_view (lvalue, rvalue, polygon_90_set_traits::orient(lvalue), boolean_op::BinaryOr()); } struct y_ps90_s : gtl_yes {}; template typename enable_if< typename gtl_and_3< y_ps90_s, typename is_polygon_90_set_type::type, typename is_polygon_90_set_type::type>::type, polygon_90_set_view >::type operator*(const geometry_type_1& lvalue, const geometry_type_2& rvalue) { return polygon_90_set_view (lvalue, rvalue, polygon_90_set_traits::orient(lvalue), boolean_op::BinaryAnd()); } struct y_ps90_a : gtl_yes {}; template typename enable_if< typename gtl_and_3< y_ps90_a, typename is_polygon_90_set_type::type, typename is_polygon_90_set_type::type>::type, polygon_90_set_view >::type operator&(const geometry_type_1& lvalue, const geometry_type_2& rvalue) { return polygon_90_set_view (lvalue, rvalue, polygon_90_set_traits::orient(lvalue), boolean_op::BinaryAnd()); } struct y_ps90_x : gtl_yes {}; template typename enable_if< typename gtl_and_3< y_ps90_x, typename is_polygon_90_set_type::type, typename is_polygon_90_set_type::type>::type, polygon_90_set_view >::type operator^(const geometry_type_1& lvalue, const geometry_type_2& rvalue) { return polygon_90_set_view (lvalue, rvalue, polygon_90_set_traits::orient(lvalue), boolean_op::BinaryXor()); } struct y_ps90_m : gtl_yes {}; template typename enable_if< typename gtl_and_3< y_ps90_m, typename gtl_if::type>::type, typename gtl_if::type>::type>::type, polygon_90_set_view >::type operator-(const geometry_type_1& lvalue, const geometry_type_2& rvalue) { return polygon_90_set_view (lvalue, rvalue, polygon_90_set_traits::orient(lvalue), boolean_op::BinaryNot()); } struct y_ps90_pe : gtl_yes {}; template typename enable_if< typename gtl_and< y_ps90_pe, typename is_polygon_90_set_type::type>::type, polygon_90_set_data >::type & operator+=(polygon_90_set_data& lvalue, const geometry_type_2& rvalue) { lvalue.insert(polygon_90_set_traits::begin(rvalue), polygon_90_set_traits::end(rvalue), polygon_90_set_traits::orient(rvalue)); return lvalue; } struct y_ps90_be : gtl_yes {}; // template typename enable_if< typename gtl_and< y_ps90_be, typename is_polygon_90_set_type::type>::type, polygon_90_set_data >::type & operator|=(polygon_90_set_data& lvalue, const geometry_type_2& rvalue) { return lvalue += rvalue; } struct y_ps90_pe2 : gtl_yes {}; //normal self assignment boolean operations template typename enable_if< typename gtl_and_3< y_ps90_pe2, typename is_mutable_polygon_90_set_type::type, typename is_polygon_90_set_type::type>::type, geometry_type_1>::type & operator+=(geometry_type_1& lvalue, const geometry_type_2& rvalue) { return self_assignment_boolean_op(lvalue, rvalue); } struct y_ps90_be2 : gtl_yes {}; template typename enable_if< typename gtl_and_3::type, typename is_polygon_90_set_type::type>::type, geometry_type_1>::type & operator|=(geometry_type_1& lvalue, const geometry_type_2& rvalue) { return self_assignment_boolean_op(lvalue, rvalue); } struct y_ps90_se : gtl_yes {}; template typename enable_if< typename gtl_and_3::type, typename is_polygon_90_set_type::type>::type, geometry_type_1>::type & operator*=(geometry_type_1& lvalue, const geometry_type_2& rvalue) { return self_assignment_boolean_op(lvalue, rvalue); } struct y_ps90_ae : gtl_yes {}; template typename enable_if< typename gtl_and_3::type, typename is_polygon_90_set_type::type>::type, geometry_type_1>::type & operator&=(geometry_type_1& lvalue, const geometry_type_2& rvalue) { return self_assignment_boolean_op(lvalue, rvalue); } struct y_ps90_xe : gtl_yes {}; template typename enable_if< typename gtl_and_3::type, typename is_polygon_90_set_type::type>::type, geometry_type_1>::type & operator^=(geometry_type_1& lvalue, const geometry_type_2& rvalue) { return self_assignment_boolean_op(lvalue, rvalue); } struct y_ps90_me : gtl_yes {}; template typename enable_if< typename gtl_and_3< y_ps90_me, typename is_mutable_polygon_90_set_type::type, typename is_polygon_90_set_type::type>::type, geometry_type_1>::type & operator-=(geometry_type_1& lvalue, const geometry_type_2& rvalue) { return self_assignment_boolean_op(lvalue, rvalue); } struct y_ps90_rpe : gtl_yes {}; template typename enable_if< typename gtl_and_3::type, typename gtl_same_type::type, coordinate_concept>::type>::type, geometry_type_1>::type & operator+=(geometry_type_1& lvalue, coordinate_type_1 rvalue) { return resize(lvalue, rvalue); } struct y_ps90_rme : gtl_yes {}; template typename enable_if< typename gtl_and_3::type, typename gtl_same_type::type, coordinate_concept>::type>::type, geometry_type_1>::type & operator-=(geometry_type_1& lvalue, coordinate_type_1 rvalue) { return resize(lvalue, -rvalue); } struct y_ps90_rp : gtl_yes {}; template typename enable_if< typename gtl_and_3::type>::type, typename gtl_if::type, coordinate_concept>::type>::type>::type, geometry_type_1>::type operator+(const geometry_type_1& lvalue, coordinate_type_1 rvalue) { geometry_type_1 retval(lvalue); retval += rvalue; return retval; } struct y_ps90_rm : gtl_yes {}; template typename enable_if< typename gtl_and_3::type>::type, typename gtl_if::type, coordinate_concept>::type>::type>::type, geometry_type_1>::type operator-(const geometry_type_1& lvalue, coordinate_type_1 rvalue) { geometry_type_1 retval(lvalue); retval -= rvalue; return retval; } } } } #endif