[nostalgia/common] Add Vec2 type
This commit is contained in:
parent
142c78db0e
commit
0e7a090d28
@ -2,6 +2,7 @@
|
|||||||
add_library(
|
add_library(
|
||||||
NostalgiaCommon
|
NostalgiaCommon
|
||||||
bounds.cpp
|
bounds.cpp
|
||||||
|
vec.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
@ -18,6 +19,7 @@ install(
|
|||||||
common.hpp
|
common.hpp
|
||||||
point.hpp
|
point.hpp
|
||||||
size.hpp
|
size.hpp
|
||||||
|
vec.hpp
|
||||||
DESTINATION
|
DESTINATION
|
||||||
include/nostalgia/common
|
include/nostalgia/common
|
||||||
)
|
)
|
||||||
|
18
src/nostalgia/common/vec.cpp
Normal file
18
src/nostalgia/common/vec.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ox/std/defines.hpp>
|
||||||
|
|
||||||
|
#include "vec.hpp"
|
||||||
|
|
||||||
|
namespace nostalgia::common {
|
||||||
|
|
||||||
|
#ifndef OX_OS_BareMetal // doesn't compile in devKitPro for some reason
|
||||||
|
static_assert([] {
|
||||||
|
Vec2 v(1, 2);
|
||||||
|
return v.x == 1 && v.y == 2 && v[0] == 1 && v[1] == 2;
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
44
src/nostalgia/common/vec.hpp
Normal file
44
src/nostalgia/common/vec.hpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if __has_include(<imgui.h>)
|
||||||
|
#include <imgui.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <ox/std/types.hpp>
|
||||||
|
|
||||||
|
namespace nostalgia::common {
|
||||||
|
|
||||||
|
struct Vec2 {
|
||||||
|
float x = 0;
|
||||||
|
float y = 0;
|
||||||
|
|
||||||
|
constexpr Vec2() noexcept = default;
|
||||||
|
|
||||||
|
constexpr Vec2(float pX, float pY) noexcept: x(pX), y(pY) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __has_include(<imgui.h>)
|
||||||
|
explicit constexpr Vec2(const ImVec2 &v) noexcept: x(v.x), y(v.y) {
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
constexpr auto &operator[](std::size_t i) noexcept {
|
||||||
|
return (&x)[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const auto &operator[](std::size_t i) const noexcept {
|
||||||
|
return (&x)[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __has_include(<imgui.h>)
|
||||||
|
explicit operator ImVec2() const noexcept {
|
||||||
|
return {x, y};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user