// ==========================================================================
// $Id: point2d.cpp,v 1.4 2017/09/23 00:53:23 jlang Exp $
// CSI2372 example Code for lecture 4
// ==========================================================================
// (C)opyright:
//
//   Jochen Lang
//   SITE, University of Ottawa
//   800 King Edward Ave.
//   Ottawa, On., K1N 6N5
//   Canada. 
//   http://www.site.uottawa.ca
// 
// Creator: jlang (Jochen Lang)
// Email:   jlang@site.uottawa.ca
// ==========================================================================
// $Log: point2d.cpp,v $
// Revision 1.4  2017/09/23 00:53:23  jlang
// Introduced references and const again for this version
//
// Revision 1.3  2017/09/13 16:21:06  jlang
// Removed arrays, references and use of const.
//
// 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
//
// Revision 1.1  2010/09/29 14:28:59  jlang
// Separate files for line_segment and point2d. Added test_point and make label test
//
// Revision 1.5  2008/10/15 21:31:32  jlang
// Reverting to 1.3
//
// Revision 1.3  2008/09/15 18:29:08  jlang
// Clarified comments
//
// Revision 1.2  2006/09/23 00:14:50  jlang
// Removed some pass by reference
//
// Revision 1.1  2006/09/23 00:00:55  jlang
// Added files for lecture 4
//
//
// ==========================================================================
#include <iostream>
#include "point2d.h"


/**
 * Point2D - All in-one constructor
 */
Point2D::Point2D( double _x, double _y ) : d_x(_x), d_y(_y) 
{}

/**
 * Dot product between two "points"
 */
double Point2D::dot( const Point2D& _oPoint ) const {
  double res = _oPoint.d_x * d_x + _oPoint.d_y * d_y;
  return res;
}

/**
 * Add a "point" to this point and return result 
 */
Point2D Point2D::add( const Point2D& _oPoint ) const {
  Point2D res;
  res.d_x = d_x + _oPoint.d_x;
  res.d_y = d_y + _oPoint.d_y;
  return res;
}

/**
 * Subtract a "point" from this point and return result
 */
Point2D Point2D::subtract( const Point2D& _oPoint ) const {
  Point2D res;
  res.d_x = d_x - _oPoint.d_x;
  res.d_y = d_y - _oPoint.d_y;
  return res;
}

/**
 * Subtract a "point" from this point as in -= and return this 
 */
Point2D& Point2D::minusEquals( const Point2D& _oPoint ) {
  d_x -= _oPoint.d_x;
  d_y -= _oPoint.d_y;
  return (*this);
}

/**
 * Convenience printing method
 */
void Point2D::print() const {
  std::cout << "( " << d_x << ", " << d_y << " )";
  return;
}


/**
 * Compare a "point" coordinate-wise to this point and return minimum
 * coordinates
 */
Point2D Point2D::min( const Point2D& _oPoint ) const {
  Point2D res;
  res.d_x = (d_x < _oPoint.d_x)?d_x:_oPoint.d_x;
  res.d_y = (d_y < _oPoint.d_y)?d_y:_oPoint.d_y;
  return res;
}

/**
 * Compare a "point" coordinate-wise to this point and return maximum
 * coordinates
 */
Point2D Point2D::max( const Point2D& _oPoint ) const {
  Point2D res;
  res.d_x = (d_x > _oPoint.d_x)?d_x:_oPoint.d_x;
  res.d_y = (d_y > _oPoint.d_y)?d_y:_oPoint.d_y;
  return res;
}

/**
 * Return true if current point has smaller coordinates than other
 * point
 */
bool Point2D::isSmaller( const Point2D& _oPoint ) const {
  if ( d_x < _oPoint.d_x && d_y < _oPoint.d_y ) {
    return true;
  } else {
    return false;
  }
}


/**
 * Return two results for component-wise comparison
 */
void Point2D::isSmaller( const Point2D& _oPoint, bool& xCompare, 
			 bool& yCompare ) const {
  if ( d_x < _oPoint.d_x ) {
    xCompare = true;
  } else {
    xCompare = false;
  }
  if ( d_y < _oPoint.d_y ) {
    yCompare = true;
  } else {
    yCompare = false;
  }
}
