Add ioOp functions for Point and Bounds
This commit is contained in:
@@ -14,23 +14,23 @@ Bounds::Bounds() {
|
||||
}
|
||||
|
||||
bool Bounds::intersects(Bounds o) const {
|
||||
return o.x2() >= X && x2() >= o.X && o.y2() >= Y && y2() >= o.Y;
|
||||
return o.x2() >= x && x2() >= o.x && o.y2() >= y && y2() >= o.y;
|
||||
}
|
||||
|
||||
bool Bounds::contains(int x, int y) const {
|
||||
return x >= X && y >= Y && x <= x2() && y <= y2();
|
||||
return x >= this->x && y >= this->y && x <= x2() && y <= y2();
|
||||
}
|
||||
|
||||
int Bounds::x2() const {
|
||||
return X + Width;
|
||||
return x + width;
|
||||
}
|
||||
|
||||
int Bounds::y2() const {
|
||||
return Y + Height;
|
||||
return y + height;
|
||||
}
|
||||
|
||||
Point Bounds::pt1() {
|
||||
return Point(X, Y);
|
||||
return Point(x, y);
|
||||
}
|
||||
|
||||
Point Bounds::pt2() {
|
||||
|
@@ -14,10 +14,10 @@ namespace common {
|
||||
|
||||
class Bounds {
|
||||
public:
|
||||
int X = 0;
|
||||
int Y = 0;
|
||||
int Width = 0;
|
||||
int Height = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -37,5 +37,16 @@ class Bounds {
|
||||
Point pt2();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
ox::Error ioOp(T *io, Bounds *obj) {
|
||||
ox::Error err = 0;
|
||||
io->setFields(4);
|
||||
err |= io->op("x", &obj->x);
|
||||
err |= io->op("y", &obj->y);
|
||||
err |= io->op("width", &obj->width);
|
||||
err |= io->op("height", &obj->height);
|
||||
return err;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -14,110 +14,110 @@ Point::Point() {
|
||||
}
|
||||
|
||||
Point::Point(int x, int y) {
|
||||
X = x;
|
||||
Y = y;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
Point Point::operator+(common::Point p) const {
|
||||
p.X += X;
|
||||
p.Y += Y;
|
||||
p.x += x;
|
||||
p.y += y;
|
||||
return p;
|
||||
}
|
||||
|
||||
Point Point::operator-(common::Point p) const {
|
||||
auto out = *this;
|
||||
out.X -= p.X;
|
||||
out.Y -= p.Y;
|
||||
out.x -= p.x;
|
||||
out.y -= p.y;
|
||||
return out;
|
||||
}
|
||||
|
||||
Point Point::operator*(common::Point p) const {
|
||||
p.X *= X;
|
||||
p.Y *= Y;
|
||||
p.x *= x;
|
||||
p.y *= y;
|
||||
return p;
|
||||
}
|
||||
|
||||
Point Point::operator/(common::Point p) const {
|
||||
auto out = *this;
|
||||
out.X /= p.X;
|
||||
out.Y /= p.Y;
|
||||
out.x /= p.x;
|
||||
out.y /= p.y;
|
||||
return out;
|
||||
}
|
||||
|
||||
Point Point::operator+=(common::Point p) {
|
||||
X += p.X;
|
||||
Y += p.Y;
|
||||
x += p.x;
|
||||
y += p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point Point::operator-=(common::Point p) {
|
||||
X -= p.X;
|
||||
Y -= p.Y;
|
||||
x -= p.x;
|
||||
y -= p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point Point::operator*=(common::Point p) {
|
||||
X *= p.X;
|
||||
Y *= p.Y;
|
||||
x *= p.x;
|
||||
y *= p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point Point::operator/=(common::Point p) {
|
||||
X /= p.X;
|
||||
Y /= p.Y;
|
||||
x /= p.x;
|
||||
y /= p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Point Point::operator+(int i) const {
|
||||
auto out = *this;
|
||||
out.X += i;
|
||||
out.Y += i;
|
||||
out.x += i;
|
||||
out.y += i;
|
||||
return out;
|
||||
}
|
||||
|
||||
Point Point::operator-(int i) const {
|
||||
auto out = *this;
|
||||
out.X -= i;
|
||||
out.Y -= i;
|
||||
out.x -= i;
|
||||
out.y -= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
Point Point::operator*(int i) const {
|
||||
auto out = *this;
|
||||
out.X *= i;
|
||||
out.Y *= i;
|
||||
out.x *= i;
|
||||
out.y *= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
Point Point::operator/(int i) const {
|
||||
auto out = *this;
|
||||
out.X /= i;
|
||||
out.Y /= i;
|
||||
out.x /= i;
|
||||
out.y /= i;
|
||||
return out;
|
||||
}
|
||||
|
||||
Point Point::operator+=(int i) {
|
||||
X += i;
|
||||
Y += i;
|
||||
x += i;
|
||||
y += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point Point::operator-=(int i) {
|
||||
X -= i;
|
||||
Y -= i;
|
||||
x -= i;
|
||||
y -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point Point::operator*=(int i) {
|
||||
X *= i;
|
||||
Y *= i;
|
||||
x *= i;
|
||||
y *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point Point::operator/=(int i) {
|
||||
X /= i;
|
||||
Y /= i;
|
||||
x /= i;
|
||||
y /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@@ -5,15 +5,18 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace common {
|
||||
|
||||
class Point {
|
||||
public:
|
||||
int X = 0;
|
||||
int Y = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
Point();
|
||||
|
||||
@@ -55,5 +58,14 @@ class Point {
|
||||
Point operator/=(int i);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
ox::Error ioOp(T *io, Point *obj) {
|
||||
ox::Error err = 0;
|
||||
io->setFields(2);
|
||||
err |= io->op("x", &obj->x);
|
||||
err |= io->op("y", &obj->y);
|
||||
return err;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user