polygon_data.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_DATA_HPP
  8. #define BOOST_POLYGON_POLYGON_DATA_HPP
  9. namespace boost { namespace polygon{
  10. struct polygon_concept;
  11. template <typename T>
  12. class polygon_data {
  13. public:
  14. typedef polygon_concept geometry_type;
  15. typedef T coordinate_type;
  16. typedef typename std::vector<point_data<coordinate_type> >::const_iterator iterator_type;
  17. typedef typename coordinate_traits<T>::coordinate_distance area_type;
  18. typedef point_data<T> point_type;
  19. inline polygon_data() : coords_() {} //do nothing default constructor
  20. template<class iT>
  21. inline polygon_data(iT input_begin, iT input_end) : coords_(input_begin, input_end) {}
  22. template<class iT>
  23. inline polygon_data& set(iT input_begin, iT input_end) {
  24. coords_.clear(); //just in case there was some old data there
  25. coords_.insert(coords_.end(), input_begin, input_end);
  26. return *this;
  27. }
  28. // copy constructor (since we have dynamic memory)
  29. inline polygon_data(const polygon_data& that) : coords_(that.coords_) {}
  30. // assignment operator (since we have dynamic memory do a deep copy)
  31. inline polygon_data& operator=(const polygon_data& that) {
  32. coords_ = that.coords_;
  33. return *this;
  34. }
  35. template <typename T2>
  36. inline polygon_data& operator=(const T2& rvalue);
  37. inline bool operator==(const polygon_data& that) const {
  38. if(coords_.size() != that.coords_.size()) return false;
  39. for(std::size_t i = 0; i < coords_.size(); ++i) {
  40. if(coords_[i] != that.coords_[i]) return false;
  41. }
  42. return true;
  43. }
  44. inline bool operator!=(const polygon_data& that) const { return !((*this) == that); }
  45. // get begin iterator, returns a pointer to a const Unit
  46. inline iterator_type begin() const { return coords_.begin(); }
  47. // get end iterator, returns a pointer to a const Unit
  48. inline iterator_type end() const { return coords_.end(); }
  49. inline std::size_t size() const { return coords_.size(); }
  50. public:
  51. std::vector<point_data<coordinate_type> > coords_;
  52. };
  53. }
  54. }
  55. #endif