polygon_90_data.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright 2008 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. #ifndef BOOST_POLYGON_POLYGON_90_DATA_HPP
  8. #define BOOST_POLYGON_POLYGON_90_DATA_HPP
  9. namespace boost { namespace polygon{
  10. struct polygon_90_concept;
  11. template <typename T>
  12. class polygon_90_data {
  13. public:
  14. typedef polygon_90_concept geometry_type;
  15. typedef T coordinate_type;
  16. typedef typename std::vector<coordinate_type>::const_iterator compact_iterator_type;
  17. typedef iterator_compact_to_points<compact_iterator_type, point_data<coordinate_type> > iterator_type;
  18. typedef typename coordinate_traits<T>::area_type area_type;
  19. inline polygon_90_data() : coords_() {} //do nothing default constructor
  20. // initialize a polygon from x,y values, it is assumed that the first is an x
  21. // and that the input is a well behaved polygon
  22. template<class iT>
  23. inline polygon_90_data& set(iT begin_point, iT end_point) {
  24. return set_compact(iterator_points_to_compact<iT, typename std::iterator_traits<iT>::value_type>(begin_point, end_point),
  25. iterator_points_to_compact<iT, typename std::iterator_traits<iT>::value_type>(end_point, end_point));
  26. }
  27. template<class iT>
  28. inline polygon_90_data& set_compact(iT input_begin, iT input_end) {
  29. coords_.clear(); //just in case there was some old data there
  30. while(input_begin != input_end) {
  31. coords_.insert(coords_.end(), *input_begin);
  32. ++input_begin;
  33. }
  34. return *this;
  35. }
  36. // copy constructor (since we have dynamic memory)
  37. inline polygon_90_data(const polygon_90_data& that) : coords_(that.coords_) {}
  38. // assignment operator (since we have dynamic memory do a deep copy)
  39. inline polygon_90_data& operator=(const polygon_90_data& that) {
  40. coords_ = that.coords_;
  41. return *this;
  42. }
  43. template <typename T2>
  44. inline polygon_90_data& operator=(const T2& rvalue);
  45. // assignment operator (since we have dynamic memory do a deep copy)
  46. inline bool operator==(const polygon_90_data& that) const {
  47. return coords_ == that.coords_;
  48. }
  49. // get begin iterator, returns a pointer to a const Unit
  50. inline iterator_type begin() const { return iterator_type(coords_.begin(), coords_.end()); }
  51. // get end iterator, returns a pointer to a const Unit
  52. inline iterator_type end() const { return iterator_type(coords_.end(), coords_.end()); }
  53. // get begin iterator, returns a pointer to a const Unit
  54. inline compact_iterator_type begin_compact() const { return coords_.begin(); }
  55. // get end iterator, returns a pointer to a const Unit
  56. inline compact_iterator_type end_compact() const { return coords_.end(); }
  57. inline std::size_t size() const { return coords_.size(); }
  58. private:
  59. std::vector<coordinate_type> coords_;
  60. };
  61. }
  62. }
  63. #endif