[nostalgia/common] constexpr-ize Point
This commit is contained in:
parent
a2c012ead4
commit
cd5c3afce7
@ -2,7 +2,6 @@
|
|||||||
add_library(
|
add_library(
|
||||||
NostalgiaCommon
|
NostalgiaCommon
|
||||||
bounds.cpp
|
bounds.cpp
|
||||||
point.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
#install(TARGETS NostalgiaCommon DESTINATION lib)
|
#install(TARGETS NostalgiaCommon DESTINATION lib)
|
||||||
|
@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2016 - 2019 gtalent2@gmail.com
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* 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/.
|
|
||||||
*/
|
|
||||||
#include "point.hpp"
|
|
||||||
|
|
||||||
namespace nostalgia::common {
|
|
||||||
|
|
||||||
Point::Point() {
|
|
||||||
}
|
|
||||||
|
|
||||||
Point::Point(int x, int y) {
|
|
||||||
this->x = x;
|
|
||||||
this->y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator+(common::Point p) const {
|
|
||||||
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;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator*(common::Point p) const {
|
|
||||||
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;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator+=(common::Point p) {
|
|
||||||
x += p.x;
|
|
||||||
y += p.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator-=(common::Point p) {
|
|
||||||
x -= p.x;
|
|
||||||
y -= p.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator*=(common::Point p) {
|
|
||||||
x *= p.x;
|
|
||||||
y *= p.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator/=(common::Point p) {
|
|
||||||
x /= p.x;
|
|
||||||
y /= p.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Point Point::operator+(int i) const {
|
|
||||||
auto out = *this;
|
|
||||||
out.x += i;
|
|
||||||
out.y += i;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator-(int i) const {
|
|
||||||
auto out = *this;
|
|
||||||
out.x -= i;
|
|
||||||
out.y -= i;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator*(int i) const {
|
|
||||||
auto out = *this;
|
|
||||||
out.x *= i;
|
|
||||||
out.y *= i;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator/(int i) const {
|
|
||||||
auto out = *this;
|
|
||||||
out.x /= i;
|
|
||||||
out.y /= i;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator+=(int i) {
|
|
||||||
x += i;
|
|
||||||
y += i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator-=(int i) {
|
|
||||||
x -= i;
|
|
||||||
y -= i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator*=(int i) {
|
|
||||||
x *= i;
|
|
||||||
y *= i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Point::operator/=(int i) {
|
|
||||||
x /= i;
|
|
||||||
y /= i;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -17,46 +17,163 @@ class Point {
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
Point();
|
constexpr Point() = default;
|
||||||
|
|
||||||
Point(int x, int y);
|
constexpr Point(int x, int y);
|
||||||
|
|
||||||
Point operator+(common::Point p) const;
|
constexpr Point operator+(common::Point p) const;
|
||||||
|
|
||||||
Point operator-(common::Point p) const;
|
constexpr Point operator-(common::Point p) const;
|
||||||
|
|
||||||
Point operator*(common::Point p) const;
|
constexpr Point operator*(common::Point p) const;
|
||||||
|
|
||||||
Point operator/(common::Point p) const;
|
constexpr Point operator/(common::Point p) const;
|
||||||
|
|
||||||
|
|
||||||
Point operator+=(common::Point p);
|
constexpr Point operator+=(common::Point p);
|
||||||
|
|
||||||
Point operator-=(common::Point p);
|
constexpr Point operator-=(common::Point p);
|
||||||
|
|
||||||
Point operator*=(common::Point p);
|
constexpr Point operator*=(common::Point p);
|
||||||
|
|
||||||
Point operator/=(common::Point p);
|
constexpr Point operator/=(common::Point p);
|
||||||
|
|
||||||
|
|
||||||
Point operator+(int i) const;
|
constexpr Point operator+(int i) const;
|
||||||
|
|
||||||
Point operator-(int i) const;
|
constexpr Point operator-(int i) const;
|
||||||
|
|
||||||
Point operator*(int i) const;
|
constexpr Point operator*(int i) const;
|
||||||
|
|
||||||
Point operator/(int i) const;
|
constexpr Point operator/(int i) const;
|
||||||
|
|
||||||
|
|
||||||
Point operator+=(int i);
|
constexpr Point operator+=(int i);
|
||||||
|
|
||||||
Point operator-=(int i);
|
constexpr Point operator-=(int i);
|
||||||
|
|
||||||
Point operator*=(int i);
|
constexpr Point operator*=(int i);
|
||||||
|
|
||||||
|
constexpr Point operator/=(int i);
|
||||||
|
|
||||||
|
|
||||||
|
constexpr bool operator==(const Point&);
|
||||||
|
|
||||||
Point operator/=(int i);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr Point::Point(int x, int y) {
|
||||||
|
this->x = x;
|
||||||
|
this->y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator+(common::Point p) const {
|
||||||
|
p.x += x;
|
||||||
|
p.y += y;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator-(common::Point p) const {
|
||||||
|
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;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator/(common::Point p) const {
|
||||||
|
auto out = *this;
|
||||||
|
out.x /= p.x;
|
||||||
|
out.y /= p.y;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator+=(common::Point p) {
|
||||||
|
x += p.x;
|
||||||
|
y += p.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator-=(common::Point p) {
|
||||||
|
x -= p.x;
|
||||||
|
y -= p.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator*=(common::Point p) {
|
||||||
|
x *= p.x;
|
||||||
|
y *= p.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator/=(common::Point p) {
|
||||||
|
x /= p.x;
|
||||||
|
y /= p.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
constexpr Point Point::operator+(int i) const {
|
||||||
|
auto out = *this;
|
||||||
|
out.x += i;
|
||||||
|
out.y += i;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator-(int i) const {
|
||||||
|
auto out = *this;
|
||||||
|
out.x -= i;
|
||||||
|
out.y -= i;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator*(int i) const {
|
||||||
|
auto out = *this;
|
||||||
|
out.x *= i;
|
||||||
|
out.y *= i;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator/(int i) const {
|
||||||
|
auto out = *this;
|
||||||
|
out.x /= i;
|
||||||
|
out.y /= i;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator+=(int i) {
|
||||||
|
x += i;
|
||||||
|
y += i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator-=(int i) {
|
||||||
|
x -= i;
|
||||||
|
y -= i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator*=(int i) {
|
||||||
|
x *= i;
|
||||||
|
y *= i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Point Point::operator/=(int i) {
|
||||||
|
x /= i;
|
||||||
|
y /= i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool Point::operator==(const Point &p) {
|
||||||
|
return x == p.x && y == p.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error model(T *io, Point *obj) {
|
ox::Error model(T *io, Point *obj) {
|
||||||
auto err = OxError(0);
|
auto err = OxError(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user