DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit c4ace382129ee43fffddf54ea1c01818176589bc
parent 3c37079c2b2d5b8654246e6484c4f671f4335d46
Author: falkTX <falktx@gmail.com>
Date:   Sat, 10 May 2014 13:15:32 +0100

Add Line class

Diffstat:
Mdgl/Geometry.hpp | 46++++++++++++++++++++++++++++++++++++++++++++++
Mdgl/src/Geometry.cpp | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 222 insertions(+), 0 deletions(-)

diff --git a/dgl/Geometry.hpp b/dgl/Geometry.hpp @@ -23,6 +23,7 @@ START_NAMESPACE_DGL // ----------------------------------------------------------------------- +template<typename> class Line; template<typename> class Rectangle; // ----------------------------------------------------------------------- @@ -54,6 +55,7 @@ public: private: T fX, fY; + template<typename> friend class Line; template<typename> friend class Rectangle; }; @@ -94,6 +96,50 @@ private: // ----------------------------------------------------------------------- template<typename T> +class Line +{ +public: + Line() noexcept; + Line(const T& startX, const T& startY, const T& endX, const T& endY) noexcept; + Line(const T& startX, const T& startY, const Point<T>& endPos) noexcept; + Line(const Point<T>& startPos, const T& endX, const T& endY) noexcept; + Line(const Point<T>& startPos, const Point<T>& endPos) noexcept; + Line(const Line<T>& line) noexcept; + + const T& getStartX() const noexcept; + const T& getStartY() const noexcept; + const T& getEndX() const noexcept; + const T& getEndY() const noexcept; + + const Point<T>& getStartPos() const noexcept; + const Point<T>& getEndPos() const noexcept; + + void setStartX(const T& x) noexcept; + void setStartY(const T& y) noexcept; + void setStartPos(const T& x, const T& y) noexcept; + void setStartPos(const Point<T>& pos) noexcept; + + void setEndX(const T& x) noexcept; + void setEndY(const T& y) noexcept; + void setEndPos(const T& x, const T& y) noexcept; + void setEndPos(const Point<T>& pos) noexcept; + + void moveBy(const T& x, const T& y) noexcept; + void moveBy(const Point<T>& pos) noexcept; + + void draw(); + + Line<T>& operator=(const Line<T>& line) noexcept; + bool operator==(const Line<T>& line) const noexcept; + bool operator!=(const Line<T>& line) const noexcept; + +private: + Point<T> fPosStart, fPosEnd; +}; + +// ----------------------------------------------------------------------- + +template<typename T> class Rectangle { public: diff --git a/dgl/src/Geometry.cpp b/dgl/src/Geometry.cpp @@ -259,6 +259,177 @@ bool Size<T>::operator!=(const Size<T>& size) const noexcept } // ----------------------------------------------------------------------- +// Line + +template<typename T> +Line<T>::Line() noexcept + : fPosStart(0, 0), + fPosEnd(0, 0) +{ +} + +template<typename T> +Line<T>::Line(const T& startX, const T& startY, const T& endX, const T& endY) noexcept + : fPosStart(startX, startY), + fPosEnd(endX, endY) +{ +} + +template<typename T> +Line<T>::Line(const T& startX, const T& startY, const Point<T>& endPos) noexcept + : fPosStart(startX, startY), + fPosEnd(endPos) +{ +} + +template<typename T> +Line<T>::Line(const Point<T>& startPos, const T& endX, const T& endY) noexcept + : fPosStart(startPos), + fPosEnd(endX, endY) +{ +} + +template<typename T> +Line<T>::Line(const Point<T>& startPos, const Point<T>& endPos) noexcept + : fPosStart(startPos), + fPosEnd(endPos) +{ +} + +template<typename T> +Line<T>::Line(const Line<T>& line) noexcept + : fPosStart(line.fPosStart), + fPosEnd(line.fPosEnd) +{ +} + +template<typename T> +const T& Line<T>::getStartX() const noexcept +{ + return fPosStart.fX; +} + +template<typename T> +const T& Line<T>::getStartY() const noexcept +{ + return fPosStart.fY; +} + +template<typename T> +const T& Line<T>::getEndX() const noexcept +{ + return fPosEnd.fX; +} + +template<typename T> +const T& Line<T>::getEndY() const noexcept +{ + return fPosEnd.fY; +} + +template<typename T> +const Point<T>& Line<T>::getStartPos() const noexcept +{ + return fPosStart; +} + +template<typename T> +const Point<T>& Line<T>::getEndPos() const noexcept +{ + return fPosEnd; +} + +template<typename T> +void Line<T>::setStartX(const T& x) noexcept +{ + fPosStart.fX = x; +} + +template<typename T> +void Line<T>::setStartY(const T& y) noexcept +{ + fPosStart.fY = y; +} + +template<typename T> +void Line<T>::setStartPos(const T& x, const T& y) noexcept +{ + fPosStart = Point<T>(x, y); +} + +template<typename T> +void Line<T>::setStartPos(const Point<T>& pos) noexcept +{ + fPosStart = pos; +} + +template<typename T> +void Line<T>::setEndX(const T& x) noexcept +{ + fPosEnd.fX = x; +} + +template<typename T> +void Line<T>::setEndY(const T& y) noexcept +{ + fPosEnd.fY = y; +} + +template<typename T> +void Line<T>::setEndPos(const T& x, const T& y) noexcept +{ + fPosEnd = Point<T>(x, y); +} + +template<typename T> +void Line<T>::setEndPos(const Point<T>& pos) noexcept +{ + fPosEnd = pos; +} + +template<typename T> +void Line<T>::moveBy(const T& x, const T& y) noexcept +{ + fPosStart.fX += x; + fPosStart.fY += y; + fPosEnd.fX += x; + fPosEnd.fY += y; +} + +template<typename T> +void Line<T>::moveBy(const Point<T>& pos) noexcept +{ + fPosStart += pos; + fPosEnd += pos; +} + +template<typename T> +void Line<T>::draw() +{ + // TODO +} + +template<typename T> +Line<T>& Line<T>::operator=(const Line<T>& line) noexcept +{ + fPosStart = line.fPosStart; + fPosEnd = line.fPosEnd; + return *this; +} + +template<typename T> +bool Line<T>::operator==(const Line<T>& line) const noexcept +{ + return (fPosStart == line.fPosStart && fPosEnd == line.fPosEnd); +} + +template<typename T> +bool Line<T>::operator!=(const Line<T>& line) const noexcept +{ + return !operator==(line); +} + +// ----------------------------------------------------------------------- // Rectangle template<typename T> @@ -532,6 +703,11 @@ template class Size<float>; template class Size<int>; template class Size<short>; +template class Line<double>; +template class Line<float>; +template class Line<int>; +template class Line<short>; + template class Rectangle<double>; template class Rectangle<float>; template class Rectangle<int>;