In closing Episode 2 – Spicing up our class, we heard Dr. Bob calling bullshit on the x coordinate testing we came up with. We should be able to test the y & z coordinates of the cabinet parts, too. But this would sure look like Dr. Bob doing the same sketch twice. It would be way better (and more efficient) to calculate the 2D rectangles forming the basis of the different cabinet parts (assuming we could get away with simple extrudes for the cabinet’s parts). Let’s do that and rewrite the tests and code accordingly.

TEST_N(SimpleCabinetGetLeftSideBase) { SimpleCabinet simpleCabinet(600, 720, 800); CHECK_EQUAL(WorldRect(0, 800, SimpleCabinet::kBoardThickness, 0), simpleCabinet.GetLeftSideBase()); }

Making the test pass is supposed to pretty simple, we calculate the WordRect required using the depth of `SimpleCabinet`. But much to our dismay, there’s no such instance variable `fDepth`. Let’s add it (test first, of course):

TEST_N(SimpleCabinetWidthAndHeight) { SimpleCabinet simpleCabinet(600, 720, 800); CHECK_EQUAL(600, simpleCabinet.GetWidth()); CHECK_EQUAL(720, simpleCabinet.GetHeight()); CHECK_EQUAL(800, simpleCabinet.GetDepth()); }

Of course, making the test pass is trivial. We add the accessor and instance variable to `SimpleCabinet`:

WorldCoord GetDepth() const { return fDepth; } WorldCoord fDepth;

Now back to our initial task, coding `GetLeftSideBase()`:

WorldRect GetLeftSideBase() const { return WorldRect(0, fDepth, kBoardThickness, 0); }

With `GetLeftSideBase()` under our belt, let’s tackle the cabinet’s right side:

TEST_N(SimpleCabinetGetRightSideBase) { SimpleCabinet simpleCabinet(600, 720, 800); CHECK_EQUAL(WorldRect(600 - SimpleCabinet::kBoardThickness, 800, 600, 0), simpleCabinet.GetRightSideBase()); }

As the basic shape of the right side will be identical to the left side’s shape, we choose to implement it by re-using `LeftLeftSideBase()`:

WorldRect GetRightSideBase() const { WorldRect r = GetLeftSideBase(); r.Offset(WorldPt(fWidth - kBoardThickness, 0)); return r; }

With the base shape of the cabinet’s left & right side plus the cabinet’s height, we are pretty optimistic about being able to create the proper Vectorworks geometry. Let’s see if we can compute the top & bottom board’s basic shape too. The basic shape for both parts is:

TEST_N(SimpleCabinetGetTopBottomBase) { SimpleCabinet simpleCabinet(600, 720, 800); CHECK_EQUAL(WorldRect(SimpleCabinet::kBoardThickness, 800, 600 - SimpleCabinet::kBoardThickness, 0), simpleCabinet.GetTopBottomBase()); }

Again, pretty simple to make this test pass:

WorldRect GetTopBottomBase() const { return WorldRect(kBoardThickness, fDepth, fWidth - kBoardThickness, 0); }

For the top board, we will sure need the z position, too. Let’s do this before we’re wrapping it up for today:

TEST_N(SimpleCabinetGetTopZPosition) { SimpleCabinet simpleCabinet(600, 720, 800); CHECK_EQUAL(720 - SimpleCabinet::kBoardThickness, simpleCabinet.GetTopZPosition()); }

Coding up `SimpleCabinet::GetTopZPosition()` is a breeze now that we’re on a roll đ

WorldCoord GetTopZPosition() const { return fHeight - kBoardThickness; }

That’s it for today. We have been able to come up with a representation of the different cabinet part’s basic shape, which, if mixed with the models information about the cabinet’s height, should enable us to – finally – create some geometry in Vectorworks.

Tune in next week when you hear Dr. Bob say “It’s time to create some Vectorworks objects or the patient will die of boredom…”.

P.S.: Just in case you’re wondering about Dr. Bob – Check out The Veterinarian’s Hospital on Wikia or on Youtube. This should give me a minute or two to prepare Episode 4.