// ========================================================================== // $Id: aa_box.cpp,v 1.6 2017/09/23 00:53:23 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.6 2017/09/23 00:53:23 jlang // Introduced references and const again for this version // // Revision 1.5 2017/09/13 16:21:05 jlang // Removed arrays, references and use of const. // // Revision 1.4 2014/09/16 22:05:53 jlang // Added some brace initialization. // // Revision 1.3 2013/09/30 19:44:44 jlang // Added default parameter for the number of points. // // 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 #include "aa_box.h" AABox::AABox( const Point2D& _lowerLeft, const Point2D& _upperRight ) : d_lowerLeft(_lowerLeft), d_upperRight(_upperRight) {} bool AABox::enclose( std::array extrema ) { Point2D lowerLeft{std::numeric_limits::max(), std::numeric_limits::max()}; Point2D upperRight{std::numeric_limits::min(), std::numeric_limits::min()}; for ( auto pt:extrema ) { lowerLeft = pt.min( lowerLeft ); upperRight = pt.max( upperRight ); } if ( lowerLeft.isSmaller( upperRight )) { d_lowerLeft = lowerLeft; d_upperRight = upperRight; return true; } return false; } void AABox::print() const { std::cout << "Box from: "; d_lowerLeft.print(); std::cout << " to "; d_upperRight.print(); return; }