Audio plugin host https://kx.studio/carla
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.

Geometry.hpp 3.9KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * DISTRHO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012-2013 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(T x, T y) noexcept;
  27. Point(const Point<T>& pos) noexcept;
  28. T getX() const noexcept;
  29. T getY() const noexcept;
  30. void setX(T x) noexcept;
  31. void setY(T y) noexcept;
  32. void move(T x, T y) noexcept;
  33. void move(const Point<T>& pos) noexcept;
  34. Point<T>& operator=(const Point<T>& pos) noexcept;
  35. Point<T>& operator+=(const Point<T>& pos) noexcept;
  36. Point<T>& operator-=(const Point<T>& pos) noexcept;
  37. bool operator==(const Point<T>& pos) const noexcept;
  38. bool operator!=(const Point<T>& pos) const noexcept;
  39. private:
  40. T fX, fY;
  41. template<typename> friend class Rectangle;
  42. };
  43. // -----------------------------------------------------------------------
  44. template<typename T>
  45. class Size
  46. {
  47. public:
  48. Size() noexcept;
  49. Size(T width, T height) noexcept;
  50. Size(const Size<T>& size) noexcept;
  51. T getWidth() const noexcept;
  52. T getHeight() const noexcept;
  53. void setWidth(T width) noexcept;
  54. void setHeight(T height) noexcept;
  55. Size<T>& operator=(const Size<T>& size) noexcept;
  56. Size<T>& operator+=(const Size<T>& size) noexcept;
  57. Size<T>& operator-=(const Size<T>& size) noexcept;
  58. Size<T>& operator*=(T m) noexcept;
  59. Size<T>& operator/=(T d) noexcept;
  60. bool operator==(const Size<T>& size) const noexcept;
  61. bool operator!=(const Size<T>& size) const noexcept;
  62. private:
  63. T fWidth, fHeight;
  64. template<typename> friend class Rectangle;
  65. };
  66. // -----------------------------------------------------------------------
  67. template<typename T>
  68. class Rectangle
  69. {
  70. public:
  71. Rectangle() noexcept;
  72. Rectangle(T x, T y, T width, T height) noexcept;
  73. Rectangle(T x, T y, const Size<T>& size) noexcept;
  74. Rectangle(const Point<T>& pos, T width, T height) noexcept;
  75. Rectangle(const Point<T>& pos, const Size<T>& size) noexcept;
  76. Rectangle(const Rectangle<T>& rect) noexcept;
  77. T getX() const noexcept;
  78. T getY() const noexcept;
  79. T getWidth() const noexcept;
  80. T getHeight() const noexcept;
  81. const Point<T>& getPos() const noexcept;
  82. const Size<T>& getSize() const noexcept;
  83. bool contains(T x, T y) const noexcept;
  84. bool contains(const Point<T>& pos) const noexcept;
  85. bool containsX(T x) const noexcept;
  86. bool containsY(T y) const noexcept;
  87. void setX(T x) noexcept;
  88. void setY(T y) noexcept;
  89. void setPos(T x, T y) noexcept;
  90. void setPos(const Point<T>& pos) noexcept;
  91. void move(T x, T y) noexcept;
  92. void move(const Point<T>& pos) noexcept;
  93. void setWidth(T width) noexcept;
  94. void setHeight(T height) noexcept;
  95. void setSize(T width, T height) noexcept;
  96. void setSize(const Size<T>& size) noexcept;
  97. Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;
  98. private:
  99. Point<T> fPos;
  100. Size<T> fSize;
  101. };
  102. // -----------------------------------------------------------------------
  103. END_NAMESPACE_DGL
  104. #endif // DGL_GEOMETRY_HPP_INCLUDED