// ========================================================================== // $Id: aa_box.cpp,v 1.1 2011/10/19 03:24:40 jlang Exp $ // CSI2372 example Code for lecture 4 // ========================================================================== // (C)opyright: // // Jochen Lang // EECS, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.eecs.uottawa.ca // // Creator: jlang (Jochen Lang) // Email: jlang@eecs.uottawa.ca // ========================================================================== // $Log: aa_box.cpp,v $ // Revision 1.1 2011/10/19 03:24:40 jlang // Added code for lecture 7 // // Revision 1.2 2011/10/03 15:29:33 jlang // Updates for lecture 3-5 // // Revision 1.1 2011/09/27 17:22:20 jlang // Added bounding shape example // // // ========================================================================== #include #include "aa_box.h" using std::cout; using std::endl; AABox::AABox( Point2D _lowerLeft, Point2D _upperRight ) : d_lowerLeft(_lowerLeft), d_upperRight(_upperRight) {} bool AABox::enclose( Point2D _extrema[], int _size ) { Point2D lowerLeft(1e99,1e99); Point2D upperRight(-1e99,-1e99); for (int i=0; i<_size; ++i) { lowerLeft = _extrema[i].min( lowerLeft ); upperRight = _extrema[i].max( upperRight ); } if ( lowerLeft.isSmaller( upperRight )) { d_lowerLeft = lowerLeft; d_upperRight = upperRight; return true; } return false; } bool AABox::isInside( const Point2D& _pt ) const { if ( _pt.isSmaller( d_upperRight ) && _pt.isGreater( d_lowerLeft )) return true; else return false; } void AABox::print() const { cout << "Box from: "; d_lowerLeft.print(); cout << " to "; d_upperRight.print(); return; } Point2D AABox::getLowerLeft() const { return d_lowerLeft; } Point2D AABox::getUpperRight() const { return d_upperRight; }