DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.5KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DGL_GEOMETRY_HPP_INCLUDED
  17. #define DGL_GEOMETRY_HPP_INCLUDED
  18. #include "Base.hpp"
  19. START_NAMESPACE_DGL
  20. // -----------------------------------------------------------------------
  21. template<typename T>
  22. class Point
  23. {
  24. public:
  25. Point() noexcept;
  26. Point(const T& x, const T& y) noexcept;
  27. Point(const Point<T>& pos) noexcept;
  28. const T& getX() const noexcept;
  29. const T& getY() const noexcept;
  30. void setX(const T& x) noexcept;
  31. void setY(const T& y) noexcept;
  32. void setPos(const T& x, const T& y) noexcept;
  33. void setPos(const Point<T>& pos) noexcept;
  34. void moveBy(const T& x, const T& y) noexcept;
  35. void moveBy(const Point<T>& pos) noexcept;
  36. Point<T>& operator=(const Point<T>& pos) noexcept;
  37. Point<T>& operator+=(const Point<T>& pos) noexcept;
  38. Point<T>& operator-=(const Point<T>& pos) noexcept;
  39. bool operator==(const Point<T>& pos) const noexcept;
  40. bool operator!=(const Point<T>& pos) const noexcept;
  41. private:
  42. T fX, fY;
  43. template<typename> friend class Rectangle;
  44. DISTRHO_PREVENT_HEAP_ALLOCATION
  45. };
  46. // -----------------------------------------------------------------------
  47. template<typename T>
  48. class Size
  49. {
  50. public:
  51. Size() noexcept;
  52. Size(const T& width, const T& height) noexcept;
  53. Size(const Size<T>& size) noexcept;
  54. const T& getWidth() const noexcept;
  55. const T& getHeight() const noexcept;
  56. void setWidth(const T& width) noexcept;
  57. void setHeight(const T& height) noexcept;
  58. void growBy(const T& multiplier) noexcept;
  59. void shrinkBy(const T& divider) noexcept;
  60. Size<T>& operator=(const Size<T>& size) noexcept;
  61. Size<T>& operator+=(const Size<T>& size) noexcept;
  62. Size<T>& operator-=(const Size<T>& size) noexcept;
  63. Size<T>& operator*=(const T& m) noexcept;
  64. Size<T>& operator/=(const T& d) noexcept;
  65. bool operator==(const Size<T>& size) const noexcept;
  66. bool operator!=(const Size<T>& size) const noexcept;
  67. private:
  68. T fWidth, fHeight;
  69. template<typename> friend class Rectangle;
  70. DISTRHO_PREVENT_HEAP_ALLOCATION
  71. };
  72. // -----------------------------------------------------------------------
  73. template<typename T>
  74. class Rectangle
  75. {
  76. public:
  77. Rectangle() noexcept;
  78. Rectangle(const T& x, const T& y, const T& width, const T& height) noexcept;
  79. Rectangle(const T& x, const T& y, const Size<T>& size) noexcept;
  80. Rectangle(const Point<T>& pos, const T& width, const T& height) noexcept;
  81. Rectangle(const Point<T>& pos, const Size<T>& size) noexcept;
  82. Rectangle(const Rectangle<T>& rect) noexcept;
  83. const T& getX() const noexcept;
  84. const T& getY() const noexcept;
  85. const T& getWidth() const noexcept;
  86. const T& getHeight() const noexcept;
  87. const Point<T>& getPos() const noexcept;
  88. const Size<T>& getSize() const noexcept;
  89. bool contains(const T& x, const T& y) const noexcept;
  90. bool contains(const Point<T>& pos) const noexcept;
  91. bool containsX(const T& x) const noexcept;
  92. bool containsY(const T& y) const noexcept;
  93. void setX(const T& x) noexcept;
  94. void setY(const T& y) noexcept;
  95. void setPos(const T& x, const T& y) noexcept;
  96. void setPos(const Point<T>& pos) noexcept;
  97. void move(const T& x, const T& y) noexcept;
  98. void move(const Point<T>& pos) noexcept;
  99. void setWidth(const T& width) noexcept;
  100. void setHeight(const T& height) noexcept;
  101. void setSize(const T& width, const T& height) noexcept;
  102. void setSize(const Size<T>& size) noexcept;
  103. Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;
  104. private:
  105. Point<T> fPos;
  106. Size<T> fSize;
  107. DISTRHO_PREVENT_HEAP_ALLOCATION
  108. };
  109. // -----------------------------------------------------------------------
  110. END_NAMESPACE_DGL
  111. #endif // DGL_GEOMETRY_HPP_INCLUDED