Explorar el Código

math: fix an idiotic bug in the box-box intersection routine.

legacy
Sam Hocevar sam hace 11 años
padre
commit
fdc877cc29
Se han modificado 2 ficheros con 8 adiciones y 4 borrados
  1. +3
    -4
      src/lol/math/geometry.h
  2. +5
    -0
      test/unit/box.cpp

+ 3
- 4
src/lol/math/geometry.h Ver fichero

@@ -60,13 +60,12 @@ struct Box3D

static inline bool BoxIsectBox(Box2D const &b1, Box2D const &b2)
{
vec2 c1 = 0.5f * (b1.A + b1.B);
vec2 c2 = 0.5f * (b2.A + b2.B);
vec2 dist = 0.5f * (b1.A - b2.A + b1.B - b2.B);
vec2 e1 = 0.5f * (b1.B - b1.A);
vec2 e2 = 0.5f * (b2.B - b2.A);

return abs(c1.x - c2.x) < abs(e1.x) + abs(e2.x)
|| abs(c1.y - c2.y) < abs(e1.y) + abs(e2.y);
return abs(dist.x) < abs(e1.x) + abs(e2.x)
&& abs(dist.y) < abs(e1.y) + abs(e2.y);
}

bool TriangleIsectTriangle(vec3 const &v00, vec3 const &v01, vec3 const &v02,


+ 5
- 0
test/unit/box.cpp Ver fichero

@@ -32,6 +32,11 @@ LOLUNIT_FIXTURE(BoxTest)

LOLUNIT_ASSERT_EQUAL(true, BoxIsectBox(b1, b2));
LOLUNIT_ASSERT_EQUAL(false, BoxIsectBox(b1, b3));

Box2D b4(vec2(96.f, 33.f), vec2(144.f, 129.f));
Box2D b5(vec2(264.f, 91.f), vec2(244.f, 71.f));

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



Cargando…
Cancelar
Guardar