Rectangle.h#
↰ Parent directory (math
)
Contains A rectangle class.
Includes#
PVRCore/glm.h
PVRCore/types/Types.h
Namespaces#
Classes#
Typedefs#
Source Code#
#pragma once
#include "PVRCore/types/Types.h"
#include "PVRCore/glm.h"
template<typename>
struct GenericOffset2D;
namespace pvr {
template<typename TYPE>
struct Rectangle
{
TYPE x;
TYPE y;
TYPE width;
TYPE height;
glm::tvec2<TYPE, glm::highp> offset() const { return glm::tvec2<TYPE, glm::highp>(x, y); }
glm::tvec2<TYPE, glm::highp> extent() const { return glm::tvec2<TYPE, glm::highp>(width, height); }
glm::tvec2<TYPE, glm::highp> center() const { return offset() + extent() / TYPE(2); }
Rectangle() {}
Rectangle(const GenericOffset2D<TYPE>& offset0, const GenericOffset2D<TYPE>& offset1)
{
x = offset0.x;
y = offset0.y;
width = offset1.x - x;
height = offset1.y - y;
}
Rectangle(TYPE TX, TYPE TY, TYPE TWidth, TYPE THeight) : x(TX), y(TY), width(TWidth), height(THeight) {}
Rectangle(glm::tvec2<TYPE, glm::precision::defaultp> bottomLeft, glm::tvec2<TYPE, glm::precision::defaultp> dimensions)
: x(bottomLeft.x), y(bottomLeft.y), width(dimensions.x), height(dimensions.y)
{}
bool operator==(const Rectangle& rhs) const { return (x == rhs.x) && (y == rhs.y) && (width == rhs.width) && (height == rhs.height); }
bool operator!=(const Rectangle& rhs) const { return !(*this == rhs); }
void expand(const Rectangle& rect)
{
auto minx = glm::min(x, rect.x);
auto miny = glm::min(y, rect.y);
auto maxx = glm::max(x + height, rect.x + rect.width);
auto maxy = glm::max(y + height, rect.y + rect.width);
x = minx;
y = miny;
width = maxx - minx;
height = maxy - miny;
}
};
typedef Rectangle<int32_t> Rectanglei;
typedef Rectangle<float> Rectanglef;
} // namespace pvr