// ==========================================================================
// $Id: aa_box.cpp,v 1.3 2017/09/13 16:09:27 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.3  2017/09/13 16:09:27  jlang
// Wrapped point array in std::array. Removed use of pointers.
//
// Revision 1.2  2014/09/16 22:06:25  jlang
// Added some brace initialization.
//
// Revision 1.1  2011/09/27 17:22:21  jlang
// Added bounding shape example
//
//
// ==========================================================================
#include <algorithm>

#include "aa_box.h"
  
AABox::AABox( Point2D _lowerLeft, Point2D _upperRight ) {
  d_lowerLeft = _lowerLeft;
  d_upperRight = _upperRight;
}
  
bool AABox::enclose( std::array<Point2D,4> extrema ) {
  Point2D lowerLeft(1e99,1e99);
  Point2D upperRight(-1e99,-1e99);
  for (int i=0; i<extrema.size(); ++i) {
    lowerLeft.d_x = std::min( extrema[i].d_x, lowerLeft.d_x );
    lowerLeft.d_y = std::min( extrema[i].d_y, lowerLeft.d_y );    
    upperRight.d_x = std::max( extrema[i].d_x, upperRight.d_x );
    upperRight.d_y = std::max( extrema[i].d_y, upperRight.d_y );
  }
  if ( lowerLeft.d_x < upperRight.d_x && lowerLeft.d_y < upperRight.d_y ) {
    d_lowerLeft = lowerLeft;
    d_upperRight = upperRight;
    return true;
  } 
  return false;
}
    
