[nostalgia/common] Add constexpr and noexcept where appropriate
This commit is contained in:
parent
4518288745
commit
2dc9ce4015
@ -9,34 +9,34 @@
|
||||
|
||||
namespace nostalgia::common {
|
||||
|
||||
Bounds::Bounds(int x, int y, int w, int h) {
|
||||
Bounds::Bounds(int x, int y, int w, int h) noexcept {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->width = w;
|
||||
this->height = h;
|
||||
}
|
||||
|
||||
bool Bounds::intersects(Bounds o) const {
|
||||
bool Bounds::intersects(const Bounds &o) const noexcept {
|
||||
return o.x2() >= x && x2() >= o.x && o.y2() >= y && y2() >= o.y;
|
||||
}
|
||||
|
||||
bool Bounds::contains(int x, int y) const {
|
||||
bool Bounds::contains(int x, int y) const noexcept {
|
||||
return x >= this->x && y >= this->y && x <= x2() && y <= y2();
|
||||
}
|
||||
|
||||
int Bounds::x2() const {
|
||||
int Bounds::x2() const noexcept {
|
||||
return x + width;
|
||||
}
|
||||
|
||||
int Bounds::y2() const {
|
||||
int Bounds::y2() const noexcept {
|
||||
return y + height;
|
||||
}
|
||||
|
||||
Point Bounds::pt1() {
|
||||
Point Bounds::pt1() const noexcept {
|
||||
return Point(x, y);
|
||||
}
|
||||
|
||||
Point Bounds::pt2() {
|
||||
Point Bounds::pt2() const noexcept {
|
||||
return Point(x2(), y2());
|
||||
}
|
||||
|
||||
|
@ -23,26 +23,32 @@ class Bounds {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
Bounds() = default;
|
||||
constexpr Bounds() noexcept = default;
|
||||
|
||||
Bounds(int x, int y, int w, int h);
|
||||
Bounds(int x, int y, int w, int h) noexcept;
|
||||
|
||||
[[nodiscard]] bool intersects(Bounds other) const;
|
||||
[[nodiscard]]
|
||||
bool intersects(const Bounds &other) const noexcept;
|
||||
|
||||
[[nodiscard]] bool contains(int x, int y) const;
|
||||
[[nodiscard]]
|
||||
bool contains(int x, int y) const noexcept;
|
||||
|
||||
[[nodiscard]] int x2() const;
|
||||
[[nodiscard]]
|
||||
int x2() const noexcept;
|
||||
|
||||
[[nodiscard]] int y2() const;
|
||||
[[nodiscard]]
|
||||
int y2() const noexcept;
|
||||
|
||||
[[nodiscard]] Point pt1();
|
||||
[[nodiscard]]
|
||||
Point pt1() const noexcept;
|
||||
|
||||
[[nodiscard]] Point pt2();
|
||||
[[nodiscard]]
|
||||
Point pt2() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
ox::Error model(T *io, Bounds *obj) {
|
||||
constexpr ox::Error model(T *io, Bounds *obj) {
|
||||
io->template setTypeInfo<Point>();
|
||||
oxReturnError(io->field("x", &obj->x));
|
||||
oxReturnError(io->field("y", &obj->y));
|
||||
|
@ -20,172 +20,174 @@ class Point {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
constexpr Point() = default;
|
||||
constexpr Point() noexcept = default;
|
||||
|
||||
constexpr Point(int x, int y);
|
||||
constexpr Point(int x, int y) noexcept;
|
||||
|
||||
constexpr Point operator+(common::Point p) const;
|
||||
constexpr Point operator+(const common::Point &p) const noexcept;
|
||||
|
||||
constexpr Point operator-(common::Point p) const;
|
||||
constexpr Point operator-(const common::Point &p) const noexcept;
|
||||
|
||||
constexpr Point operator*(common::Point p) const;
|
||||
constexpr Point operator*(const common::Point &p) const noexcept;
|
||||
|
||||
constexpr Point operator/(common::Point p) const;
|
||||
constexpr Point operator/(const common::Point &p) const noexcept;
|
||||
|
||||
|
||||
constexpr Point operator+=(common::Point p);
|
||||
constexpr Point operator+=(const common::Point &p) noexcept;
|
||||
|
||||
constexpr Point operator-=(common::Point p);
|
||||
constexpr Point operator-=(const common::Point &p) noexcept;
|
||||
|
||||
constexpr Point operator*=(common::Point p);
|
||||
constexpr Point operator*=(const common::Point &p) noexcept;
|
||||
|
||||
constexpr Point operator/=(common::Point p);
|
||||
constexpr Point operator/=(const common::Point &p) noexcept;
|
||||
|
||||
|
||||
constexpr Point operator+(int i) const;
|
||||
constexpr Point operator+(int i) const noexcept;
|
||||
|
||||
constexpr Point operator-(int i) const;
|
||||
constexpr Point operator-(int i) const noexcept;
|
||||
|
||||
constexpr Point operator*(int i) const;
|
||||
constexpr Point operator*(int i) const noexcept;
|
||||
|
||||
constexpr Point operator/(int i) const;
|
||||
constexpr Point operator/(int i) const noexcept;
|
||||
|
||||
|
||||
constexpr Point operator+=(int i);
|
||||
constexpr Point operator+=(int i) noexcept;
|
||||
|
||||
constexpr Point operator-=(int i);
|
||||
constexpr Point operator-=(int i) noexcept;
|
||||
|
||||
constexpr Point operator*=(int i);
|
||||
constexpr Point operator*=(int i) noexcept;
|
||||
|
||||
constexpr Point operator/=(int i);
|
||||
constexpr Point operator/=(int i) noexcept;
|
||||
|
||||
|
||||
constexpr bool operator==(const Point&) const;
|
||||
constexpr bool operator==(const Point&) const noexcept;
|
||||
|
||||
constexpr bool operator!=(const Point&) const;
|
||||
constexpr bool operator!=(const Point&) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
constexpr Point::Point(int x, int y) {
|
||||
constexpr Point::Point(int x, int y) noexcept {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator+(common::Point p) const {
|
||||
p.x += x;
|
||||
p.y += y;
|
||||
constexpr Point Point::operator+(const common::Point &p) const noexcept {
|
||||
auto out = *this;
|
||||
out.x += x;
|
||||
out.y += y;
|
||||
return p;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator-(common::Point p) const {
|
||||
constexpr Point Point::operator-(const common::Point &p) const noexcept {
|
||||
auto out = *this;
|
||||
out.x -= p.x;
|
||||
out.y -= p.y;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator*(common::Point p) const {
|
||||
p.x *= x;
|
||||
p.y *= y;
|
||||
constexpr Point Point::operator*(const common::Point &p) const noexcept {
|
||||
auto out = *this;
|
||||
out.x *= x;
|
||||
out.y *= y;
|
||||
return p;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator/(common::Point p) const {
|
||||
constexpr Point Point::operator/(const common::Point &p) const noexcept {
|
||||
auto out = *this;
|
||||
out.x /= p.x;
|
||||
out.y /= p.y;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator+=(common::Point p) {
|
||||
constexpr Point Point::operator+=(const common::Point &p) noexcept {
|
||||
x += p.x;
|
||||
y += p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator-=(common::Point p) {
|
||||
constexpr Point Point::operator-=(const common::Point &p) noexcept {
|
||||
x -= p.x;
|
||||
y -= p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator*=(common::Point p) {
|
||||
constexpr Point Point::operator*=(const common::Point &p) noexcept {
|
||||
x *= p.x;
|
||||
y *= p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator/=(common::Point p) {
|
||||
constexpr Point Point::operator/=(const common::Point &p) noexcept {
|
||||
x /= p.x;
|
||||
y /= p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
constexpr Point Point::operator+(int i) const {
|
||||
constexpr Point Point::operator+(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.x += i;
|
||||
out.y += i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator-(int i) const {
|
||||
constexpr Point Point::operator-(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.x -= i;
|
||||
out.y -= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator*(int i) const {
|
||||
constexpr Point Point::operator*(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.x *= i;
|
||||
out.y *= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator/(int i) const {
|
||||
constexpr Point Point::operator/(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.x /= i;
|
||||
out.y /= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator+=(int i) {
|
||||
constexpr Point Point::operator+=(int i) noexcept {
|
||||
x += i;
|
||||
y += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator-=(int i) {
|
||||
constexpr Point Point::operator-=(int i) noexcept {
|
||||
x -= i;
|
||||
y -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator*=(int i) {
|
||||
constexpr Point Point::operator*=(int i) noexcept {
|
||||
x *= i;
|
||||
y *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Point Point::operator/=(int i) {
|
||||
constexpr Point Point::operator/=(int i) noexcept {
|
||||
x /= i;
|
||||
y /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool Point::operator==(const Point &p) const {
|
||||
constexpr bool Point::operator==(const Point &p) const noexcept {
|
||||
return x == p.x && y == p.y;
|
||||
}
|
||||
|
||||
|
||||
constexpr bool Point::operator!=(const Point &p) const {
|
||||
constexpr bool Point::operator!=(const Point &p) const noexcept {
|
||||
return x != p.x || y != p.y;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
ox::Error model(T *io, Point *obj) {
|
||||
constexpr ox::Error model(T *io, Point *obj) {
|
||||
io->template setTypeInfo<Point>();
|
||||
oxReturnError(io->field("x", &obj->x));
|
||||
oxReturnError(io->field("y", &obj->y));
|
||||
|
@ -20,172 +20,172 @@ class Size {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
constexpr Size() = default;
|
||||
constexpr Size() noexcept = default;
|
||||
|
||||
constexpr Size(int width, int height);
|
||||
constexpr Size(int width, int height) noexcept;
|
||||
|
||||
constexpr Size operator+(common::Size p) const;
|
||||
constexpr Size operator+(common::Size p) const noexcept;
|
||||
|
||||
constexpr Size operator-(common::Size p) const;
|
||||
constexpr Size operator-(common::Size p) const noexcept;
|
||||
|
||||
constexpr Size operator*(common::Size p) const;
|
||||
constexpr Size operator*(common::Size p) const noexcept;
|
||||
|
||||
constexpr Size operator/(common::Size p) const;
|
||||
constexpr Size operator/(common::Size p) const noexcept;
|
||||
|
||||
|
||||
constexpr Size operator+=(common::Size p);
|
||||
constexpr Size operator+=(common::Size p) noexcept;
|
||||
|
||||
constexpr Size operator-=(common::Size p);
|
||||
constexpr Size operator-=(common::Size p) noexcept;
|
||||
|
||||
constexpr Size operator*=(common::Size p);
|
||||
constexpr Size operator*=(common::Size p) noexcept;
|
||||
|
||||
constexpr Size operator/=(common::Size p);
|
||||
constexpr Size operator/=(common::Size p) noexcept;
|
||||
|
||||
|
||||
constexpr Size operator+(int i) const;
|
||||
constexpr Size operator+(int i) const noexcept;
|
||||
|
||||
constexpr Size operator-(int i) const;
|
||||
constexpr Size operator-(int i) const noexcept;
|
||||
|
||||
constexpr Size operator*(int i) const;
|
||||
constexpr Size operator*(int i) const noexcept;
|
||||
|
||||
constexpr Size operator/(int i) const;
|
||||
constexpr Size operator/(int i) const noexcept;
|
||||
|
||||
|
||||
constexpr Size operator+=(int i);
|
||||
constexpr Size operator+=(int i) noexcept;
|
||||
|
||||
constexpr Size operator-=(int i);
|
||||
constexpr Size operator-=(int i) noexcept;
|
||||
|
||||
constexpr Size operator*=(int i);
|
||||
constexpr Size operator*=(int i) noexcept;
|
||||
|
||||
constexpr Size operator/=(int i);
|
||||
constexpr Size operator/=(int i) noexcept;
|
||||
|
||||
|
||||
constexpr bool operator==(const Size&) const;
|
||||
constexpr bool operator==(const Size&) const noexcept;
|
||||
|
||||
constexpr bool operator!=(const Size&) const;
|
||||
constexpr bool operator!=(const Size&) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
constexpr Size::Size(int width, int height) {
|
||||
constexpr Size::Size(int width, int height) noexcept {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator+(common::Size p) const {
|
||||
constexpr Size Size::operator+(common::Size p) const noexcept {
|
||||
p.width += width;
|
||||
p.height += height;
|
||||
return p;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator-(common::Size p) const {
|
||||
constexpr Size Size::operator-(common::Size p) const noexcept {
|
||||
auto out = *this;
|
||||
out.width -= p.width;
|
||||
out.height -= p.height;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator*(common::Size p) const {
|
||||
constexpr Size Size::operator*(common::Size p) const noexcept {
|
||||
p.width *= width;
|
||||
p.height *= height;
|
||||
return p;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator/(common::Size p) const {
|
||||
constexpr Size Size::operator/(common::Size p) const noexcept {
|
||||
auto out = *this;
|
||||
out.width /= p.width;
|
||||
out.height /= p.height;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator+=(common::Size p) {
|
||||
constexpr Size Size::operator+=(common::Size p) noexcept {
|
||||
width += p.width;
|
||||
height += p.height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator-=(common::Size p) {
|
||||
constexpr Size Size::operator-=(common::Size p) noexcept {
|
||||
width -= p.width;
|
||||
height -= p.height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator*=(common::Size p) {
|
||||
constexpr Size Size::operator*=(common::Size p) noexcept {
|
||||
width *= p.width;
|
||||
height *= p.height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator/=(common::Size p) {
|
||||
constexpr Size Size::operator/=(common::Size p) noexcept {
|
||||
width /= p.width;
|
||||
height /= p.height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
constexpr Size Size::operator+(int i) const {
|
||||
constexpr Size Size::operator+(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.width += i;
|
||||
out.height += i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator-(int i) const {
|
||||
constexpr Size Size::operator-(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.width -= i;
|
||||
out.height -= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator*(int i) const {
|
||||
constexpr Size Size::operator*(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.width *= i;
|
||||
out.height *= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator/(int i) const {
|
||||
constexpr Size Size::operator/(int i) const noexcept {
|
||||
auto out = *this;
|
||||
out.width /= i;
|
||||
out.height /= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator+=(int i) {
|
||||
constexpr Size Size::operator+=(int i) noexcept {
|
||||
width += i;
|
||||
height += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator-=(int i) {
|
||||
constexpr Size Size::operator-=(int i) noexcept {
|
||||
width -= i;
|
||||
height -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator*=(int i) {
|
||||
constexpr Size Size::operator*=(int i) noexcept {
|
||||
width *= i;
|
||||
height *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Size Size::operator/=(int i) {
|
||||
constexpr Size Size::operator/=(int i) noexcept {
|
||||
width /= i;
|
||||
height /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool Size::operator==(const Size &p) const {
|
||||
constexpr bool Size::operator==(const Size &p) const noexcept {
|
||||
return width == p.width && height == p.height;
|
||||
}
|
||||
|
||||
|
||||
constexpr bool Size::operator!=(const Size &p) const {
|
||||
constexpr bool Size::operator!=(const Size &p) const noexcept {
|
||||
return width != p.width || height != p.height;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
ox::Error model(T *io, Size *obj) {
|
||||
constexpr ox::Error model(T *io, Size *obj) {
|
||||
io->template setTypeInfo<Size>();
|
||||
oxReturnError(io->field("width", &obj->width));
|
||||
oxReturnError(io->field("height", &obj->height));
|
||||
|
Loading…
x
Reference in New Issue
Block a user