diff --git a/src/nostalgia/geo/CMakeLists.txt b/src/nostalgia/geo/CMakeLists.txt index eda62d45..baf6fbba 100644 --- a/src/nostalgia/geo/CMakeLists.txt +++ b/src/nostalgia/geo/CMakeLists.txt @@ -1,12 +1,11 @@ add_library( NostalgiaGeo - bounds.cpp - vec.cpp + vec.cpp ) target_link_libraries( - NostalgiaGeo + NostalgiaGeo PUBLIC OxStd ) diff --git a/src/nostalgia/geo/bounds.cpp b/src/nostalgia/geo/bounds.cpp deleted file mode 100644 index 14a63977..00000000 --- a/src/nostalgia/geo/bounds.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include "bounds.hpp" - -namespace nostalgia::geo { - -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(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 noexcept { - return x >= this->x && y >= this->y && x <= x2() && y <= y2(); -} - -int Bounds::x2() const noexcept { - return x + width; -} - -int Bounds::y2() const noexcept { - return y + height; -} - -Point Bounds::pt1() const noexcept { - return {x, y}; -} - -Point Bounds::pt2() const noexcept { - return {x2(), y2()}; -} - -} diff --git a/src/nostalgia/geo/bounds.hpp b/src/nostalgia/geo/bounds.hpp index e735279d..4d6b2e66 100644 --- a/src/nostalgia/geo/bounds.hpp +++ b/src/nostalgia/geo/bounds.hpp @@ -4,6 +4,9 @@ #pragma once +#include +#include + #include "point.hpp" namespace nostalgia::geo { @@ -20,36 +23,64 @@ class Bounds { constexpr Bounds() noexcept = default; - Bounds(int x, int y, int w, int h) noexcept; + constexpr Bounds(int x, int y, int w, int h) noexcept; [[nodiscard]] - bool intersects(const Bounds &other) const noexcept; + constexpr bool intersects(const Bounds &other) const noexcept; [[nodiscard]] - bool contains(int x, int y) const noexcept; + constexpr bool contains(int x, int y) const noexcept; [[nodiscard]] - int x2() const noexcept; + constexpr int x2() const noexcept; [[nodiscard]] - int y2() const noexcept; + constexpr int y2() const noexcept; [[nodiscard]] - Point pt1() const noexcept; + constexpr Point pt1() const noexcept; [[nodiscard]] - Point pt2() const noexcept; + constexpr Point pt2() const noexcept; }; -template -constexpr ox::Error model(T *io, Bounds *obj) noexcept { - io->template setTypeInfo(); - oxReturnError(io->field("x", &obj->x)); - oxReturnError(io->field("y", &obj->y)); - oxReturnError(io->field("width", &obj->width)); - oxReturnError(io->field("height", &obj->height)); - return OxError(0); +constexpr Bounds::Bounds(int x, int y, int w, int h) noexcept { + this->x = x; + this->y = y; + this->width = w; + this->height = h; } +constexpr bool Bounds::intersects(const Bounds &o) const noexcept { + return o.x2() >= x && x2() >= o.x && o.y2() >= y && y2() >= o.y; +} + +constexpr bool Bounds::contains(int x, int y) const noexcept { + return x >= this->x && y >= this->y && x <= x2() && y <= y2(); +} + +constexpr int Bounds::x2() const noexcept { + return x + width; +} + +constexpr int Bounds::y2() const noexcept { + return y + height; +} + +constexpr Point Bounds::pt1() const noexcept { + return {x, y}; +} + +constexpr Point Bounds::pt2() const noexcept { + return {x2(), y2()}; +} + +oxModelBegin(Bounds) + oxModelField(x) + oxModelField(y) + oxModelField(width) + oxModelField(height) +oxModelEnd() + } diff --git a/src/nostalgia/geo/point.hpp b/src/nostalgia/geo/point.hpp index 0d4e4cc6..8b2b64a0 100644 --- a/src/nostalgia/geo/point.hpp +++ b/src/nostalgia/geo/point.hpp @@ -4,6 +4,7 @@ #pragma once +#include #include namespace nostalgia::geo { @@ -175,18 +176,13 @@ constexpr bool Point::operator==(const Point &p) const noexcept { return x == p.x && y == p.y; } - constexpr bool Point::operator!=(const Point &p) const noexcept { return x != p.x || y != p.y; } - -template -constexpr ox::Error model(T *io, Point *obj) noexcept { - io->template setTypeInfo(); - oxReturnError(io->field("x", &obj->x)); - oxReturnError(io->field("y", &obj->y)); - return OxError(0); -} +oxModelBegin(Point) + oxModelField(x) + oxModelField(y) +oxModelEnd() } diff --git a/src/nostalgia/geo/size.hpp b/src/nostalgia/geo/size.hpp index 67f14b1b..9a58ca31 100644 --- a/src/nostalgia/geo/size.hpp +++ b/src/nostalgia/geo/size.hpp @@ -145,6 +145,7 @@ constexpr Size Size::operator/(int i) const noexcept { return out; } + constexpr Size Size::operator+=(int i) noexcept { width += i; height += i; @@ -169,22 +170,19 @@ constexpr Size Size::operator/=(int i) noexcept { return *this; } + constexpr bool Size::operator==(const Size &p) const noexcept { return width == p.width && height == p.height; } - constexpr bool Size::operator!=(const Size &p) const noexcept { return width != p.width || height != p.height; } -template -constexpr ox::Error model(T *io, Size *obj) noexcept { - io->template setTypeInfo(); - oxReturnError(io->field("width", &obj->width)); - oxReturnError(io->field("height", &obj->height)); - return OxError(0); -} +oxModelBegin(Size) + oxModelField(width) + oxModelField(height) +oxModelEnd() }