int VectorGraphic::getWidth() const { // I'm cheating a bit here by using a function object and the for_each // algorithm, which we haven't discussed. // I defined ComputeWidth() in ComputeDimensions.h return std::for_each(myPath.begin(), myPath.end(), ComputeWidth()); // If I were to do the same thing inside this function, it // would something like this... // // int currentMin = INT_MAX; // int currentMax = INT_MIN; // for (Points::const_iterator i = myPath.begin(); i != myPath.end(); ++i) // { // if (i->getX() > currentMax) // { // currentMax = i->getX(); // } // // if (i->getX() < currentMin) // { // currentMin = i->getX(); // } // } // return currentMax - currentMin; }
/***************************************************************** * MoveCenter(): Centers the rectangle on 'x' and 'y' * * Ins: x - the x coordinate to place the rectangle * y - the y coordinate to place the rectangle * * Outs: * * Returns: * * Mod. Date: 05/15/2015 * Mod. Initials: *****************************************************************/ void CRectangle::MoveCenter(float x, float y) { float width = ComputeWidth( ); float height = ComputeHeight( ); m_fLeft = x - width / 2.f; m_fRight = x + width / 2.f; m_fTop = y - height / 2.f; m_fBottom = y + height / 2.f; }