/****************************************************************************************


		MCPoint.h


		Copyright: (c) 2001 Eovia Corp. All rights reserved.


		Author:	Ian (from RDSource)
		Date:	12/10/97

		Revision History

		when		who			what & why
		==========	==========	======================================================
		05/17/99	del			Added some operators...
		04/20/99	Nba			Added Norm1
		4/2/98		Ian			Moved operators into MCStreamOperators.
								Added kDoneSel to XYSelect, made operator[] return an
								int32& to act like a real [] operator, and added a const
								version.
		3/16/98		link		Added Set().

*****************************************************************************************/

#ifndef __MCPoint__
#define __MCPoint__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCBasicTypes.h"

class TMCiostream;

/// \addtogroup MCCore
/// \{

/// TMCPoint represents a 2D integer point. It is generally used to represent pixel coordinates.
///
class TMCPoint : public TMCObject0
{

public:

	enum XYSelect
	{
		kXSel=0, 
		kYSel=1,
		kDoneSel = 2
	}; 

	int32	x;
	int32	y;
	
	//Should we init to zero?
	/// Constructor that does NOT initialize the memory...
	///
	TMCPoint (void)							{}
	TMCPoint (const TMCPoint& fromPoint)	{x = fromPoint.x; y = fromPoint.y;}
	TMCPoint (int32 xVal, int32 yVal)		{x = xVal;y = yVal;}

	const int32&	operator[]	(XYSelect sel) const				{return (sel == kXSel ? x : y);}
	      int32&	operator[]  (XYSelect sel)						{return (sel == kXSel ? x : y);}
		  void		operator+=  (const TMCPoint& rhs)				{x += rhs.x;y += rhs.y;}
		  void		operator-=  (const TMCPoint& rhs)				{x -= rhs.x;y -= rhs.y;}
		  void		operator*=	(const int32 mul)					{x*=mul; y*=mul; }
		  void		operator/=	(const int32 div)					{x/=div; y/=div; }
		  void		operator<<= (const uint8 i)						{x<<=i; y<<=i; }
		  void		operator>>= (const uint8 i)						{x>>=i; y>>=i; }
		  TMCPoint	operator-	() const							{return TMCPoint(-x, -y);}
		  TMCPoint	operator+	(const TMCPoint& rhs) const			{return TMCPoint(x + rhs.x, y + rhs.y);}
		  TMCPoint	operator-	(const TMCPoint& rhs) const			{return TMCPoint(x - rhs.x, y - rhs.y);}
		  TMCPoint	operator*	(const int32 mul) const				{return TMCPoint(x*mul,y*mul); }
		  TMCPoint	operator/	(const int32 div) const				{return TMCPoint(x/div,y/div); }
		  TMCPoint	operator<<	(const uint8 i) const				{return TMCPoint(x<<i,y<<i); }
		  TMCPoint	operator>>	(const uint8 i) const				{return TMCPoint(x>>i,y>>i); }
		  boolean	operator == (const TMCPoint& rhs) const			{return (x == rhs.x) && (y == rhs.y);}
		  boolean	operator != (const TMCPoint& rhs) const			{return !((x == rhs.x) && (y == rhs.y));}
		  void		operator=	(const TMCPoint& rhs)				{x = rhs.x;y = rhs.y;}

		  void		Set			(const int32 inX, const int32 inY)	{x = inX; y = inY; }


		  int32		X()	{return x;}
		  int32		Y()	{return y;}

		  static TMCPoint gZeroPoint;

		  int32 Norm1() const { return ((x <0)?-x:x) + ((y < 0)?-y:y); }
		
		  ///Dot product
		  inline real	operator*  (const TMCPoint& b) const	{ return x * b.x + y * b.y; }

		  ///Cross product
		  inline real	operator^  (const TMCPoint& b) const	{ return x * b.y - y * b.x; }
};

/// \}


#endif