]> git.localhorst.tv Git - orbi.git/blobdiff - src/world/AABB.h
addressed some float issues
[orbi.git] / src / world / AABB.h
index a0e3436194fd57dbee28b06682babc553ef6edd2..5b482c4cc701ae9fe6fa9eb8d568bb5b56508f87 100644 (file)
@@ -13,9 +13,9 @@ class AABB {
 public:
        constexpr AABB() { }
        constexpr AABB(Vector<float> pos, Vector<float> size)
-       : lt(pos), rb(pos + size) { }
+       : size(size), lt(pos), rb(pos + size) { }
        constexpr AABB(float x, float y, float w, float h)
-       : lt(x, y), rb(x + w, y + h) { }
+       : size(w, h), lt(x, y), rb(x + w, y + h) { }
 
 public:
        float Left() const { return lt.x; }
@@ -26,16 +26,17 @@ public:
        Vector<float> Position() const { return lt; }
        Vector<float> Center() const { return lt + HalfSize(); }
        Vector<float> HalfSize() const { return Size() / 2.0f; }
-       Vector<float> Size() const { return rb - lt; }
+       Vector<float> Size() const { return size; }
 
 public:
-       void Move(Vector<float> delta) { lt += delta; rb += delta; }
+       void Move(Vector<float> delta) { lt += delta; rb = lt + size; }
        void Resize(Vector<float> size) { *this = AABB(lt, size); }
 
        bool Intersects(const AABB &other) const;
        bool Intersects(const AABB &other, Collision &) const;
 
 private:
+       Vector<float> size;
        Vector<float> lt;
        Vector<float> rb;