/* * DISTRHO Plugin Toolkit (DPT) * Copyright (C) 2012-2013 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this * permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "../Geometry.hpp" START_NAMESPACE_DGL // ----------------------------------------------------------------------- // Point template Point::Point() noexcept : fX(0), fY(0) { } template Point::Point(T x, T y) noexcept : fX(x), fY(y) { } template Point::Point(const Point& pos) noexcept : fX(pos.fX), fY(pos.fY) { } template T Point::getX() const noexcept { return fX; } template T Point::getY() const noexcept { return fY; } template void Point::setX(T x) noexcept { fX = x; } template void Point::setY(T y) noexcept { fY = y; } template void Point::move(T x, T y) noexcept { fX += x; fY += y; } template void Point::move(const Point& pos) noexcept { fX += pos.fX; fY += pos.fY; } template Point& Point::operator=(const Point& pos) noexcept { fX = pos.fX; fY = pos.fY; return *this; } template Point& Point::operator+=(const Point& pos) noexcept { fX += pos.fX; fY += pos.fY; return *this; } template Point& Point::operator-=(const Point& pos) noexcept { fX -= pos.fX; fY -= pos.fY; return *this; } template bool Point::operator==(const Point& pos) const noexcept { return (fX == pos.fX && fY== pos.fY); } template bool Point::operator!=(const Point& pos) const noexcept { return !operator==(pos); } // ----------------------------------------------------------------------- // Size template Size::Size() noexcept : fWidth(0), fHeight(0) { } template Size::Size(T width, T height) noexcept : fWidth(width), fHeight(height) { } template Size::Size(const Size& size) noexcept : fWidth(size.fWidth), fHeight(size.fHeight) { } template T Size::getWidth() const noexcept { return fWidth; } template T Size::getHeight() const noexcept { return fHeight; } template void Size::setWidth(T width) noexcept { fWidth = width; } template void Size::setHeight(T height) noexcept { fHeight = height; } template Size& Size::operator=(const Size& size) noexcept { fWidth = size.fWidth; fHeight = size.fHeight; return *this; } template Size& Size::operator+=(const Size& size) noexcept { fWidth += size.fWidth; fHeight += size.fHeight; return *this; } template Size& Size::operator-=(const Size& size) noexcept { fWidth -= size.fWidth; fHeight -= size.fHeight; return *this; } template Size& Size::operator*=(T m) noexcept { fWidth *= m; fHeight *= m; return *this; } template Size& Size::operator/=(T d) noexcept { fWidth /= d; fHeight /= d; return *this; } template bool Size::operator==(const Size& size) const noexcept { return (fWidth == size.fWidth && fHeight == size.fHeight); } template bool Size::operator!=(const Size& size) const noexcept { return !operator==(size); } // ----------------------------------------------------------------------- // Rectangle template Rectangle::Rectangle() noexcept : fPos(0, 0), fSize(0, 0) { } template Rectangle::Rectangle(T x, T y, T width, T height) noexcept : fPos(x, y), fSize(width, height) { } template Rectangle::Rectangle(T x, T y, const Size& size) noexcept : fPos(x, y), fSize(size) { } template Rectangle::Rectangle(const Point& pos, T width, T height) noexcept : fPos(pos), fSize(width, height) { } template Rectangle::Rectangle(const Point& pos, const Size& size) noexcept : fPos(pos), fSize(size) { } template Rectangle::Rectangle(const Rectangle& rect) noexcept : fPos(rect.fPos), fSize(rect.fSize) { } template T Rectangle::getX() const noexcept { return fPos.fX; } template T Rectangle::getY() const noexcept { return fPos.fY; } template T Rectangle::getWidth() const noexcept { return fSize.fWidth; } template T Rectangle::getHeight() const noexcept { return fSize.fHeight; } template const Point& Rectangle::getPos() const noexcept { return fPos; } template const Size& Rectangle::getSize() const noexcept { return fSize; } template bool Rectangle::contains(T x, T y) const noexcept { return (x >= fPos.fX && y >= fPos.fY && x <= fPos.fX+fSize.fWidth && y <= fPos.fY+fSize.fHeight); } template bool Rectangle::contains(const Point& pos) const noexcept { return contains(pos.fX, pos.fY); } template bool Rectangle::containsX(T x) const noexcept { return (x >= fPos.fX && x <= fPos.fX + fSize.fWidth); } template bool Rectangle::containsY(T y) const noexcept { return (y >= fPos.fY && y <= fPos.fY + fSize.fHeight); } template void Rectangle::setX(T x) noexcept { fPos.fX = x; } template void Rectangle::setY(T y) noexcept { fPos.fY = y; } template void Rectangle::setPos(T x, T y) noexcept { fPos.fX = x; fPos.fY = y; } template void Rectangle::setPos(const Point& pos) noexcept { fPos = pos; } template void Rectangle::move(T x, T y) noexcept { fPos.fX += x; fPos.fY += y; } template void Rectangle::move(const Point& pos) noexcept { fPos += pos; } template void Rectangle::setWidth(T width) noexcept { fSize.fWidth = width; } template void Rectangle::setHeight(T height) noexcept { fSize.fHeight = height; } template void Rectangle::setSize(T width, T height) noexcept { fSize.fWidth = width; fSize.fHeight = height; } template void Rectangle::setSize(const Size& size) noexcept { fSize = size; } template Rectangle& Rectangle::operator=(const Rectangle& rect) noexcept { fPos = rect.fPos; fSize = rect.fSize; return *this; } // ----------------------------------------------------------------------- // Possible template data types template class Point; template class Point; template class Point; template class Point; template class Size; template class Size; template class Size; template class Size; template class Rectangle; template class Rectangle; template class Rectangle; template class Rectangle; // ----------------------------------------------------------------------- END_NAMESPACE_DGL