Browse Source

Refactored and renamed Box, Int2, Rect and FRect #2 (SVN being silly)

Marko Pintera 12 years ago
parent
commit
3fed3402b3

+ 44 - 0
CamelotCore/Include/CmPixelVolume.h

@@ -0,0 +1,44 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+
+namespace CamelotFramework
+{
+	/**
+	 * @brief	Volume of pixels used for referencing a part of
+	 * 			a texture.
+	 */
+	struct CM_EXPORT PixelVolume
+	{
+		UINT32 left, top, right, bottom, front, back;
+
+		PixelVolume()
+			: left(0), top(0), right(1), bottom(1), front(0), back(1)
+		{ }
+
+		PixelVolume(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom):
+			left(left), top(top), right(right), bottom(bottom), front(0), back(1)
+		{
+			assert(right >= left && bottom >= top && back >= front);
+		}
+
+		PixelVolume(UINT32 left, UINT32 top, UINT32 front, UINT32 right, UINT32 bottom, UINT32 back):
+			left(left), top(top), right(right), bottom(bottom), front(front), back(back)
+		{
+			assert(right >= left && bottom >= top && back >= front);
+		}
+            
+		/**
+		 * @brief	Return true if the other box is a part of this one.
+		 */
+		bool contains(const PixelVolume &volume) const
+		{
+			return (volume.left >= left && volume.top >= top && volume.front >= front &&
+				volume.right <= right && volume.bottom <= bottom && volume.back <= back);
+		}
+            
+		UINT32 getWidth() const { return right-left; }
+		UINT32 getHeight() const { return bottom-top; }
+		UINT32 getDepth() const { return back-front; }
+	};
+}

+ 1 - 0
CamelotCore/Source/CmPixelVolume.cpp

@@ -0,0 +1 @@
+#include "CmPixelVolume.h"

+ 0 - 227
CamelotUtility/Include/CmInt2.h

@@ -1,227 +0,0 @@
-#pragma once
-
-#include "CmPrerequisitesUtil.h"
-
-namespace CamelotFramework
-{
-	struct CM_UTILITY_EXPORT Int2
-	{
-		int x;
-		int y;
-
-		inline Int2()
-			: x(0), y(0)
-		{
-		}
-
-		inline Int2(const int _x, const int _y )
-            : x( _x ), y( _y )
-        {
-        }
-
-        inline explicit Int2( const int scaler )
-            : x( scaler), y( scaler )
-        {
-        }
-
-        inline explicit Int2( const int afCoordinate[2] )
-        {
-            x = afCoordinate[0];
-            y = afCoordinate[1];
-        }
-
-        inline explicit Int2( int* const r )
-            : x( r[0] ), y( r[1] )
-        {
-        }
-
-		/** Exchange the contents of this vector with another. 
-		*/
-		inline void swap(Int2& other)
-		{
-			std::swap(x, other.x);
-			std::swap(y, other.y);
-		}
-
-		inline unsigned int manhattanDist(const Int2& other)
-		{
-			return (unsigned int)fabs(float(other.x - x)) + (unsigned int)fabs(float(other.y - y));
-		}
-
-		inline int operator [] ( const size_t i ) const
-        {
-            assert( i < 2 );
-
-            return *(&x+i);
-        }
-
-		inline int& operator [] ( const size_t i )
-        {
-            assert( i < 2 );
-
-            return *(&x+i);
-        }
-
-		/// Pointer accessor for direct copying
-		inline int* ptr()
-		{
-			return &x;
-		}
-		/// Pointer accessor for direct copying
-		inline const int* ptr() const
-		{
-			return &x;
-		}
-
-        /** Assigns the value of the other vector.
-            @param
-                rhs The other vector
-        */
-        inline Int2& operator = ( const Int2& rhs )
-        {
-            x = rhs.x;
-            y = rhs.y;
-
-            return *this;
-        }
-
-		inline Int2& operator = ( const int fScalar)
-		{
-			x = fScalar;
-			y = fScalar;
-
-			return *this;
-		}
-
-        inline bool operator == ( const Int2& rhs ) const
-        {
-            return ( x == rhs.x && y == rhs.y );
-        }
-
-        inline bool operator != ( const Int2& rhs ) const
-        {
-            return ( x != rhs.x || y != rhs.y  );
-        }
-
-        // arithmetic operations
-        inline Int2 operator + ( const Int2& rhs ) const
-        {
-            return Int2(
-                x + rhs.x,
-                y + rhs.y);
-        }
-
-        inline Int2 operator - ( const Int2& rhs ) const
-        {
-            return Int2(
-                x - rhs.x,
-                y - rhs.y);
-        }
-
-        inline Int2 operator * ( const int fScalar ) const
-        {
-            return Int2(
-                x * fScalar,
-                y * fScalar);
-        }
-
-        inline Int2 operator * ( const Int2& rhs) const
-        {
-            return Int2(
-                x * rhs.x,
-                y * rhs.y);
-        }
-
-        inline Int2 operator / ( const int fScalar ) const
-        {
-            assert( fScalar != 0 );
-
-            return Int2(
-                x / fScalar,
-                y / fScalar);
-        }
-
-        inline Int2 operator / ( const Int2& rhs) const
-        {
-            return Int2(
-                x / rhs.x,
-                y / rhs.y);
-        }
-
-        inline const Int2& operator + () const
-        {
-            return *this;
-        }
-
-        inline Int2 operator - () const
-        {
-            return Int2(-x, -y);
-        }
-
-        // overloaded operators to help Vector2
-        inline friend Int2 operator * ( const int fScalar, const Int2& rhs )
-        {
-            return Int2(
-                fScalar * rhs.x,
-                fScalar * rhs.y);
-        }
-
-        inline friend Int2 operator / ( const int fScalar, const Int2& rhs )
-        {
-            return Int2(
-                fScalar / rhs.x,
-                fScalar / rhs.y);
-        }
-
-        // arithmetic updates
-        inline Int2& operator += ( const Int2& rhs )
-        {
-            x += rhs.x;
-            y += rhs.y;
-
-            return *this;
-        }
-
-        inline Int2& operator -= ( const Int2& rhs )
-        {
-            x -= rhs.x;
-            y -= rhs.y;
-
-            return *this;
-        }
-
-        inline Int2& operator *= ( const int fScalar )
-        {
-            x *= fScalar;
-            y *= fScalar;
-
-            return *this;
-        }
-
-        inline Int2& operator *= ( const Int2& rhs )
-        {
-            x *= rhs.x;
-            y *= rhs.y;
-
-            return *this;
-        }
-
-        inline Int2& operator /= ( const int fScalar )
-        {
-            assert( fScalar != 0 );
-
-            x /= fScalar;
-            y /= fScalar;
-
-            return *this;
-        }
-
-        inline Int2& operator /= ( const Int2& rhs )
-        {
-            x /= rhs.x;
-            y /= rhs.y;
-
-            return *this;
-        }
-	};
-}

+ 9 - 9
CamelotUtility/Include/CmFRect.h → CamelotUtility/Include/CmRectF.h

@@ -4,18 +4,18 @@
 
 namespace CamelotFramework
 {
-	class CM_UTILITY_EXPORT FRect
+	class CM_UTILITY_EXPORT RectF
 	{
 	public:
-		FRect();
-		FRect(float _x, float _y, float _width, float _height);
+		RectF();
+		RectF(float _x, float _y, float _width, float _height);
 
 		float x, y, width, height;
 
 		bool contains(const Vector2& point) const;
-		bool overlaps(const FRect& other) const;
-		void encapsulate(const FRect& other);
-		void clip(const FRect& clipRect);
+		bool overlaps(const RectF& other) const;
+		void encapsulate(const RectF& other);
+		void clip(const RectF& clipRect);
 
 		/**
 		 * @brief	Transforms the bounds by the given matrix.
@@ -26,16 +26,16 @@ namespace CamelotFramework
 		 */
 		void transform(const Matrix4& matrix);
 
-		inline bool operator== (const FRect& rhs) const
+		inline bool operator== (const RectF& rhs) const
 		{
 			return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height;
 		}
 
-		inline bool operator!= (const FRect& rhs) const
+		inline bool operator!= (const RectF& rhs) const
 		{
 			return !(*this == rhs);
 		}
 
-		static const FRect EMPTY;
+		static const RectF EMPTY;
 	};
 }

+ 10 - 10
CamelotUtility/Include/CmRect.h → CamelotUtility/Include/CmRectI.h

@@ -4,18 +4,18 @@
 
 namespace CamelotFramework
 {
-	class CM_UTILITY_EXPORT Rect
+	class CM_UTILITY_EXPORT RectI
 	{
 	public:
-		Rect();
-		Rect(int _x, int _y, int _width, int _height);
+		RectI();
+		RectI(int _x, int _y, int _width, int _height);
 
 		int x, y, width, height;
 
-		bool contains(const Int2& point) const;
-		bool overlaps(const Rect& other) const;
-		void encapsulate(const Rect& other);
-		void clip(const Rect& clipRect);
+		bool contains(const Vector2I& point) const;
+		bool overlaps(const RectI& other) const;
+		void encapsulate(const RectI& other);
+		void clip(const RectI& clipRect);
 
 		/**
 		 * @brief	Transforms the bounds by the given matrix.
@@ -26,16 +26,16 @@ namespace CamelotFramework
 		 */
 		void transform(const Matrix4& matrix);
 
-		inline bool operator== (const Rect& rhs) const
+		inline bool operator== (const RectI& rhs) const
 		{
 			return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height;
 		}
 
-		inline bool operator!= (const Rect& rhs) const
+		inline bool operator!= (const RectI& rhs) const
 		{
 			return !(*this == rhs);
 		}
 
-		static const Rect EMPTY;
+		static const RectI EMPTY;
 	};
 }

+ 177 - 0
CamelotUtility/Include/CmVector2I.h

@@ -0,0 +1,177 @@
+#pragma once
+
+#include "CmPrerequisitesUtil.h"
+
+namespace CamelotFramework
+{
+	struct CM_UTILITY_EXPORT Vector2I
+	{
+		INT32 x;
+		INT32 y;
+
+		Vector2I()
+			:x(0), y(0)
+		{ }
+
+		inline Vector2I(INT32 _x, INT32 _y )
+            :x(_x), y(_y)
+        { }
+
+        explicit Vector2I(int val)
+            :x(val), y(val)
+        { }
+
+		void swap(Vector2I& other)
+		{
+			std::swap(x, other.x);
+			std::swap(y, other.y);
+		}
+
+		UINT32 manhattanDist(const Vector2I& other)
+		{
+			return (UINT32)fabs(float(other.x - x)) + (UINT32)fabs(float(other.y - y));
+		}
+
+		INT32 operator[] (size_t i) const
+        {
+            assert(i < 2);
+
+            return *(&x+i);
+        }
+
+		INT32& operator[] (size_t i)
+        {
+            assert(i < 2);
+
+            return *(&x+i);
+        }
+
+        Vector2I& operator= (const Vector2I& rhs)
+        {
+            x = rhs.x;
+            y = rhs.y;
+
+            return *this;
+        }
+
+		Vector2I& operator= (int val)
+		{
+			x = val;
+			y = val;
+
+			return *this;
+		}
+
+        bool operator== (const Vector2I& rhs) const
+        {
+            return (x == rhs.x && y == rhs.y);
+        }
+
+        bool operator!= (const Vector2I& rhs) const
+        {
+            return (x != rhs.x || y != rhs.y);
+        }
+
+        Vector2I operator+ (const Vector2I& rhs) const
+        {
+            return Vector2I(x + rhs.x, y + rhs.y);
+        }
+
+        Vector2I operator- (const Vector2I& rhs) const
+        {
+            return Vector2I(x - rhs.x, y - rhs.y);
+        }
+
+        Vector2I operator* (int val) const
+        {
+            return Vector2I(x * val, y * val);
+        }
+
+        Vector2I operator* (const Vector2I& rhs) const
+        {
+            return Vector2I(x * rhs.x, y * rhs.y);
+        }
+
+        Vector2I operator/ (int val) const
+        {
+            assert(val != 0);
+
+            return Vector2I(x / val, y / val);
+        }
+
+        Vector2I operator/ (const Vector2I& rhs) const
+        {
+            return Vector2I(x / rhs.x, y / rhs.y);
+        }
+
+        const Vector2I& operator+ () const
+        {
+            return *this;
+        }
+
+        Vector2I operator- () const
+        {
+            return Vector2I(-x, -y);
+        }
+
+        friend Vector2I operator* (int lhs, const Vector2I& rhs)
+        {
+            return Vector2I(lhs * rhs.x, lhs * rhs.y);
+        }
+
+        friend Vector2I operator/ (int lhs, const Vector2I& rhs)
+        {
+            return Vector2I(lhs / rhs.x, lhs / rhs.y);
+        }
+
+        Vector2I& operator+= (const Vector2I& rhs)
+        {
+            x += rhs.x;
+            y += rhs.y;
+
+            return *this;
+        }
+
+        Vector2I& operator-= (const Vector2I& rhs)
+        {
+            x -= rhs.x;
+            y -= rhs.y;
+
+            return *this;
+        }
+
+        Vector2I& operator*= (INT32 val)
+        {
+            x *= val;
+            y *= val;
+
+            return *this;
+        }
+
+        Vector2I& operator*= (const Vector2I& rhs)
+        {
+            x *= rhs.x;
+            y *= rhs.y;
+
+            return *this;
+        }
+
+        Vector2I& operator/= (INT32 val)
+        {
+            assert(val != 0);
+
+            x /= val;
+            y /= val;
+
+            return *this;
+        }
+
+        Vector2I& operator/= (const Vector2I& rhs)
+        {
+            x /= rhs.x;
+            y /= rhs.y;
+
+            return *this;
+        }
+	};
+}

+ 0 - 1
CamelotUtility/Source/CmInt2.cpp

@@ -1 +0,0 @@
-#include "CmInt2.h"

+ 9 - 9
CamelotUtility/Source/CmFRect.cpp → CamelotUtility/Source/CmRectF.cpp

@@ -1,21 +1,21 @@
-#include "CmFRect.h"
+#include "CmRectF.h"
 #include "CmVector2.h"
 #include "CmMatrix4.h"
 #include "CmMath.h"
 
 namespace CamelotFramework
 {
-	const FRect FRect::EMPTY = FRect();
+	const RectF RectF::EMPTY = RectF();
 
-	FRect::FRect()
+	RectF::RectF()
 		:x(0), y(0), width(0), height(0)
 	{ }
 
-	FRect::FRect(float _x, float _y, float _width, float _height)
+	RectF::RectF(float _x, float _y, float _width, float _height)
 		:x(_x), y(_y), width(_width), height(_height)
 	{ }
 
-	bool FRect::contains(const Vector2& point) const
+	bool RectF::contains(const Vector2& point) const
 	{
 		if(point.x >= x && point.x <= (x + width))
 		{
@@ -26,7 +26,7 @@ namespace CamelotFramework
 		return false;
 	}
 
-	bool FRect::overlaps(const FRect& other) const
+	bool RectF::overlaps(const RectF& other) const
 	{
 		float otherRight = other.x + other.width;
 		float myRight = x + width;
@@ -41,7 +41,7 @@ namespace CamelotFramework
 		return false;
 	}
 
-	void FRect::encapsulate(const FRect& other)
+	void RectF::encapsulate(const RectF& other)
 	{
 		float myRight = x + width;
 		float myBottom = y + height;
@@ -65,7 +65,7 @@ namespace CamelotFramework
 			height = myBottom - y;
 	}
 
-	void FRect::clip(const FRect& clipRect)
+	void RectF::clip(const RectF& clipRect)
 	{
 		float newLeft = std::max(x, clipRect.x);
 		float newTop = std::max(y, clipRect.y);
@@ -79,7 +79,7 @@ namespace CamelotFramework
 		height = newBottom - newTop;
 	}
 
-	void FRect::transform(const Matrix4& matrix)
+	void RectF::transform(const Matrix4& matrix)
 	{
 		Vector4 verts[4];
 		verts[0] = Vector4(x, y, 0.0f, 1.0f);

+ 10 - 10
CamelotUtility/Source/CmRect.cpp → CamelotUtility/Source/CmRectI.cpp

@@ -1,21 +1,21 @@
-#include "CmRect.h"
-#include "CmInt2.h"
+#include "CmRectI.h"
+#include "CmVector2I.h"
 #include "CmMatrix4.h"
 #include "CmMath.h"
 
 namespace CamelotFramework
 {
-	const Rect Rect::EMPTY = Rect();
+	const RectI RectI::EMPTY = RectI();
 
-	Rect::Rect()
+	RectI::RectI()
 		:x(0), y(0), width(0), height(0)
 	{ }
 
-	Rect::Rect(int _x, int _y, int _width, int _height)
+	RectI::RectI(int _x, int _y, int _width, int _height)
 		:x(_x), y(_y), width(_width), height(_height)
 	{ }
 
-	bool Rect::contains(const Int2& point) const
+	bool RectI::contains(const Vector2I& point) const
 	{
 		if(point.x >= x && point.x <= (x + width))
 		{
@@ -26,7 +26,7 @@ namespace CamelotFramework
 		return false;
 	}
 
-	bool Rect::overlaps(const Rect& other) const
+	bool RectI::overlaps(const RectI& other) const
 	{
 		INT32 otherRight = other.x + other.width;
 		INT32 myRight = x + width;
@@ -41,7 +41,7 @@ namespace CamelotFramework
 		return false;
 	}
 
-	void Rect::encapsulate(const Rect& other)
+	void RectI::encapsulate(const RectI& other)
 	{
 		int myRight = x + width;
 		int myBottom = y + height;
@@ -65,7 +65,7 @@ namespace CamelotFramework
 			height = myBottom - y;
 	}
 
-	void Rect::clip(const Rect& clipRect)
+	void RectI::clip(const RectI& clipRect)
 	{
 		int newLeft = std::max(x, clipRect.x);
 		int newTop = std::max(y, clipRect.y);
@@ -79,7 +79,7 @@ namespace CamelotFramework
 		height = newBottom - newTop;
 	}
 
-	void Rect::transform(const Matrix4& matrix)
+	void RectI::transform(const Matrix4& matrix)
 	{
 		Vector4 verts[4];
 		verts[0] = Vector4((float)x, (float)y, 0.0f, 1.0f);

+ 1 - 0
CamelotUtility/Source/CmVector2I.cpp

@@ -0,0 +1 @@
+#include "CmVector2I.h"