Changeset 2469


Ignore:
Timestamp:
Feb 22, 2013, 4:44:42 PM (6 years ago)
Author:
sam
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/geometry.h

    r2463 r2469  
    6161static inline bool BoxIsectBox(Box2D const &b1, Box2D const &b2)
    6262{
    63     vec2 c1 = 0.5f * (b1.A + b1.B);
    64     vec2 c2 = 0.5f * (b2.A + b2.B);
     63    vec2 dist = 0.5f * (b1.A - b2.A + b1.B - b2.B);
    6564    vec2 e1 = 0.5f * (b1.B - b1.A);
    6665    vec2 e2 = 0.5f * (b2.B - b2.A);
    6766
    68     return abs(c1.x - c2.x) < abs(e1.x) + abs(e2.x)
    69         || abs(c1.y - c2.y) < abs(e1.y) + abs(e2.y);
     67    return abs(dist.x) < abs(e1.x) + abs(e2.x)
     68        && abs(dist.y) < abs(e1.y) + abs(e2.y);
    7069}
    7170
  • trunk/test/unit/box.cpp

    r2468 r2469  
    3333        LOLUNIT_ASSERT_EQUAL(true, BoxIsectBox(b1, b2));
    3434        LOLUNIT_ASSERT_EQUAL(false, BoxIsectBox(b1, b3));
     35
     36        Box2D b4(vec2(96.f, 33.f), vec2(144.f, 129.f));
     37        Box2D b5(vec2(264.f, 91.f), vec2(244.f, 71.f));
     38
     39        LOLUNIT_ASSERT_EQUAL(false, BoxIsectBox(b4, b5));
    3540    }
    3641};
Note: See TracChangeset for help on using the changeset viewer.