Przeglądaj źródła

math: add Box2d + vec2 operations for easy box translations.

legacy
Sam Hocevar sam 11 lat temu
rodzic
commit
8143b73ffb
2 zmienionych plików z 63 dodań i 0 usunięć
  1. +48
    -0
      src/lol/math/geometry.h
  2. +15
    -0
      test/unit/box.cpp

+ 48
- 0
src/lol/math/geometry.h Wyświetl plik

@@ -40,6 +40,30 @@ struct Box2D
B(b)
{}

Box2D operator +(vec2 v)
{
return Box2D(A + v, B + v);
}

Box2D &operator +=(vec2 v)
{
A += v;
B += v;
return *this;
}

Box2D operator -(vec2 v)
{
return Box2D(A - v, B - v);
}

Box2D &operator -=(vec2 v)
{
A -= v;
B -= v;
return *this;
}

vec2 A, B;
};

@@ -55,6 +79,30 @@ struct Box3D
B(b)
{}

Box3D operator +(vec3 v)
{
return Box3D(A + v, B + v);
}

Box3D &operator +=(vec3 v)
{
A += v;
B += v;
return *this;
}

Box3D operator -(vec3 v)
{
return Box3D(A - v, B - v);
}

Box3D &operator -=(vec3 v)
{
A -= v;
B -= v;
return *this;
}

vec3 A, B;
};



+ 15
- 0
test/unit/box.cpp Wyświetl plik

@@ -38,6 +38,21 @@ LOLUNIT_FIXTURE(BoxTest)

LOLUNIT_ASSERT_EQUAL(false, BoxIsectBox(b4, b5));
}

LOLUNIT_TEST(Box2DMove)
{
Box2D b1(vec2(0.f, 0.f), vec2(1.f, 1.f));
Box2D b2(vec2(2.f, 2.f), vec2(3.f, 3.f));

b1 += vec2(0.6f, 0.6f);
LOLUNIT_ASSERT_EQUAL(false, BoxIsectBox(b1, b2));

b1 += vec2(0.6f, 0.6f);
LOLUNIT_ASSERT_EQUAL(true, BoxIsectBox(b1, b2));

b1 -= vec2(0.0f, 0.6f);
LOLUNIT_ASSERT_EQUAL(false, BoxIsectBox(b1, b2));
}
};

} /* namespace lol */


Ładowanie…
Anuluj
Zapisz