[nostalgia/geo] Cleanup geo package
This commit is contained in:
parent
9b1275e704
commit
9bd10bac78
@ -1,12 +1,11 @@
|
||||
|
||||
add_library(
|
||||
NostalgiaGeo
|
||||
bounds.cpp
|
||||
vec.cpp
|
||||
vec.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaGeo
|
||||
NostalgiaGeo PUBLIC
|
||||
OxStd
|
||||
)
|
||||
|
||||
|
@ -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()};
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/model/def.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
|
||||
#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<typename T>
|
||||
constexpr ox::Error model(T *io, Bounds *obj) noexcept {
|
||||
io->template setTypeInfo<Point>();
|
||||
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()
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/model/def.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
|
||||
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<typename T>
|
||||
constexpr ox::Error model(T *io, Point *obj) noexcept {
|
||||
io->template setTypeInfo<Point>();
|
||||
oxReturnError(io->field("x", &obj->x));
|
||||
oxReturnError(io->field("y", &obj->y));
|
||||
return OxError(0);
|
||||
}
|
||||
oxModelBegin(Point)
|
||||
oxModelField(x)
|
||||
oxModelField(y)
|
||||
oxModelEnd()
|
||||
|
||||
}
|
||||
|
@ -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<typename T>
|
||||
constexpr ox::Error model(T *io, Size *obj) noexcept {
|
||||
io->template setTypeInfo<Size>();
|
||||
oxReturnError(io->field("width", &obj->width));
|
||||
oxReturnError(io->field("height", &obj->height));
|
||||
return OxError(0);
|
||||
}
|
||||
oxModelBegin(Size)
|
||||
oxModelField(width)
|
||||
oxModelField(height)
|
||||
oxModelEnd()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user