mirror of
https://github.com/zetaPRIME/libstarlight.git
synced 2025-06-26 05:32:46 +00:00
clean up datatypes a bit
This commit is contained in:
parent
e7e9ed7de7
commit
017fd97d46
@ -8,13 +8,6 @@
|
|||||||
using starlight::Vector2;
|
using starlight::Vector2;
|
||||||
using starlight::VRect;
|
using starlight::VRect;
|
||||||
|
|
||||||
VRect::VRect() : pos(Vector2()), size(Vector2()) { }
|
|
||||||
|
|
||||||
VRect::~VRect() { }
|
|
||||||
|
|
||||||
VRect::VRect(float x, float y, float w, float h) : pos(x, y), size(w, h) { }
|
|
||||||
VRect::VRect(Vector2 pos, Vector2 size) : pos(pos), size(size) { }
|
|
||||||
|
|
||||||
Vector2 VRect::Center() const { return pos + (size * 0.5f); }
|
Vector2 VRect::Center() const { return pos + (size * 0.5f); }
|
||||||
Vector2 VRect::TopLeft() const { return pos; }
|
Vector2 VRect::TopLeft() const { return pos; }
|
||||||
Vector2 VRect::TopRight() const { return Vector2(pos.x + size.x, pos.y); }
|
Vector2 VRect::TopRight() const { return Vector2(pos.x + size.x, pos.y); }
|
||||||
@ -62,4 +55,6 @@ VRect VRect::LeftEdge(float width) const { return VRect(pos.x, pos.y, width,
|
|||||||
VRect VRect::RightEdge(float width) const { return VRect(pos.x + size.x - width, pos.y, width, size.y); }
|
VRect VRect::RightEdge(float width) const { return VRect(pos.x + size.x - width, pos.y, width, size.y); }
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
const VRect VRect::zero = VRect(); // should initialize to 0,0,0,0
|
const VRect VRect::invalid = VRect(Vector2::invalid, Vector2::invalid);
|
||||||
|
|
||||||
|
const VRect VRect::zero = VRect(); // should initialize to 0,0,0,0
|
||||||
|
@ -12,10 +12,10 @@ namespace starlight {
|
|||||||
Vector2 pos;
|
Vector2 pos;
|
||||||
Vector2 size;
|
Vector2 size;
|
||||||
|
|
||||||
VRect();
|
constexpr VRect() = default;
|
||||||
VRect(float x, float y, float w, float h);
|
constexpr VRect(float x, float y, float w, float h) : pos(x, y), size(w, h) { }
|
||||||
VRect(Vector2 pos, Vector2 size);
|
constexpr VRect(Vector2 pos, Vector2 size) : pos(pos), size(size) { }
|
||||||
~VRect();
|
~VRect() = default;
|
||||||
|
|
||||||
Vector2 Center() const;
|
Vector2 Center() const;
|
||||||
Vector2 TopLeft() const;
|
Vector2 TopLeft() const;
|
||||||
@ -54,6 +54,9 @@ namespace starlight {
|
|||||||
inline VRect & operator += (const Vector2 & vec) { pos += vec; return *this; }
|
inline VRect & operator += (const Vector2 & vec) { pos += vec; return *this; }
|
||||||
inline VRect & operator -= (const Vector2 & vec) { pos -= vec; return *this; }
|
inline VRect & operator -= (const Vector2 & vec) { pos -= vec; return *this; }
|
||||||
|
|
||||||
|
inline explicit operator bool() { return pos && size; }
|
||||||
|
|
||||||
|
static const VRect invalid;
|
||||||
static const VRect zero;
|
static const VRect zero;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fastmath.h>
|
#include <fastmath.h>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#include "Vector2.h"
|
#include "Vector2.h"
|
||||||
|
|
||||||
using starlight::Vector2;
|
using starlight::Vector2;
|
||||||
|
|
||||||
Vector2::Vector2() : x(0.0f), y(0.0f) { }
|
|
||||||
|
|
||||||
Vector2::~Vector2() { }
|
|
||||||
|
|
||||||
Vector2::Vector2(float x, float y) : x(x), y(y) { }
|
|
||||||
|
|
||||||
// maths
|
// maths
|
||||||
float Vector2::Length() const { return sqrtf(x * x + y * y); }
|
float Vector2::Length() const { return sqrtf(x * x + y * y); }
|
||||||
Vector2 Vector2::Normalized() const { float m = Length(); return m == 0.0f ? Vector2::zero : Vector2(x / m, y / m); }
|
Vector2 Vector2::Normalized() const { float m = Length(); return m == 0.0f ? Vector2::zero : Vector2(x / m, y / m); }
|
||||||
@ -35,9 +30,11 @@ Vector2 Vector2::RotateAround(const Vector2& anchor, float angle) const { return
|
|||||||
//inline Vector2 operator *(const Vector2* vec, const float scalar) { return Vector2(vec.x * scalar, vec.y * scalar); }
|
//inline Vector2 operator *(const Vector2* vec, const float scalar) { return Vector2(vec.x * scalar, vec.y * scalar); }
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
|
const Vector2 Vector2::invalid = Vector2(std::numeric_limits<double>::quiet_NaN());
|
||||||
|
|
||||||
const Vector2 Vector2::zero = Vector2(0.0f, 0.0f);
|
const Vector2 Vector2::zero = Vector2(0.0f, 0.0f);
|
||||||
const Vector2 Vector2::one = Vector2(1.0f, 1.0f);
|
const Vector2 Vector2::one = Vector2(1.0f, 1.0f);
|
||||||
const Vector2 Vector2::half = Vector2(0.5f, 0.5f);
|
const Vector2 Vector2::half = Vector2(0.5f, 0.5f);
|
||||||
|
|
||||||
const Vector2 Vector2::h = Vector2(1, 0);
|
const Vector2 Vector2::h = Vector2(1, 0);
|
||||||
const Vector2 Vector2::v = Vector2(0, 1);
|
const Vector2 Vector2::v = Vector2(0, 1);
|
||||||
|
@ -10,9 +10,10 @@ namespace starlight {
|
|||||||
float x = 0.0f;
|
float x = 0.0f;
|
||||||
float y = 0.0f;
|
float y = 0.0f;
|
||||||
|
|
||||||
Vector2();
|
constexpr Vector2() = default;
|
||||||
Vector2(float x, float y);
|
constexpr Vector2(float x, float y) : x(x), y(y) { }
|
||||||
~Vector2();
|
constexpr Vector2(float mag) : x(mag), y(mag) { }
|
||||||
|
~Vector2() = default;
|
||||||
|
|
||||||
float Length() const;
|
float Length() const;
|
||||||
Vector2 Normalized() const;
|
Vector2 Normalized() const;
|
||||||
@ -47,6 +48,9 @@ namespace starlight {
|
|||||||
inline Vector2 & operator -= (const Vector2 & o) { x -= o.x; y -= o.y; return *this; }
|
inline Vector2 & operator -= (const Vector2 & o) { x -= o.x; y -= o.y; return *this; }
|
||||||
inline Vector2 & operator *= (const Vector2 & o) { x *= o.x; y *= o.y; return *this; }
|
inline Vector2 & operator *= (const Vector2 & o) { x *= o.x; y *= o.y; return *this; }
|
||||||
|
|
||||||
|
inline explicit operator bool() const { return x == x && y == y; }
|
||||||
|
|
||||||
|
static const Vector2 invalid;
|
||||||
static const Vector2 zero;
|
static const Vector2 zero;
|
||||||
static const Vector2 one;
|
static const Vector2 one;
|
||||||
static const Vector2 half;
|
static const Vector2 half;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user