www.pudn.com > Gimcrack-v0.0051-Source.zip > point.h


#ifndef _POINT_H_ 
#define _POINT_H_ 
 
typedef float pointType; 
 
class GcPoint2 
{ 
public: 
 
	/* Everyting is declared in the header (for inlining) since */ 
	/*          speed is vital to point calculation				*/ 
 
	// Default constructor 
	GcPoint2(): x(0), y(0){} 
 
	// Overloaded constructor allowing initialazion 
	GcPoint2(pointType sX, pointType sY): x(sX), y(sY) {} 
 
	// Destructor 
	~GcPoint2() {} 
 
	/* Overload the standard math operators to work with the pointor */ 
 
	// Negation 
	GcPoint2 operator-() 
	{ 
		return GcPoint2(-x, -y); 
	} 
 
	// Addition (point1 + point2) 
	GcPoint2 operator+(const GcPoint2 point) 
	{ 
		return GcPoint2(x + point.x, y + point.y); 
	} 
 
	// Addition (point1 += point2) 
	void operator+=(const GcPoint2 point) 
	{ 
		x += point.x;  
		y += point.y;  
	} 
 
	// Substraction (point1 - point2) 
	GcPoint2 operator-(const GcPoint2 point) 
	{ 
		return GcPoint2(x - point.x, y - point.y); 
	} 
 
	// Substraction (point1 -= point2) 
	void operator-=(const GcPoint2 point) 
	{ 
		x -= point.x; 
		y -= point.y;  
	} 
 
	// Scalar multiplication (point * scal) 
	GcPoint2 operator*(pointType scalar) 
	{ 
		return GcPoint2(x * scalar, y * scalar); 
	} 
 
	// Scalar multiplication (point *= scal) 
	void operator*=(pointType scalar) 
	{ 
		x *= scalar; 
		y *= scalar;  
	} 
 
	// Scalar division (point / scal) 
	GcPoint2 operator/(pointType scalar) 
	{ 
		return GcPoint2(x / scalar, y / scalar); 
	} 
 
	// Scalar division (point /= scal) 
	void operator/=(pointType scalar) 
	{ 
		x /= scalar; 
		y /= scalar; 
	} 
 
 
	/* Overload the standard comperation operator */ 
 
	// Equal too 
	bool operator==(const GcPoint2 point) 
	{ 
		return ((x == point.x) && (y == point.y)); 
		 
	} 
 
	/* The variables are public for easier access */ 
	union  
	{ 
		struct  
		{ 
			pointType x, y; 
        }; 
 
		pointType array[2]; 
	}; 
}; 
 
class GcPoint3 
{ 
public: 
 
	/* Everyting is declared in the header (for inlining) since */ 
	/*          speed is vital to pointor calculation			*/ 
 
	// Default constructor 
	GcPoint3(): x(0), y(0), z(0) {} 
 
	// Overloaded constructor allowing initialazion 
	GcPoint3(pointType sX, pointType sY, pointType sZ): x(sX), y(sY), z(sZ) {} 
 
	// Destructor 
	~GcPoint3() {} 
 
	/* Overload the standard math operators to work with the pointor */ 
 
	// Negation 
	GcPoint3 operator-() 
	{ 
		return GcPoint3(-x, -y, -z); 
	} 
 
	// Addition (point1 + point2) 
	GcPoint3 operator+(const GcPoint3 point) 
	{ 
		return GcPoint3(x + point.x, y + point.y, z +  point.z); 
	} 
 
	// Addition (point1 += point2) 
	void operator+=(const GcPoint3 point) 
	{ 
		x += point.x;  
		y += point.y;  
		z +=  point.z; 
	} 
 
	// Substraction (point1 - point2) 
	GcPoint3 operator-(const GcPoint3 point) 
	{ 
		return GcPoint3(x - point.x, y - point.y, z - point.z); 
	} 
 
	// Substraction (point1 -= point2) 
	void operator-=(const GcPoint3 point) 
	{ 
		x -= point.x; 
		y -= point.y;  
		z -= point.z; 
	} 
 
	// Scalar multiplication (point * scal) 
	GcPoint3 operator*(pointType scalar) 
	{ 
		return GcPoint3(x * scalar, y * scalar, z * scalar); 
	} 
 
	// Scalar multiplication (point *= scal) 
	void operator*=(pointType scalar) 
	{ 
		x *= scalar; 
		y *= scalar;  
		z *= scalar; 
	} 
 
	// Scalar division (point / scal) 
	GcPoint3 operator/(pointType scalar) 
	{ 
		return GcPoint3(x / scalar, y / scalar, z / scalar); 
	} 
 
	// Scalar division (point /= scal) 
	void operator/=(pointType scalar) 
	{ 
		x /= scalar; 
		y /= scalar; 
		z /= scalar; 
	} 
 
 
	/* Overload the standard comperation operator */ 
 
	// Equal too 
	bool operator==(const GcPoint3 point) 
	{ 
		return ((x == point.x) && (y == point.y) && (z == point.z)); 
		 
	} 
 
	/* The variables are public for easier access */ 
	union  
	{ 
		struct  
		{ 
			pointType x, y, z; 
        }; 
 
		pointType array[3]; 
	}; 
}; 
 
#endif