Browse Source

Add Line class

gh-pages
falkTX 10 years ago
parent
commit
c4ace38212
2 changed files with 222 additions and 0 deletions
  1. +46
    -0
      dgl/Geometry.hpp
  2. +176
    -0
      dgl/src/Geometry.cpp

+ 46
- 0
dgl/Geometry.hpp View File

@@ -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;
};

@@ -93,6 +95,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
{


+ 176
- 0
dgl/src/Geometry.cpp View File

@@ -258,6 +258,177 @@ bool Size<T>::operator!=(const Size<T>& size) const noexcept
return !operator==(size);
}

// -----------------------------------------------------------------------
// 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

@@ -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>;


Loading…
Cancel
Save