Skip to content
Permalink
Browse files

ULTIMA8: Correct Box.InBox boundary conditions

The boundary conditions were reversed in Box.Inbox when compared with
Box.Overlaps.  Since InBox is not being used and Overlaps is, I went with the
definitions from Overlaps. Also configured unit tests to exercise this
behavior.
  • Loading branch information
mduggan committed Mar 25, 2020
1 parent 4e7f9ee commit 8c3ebe9af4e04618918ca353d008d38b66ca18f5
Showing with 9 additions and 13 deletions.
  1. +2 −2 engines/ultima/ultima8/misc/box.h
  2. +7 −11 test/engines/ultima/ultima8/misc/box.h
@@ -56,8 +56,8 @@ struct Box {

// Check to see if a point is within the Box
bool InBox(int px, int py, int pz) const {
return (px >= (_x - _xd) && py >= (_y - _yd) && pz >= _z &&
px < _x && py < _y && pz < (_z + _zd));
return (px > (_x - _xd) && py > (_y - _yd) && pz >= _z &&
px <= _x && py <= _y && pz < (_z + _zd));
}

// Move the Box (Relative)
@@ -24,16 +24,13 @@ class U8BoxTestSuite : public CxxTest::TestSuite {
TS_ASSERT(box.IsValid());
TS_ASSERT(box.Overlaps(box));
TS_ASSERT(box == box);
// TODO: All these tests are disabled becasue the box uses reversed
// coordinates in x and y.. need to confirm if that's the correct
// behavior
/*
TS_ASSERT(box.InBox(0,0,1));
TS_ASSERT(box.InBox(0,1,0));
TS_ASSERT(box.InBox(1,0,0));

// Note: These tests expect Box has reversed coordinates in x and y.
TS_ASSERT(box.InBox(-1,-1,1));
TS_ASSERT(box.InBox(-1,-1,0));
box.MoveRel(0, 0, 1);
TS_ASSERT(!box.InBox(0,0,1));
TS_ASSERT(box.InBox(0,0,2));
TS_ASSERT(!box.InBox(-1,-1,0));
TS_ASSERT(box.InBox(-1,-1,2));

Ultima::Ultima8::Box box2(box);
TS_ASSERT(box == box2);
@@ -45,9 +42,8 @@ class U8BoxTestSuite : public CxxTest::TestSuite {
TS_ASSERT(!(box2 == box3));
TS_ASSERT(box2.Overlaps(box3));
TS_ASSERT(box3.Overlaps(box2));
box3.ResizeAbs(1,2,2);
box3.ResizeAbs(1,1,1);
TS_ASSERT(!box3.Overlaps(box2));
*/
}

};

0 comments on commit 8c3ebe9

Please sign in to comment.
You can’t perform that action at this time.