rectangle_data.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_RECTANGLE_DATA_HPP
  8. #define BOOST_POLYGON_RECTANGLE_DATA_HPP
  9. #include "isotropy.hpp"
  10. //interval
  11. #include "interval_data.hpp"
  12. namespace boost { namespace polygon{
  13. template <typename T>
  14. class rectangle_data {
  15. public:
  16. typedef T coordinate_type;
  17. typedef interval_data<T> interval_type;
  18. inline rectangle_data():ranges_() {}
  19. inline rectangle_data(T xl, T yl, T xh, T yh):ranges_() {
  20. if(xl > xh) std::swap(xl, xh);
  21. if(yl > yh) std::swap(yl, yh);
  22. ranges_[HORIZONTAL] = interval_data<T>(xl, xh);
  23. ranges_[VERTICAL] = interval_data<T>(yl, yh);
  24. }
  25. template <typename interval_type_1, typename interval_type_2>
  26. inline rectangle_data(const interval_type_1& hrange,
  27. const interval_type_2& vrange):ranges_() {
  28. set(HORIZONTAL, hrange); set(VERTICAL, vrange); }
  29. inline rectangle_data(const rectangle_data& that):ranges_() { (*this) = that; }
  30. inline rectangle_data& operator=(const rectangle_data& that) {
  31. ranges_[0] = that.ranges_[0]; ranges_[1] = that.ranges_[1]; return *this;
  32. }
  33. template <typename T2>
  34. inline rectangle_data& operator=(const T2& rvalue);
  35. template <typename T2>
  36. inline bool operator==(const T2& rvalue) const;
  37. template <typename T2>
  38. inline bool operator!=(const T2& rvalue) const { return !((*this) == rvalue); }
  39. inline interval_data<coordinate_type> get(orientation_2d orient) const {
  40. return ranges_[orient.to_int()]; }
  41. inline coordinate_type get(direction_2d dir) const {
  42. return ranges_[orientation_2d(dir).to_int()].get(direction_1d(dir));
  43. }
  44. inline void set(direction_2d dir, coordinate_type value) {
  45. return ranges_[orientation_2d(dir).to_int()].set(direction_1d(dir), value);
  46. }
  47. template <typename interval_type_1>
  48. inline void set(orientation_2d orient, const interval_type_1& interval);
  49. private:
  50. interval_data<coordinate_type> ranges_[2];
  51. };
  52. }
  53. }
  54. #endif