From 0349c1af8bc8a2bce0f0423218e52cbab7266f3b Mon Sep 17 00:00:00 2001
From: Alfred Burgess <aburgess@ucc.gu.uwa.edu.au>
Date: Fri, 1 Dec 2023 14:56:30 +0800
Subject: [PATCH] Added basic Vec2 class

---
 include/main.h        |  4 +++-
 include/maths/maths.h |  6 ++++++
 include/maths/vec2.h  | 27 +++++++++++++++++++++++++++
 src/maths/vec2.cpp    | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 include/maths/maths.h
 create mode 100644 include/maths/vec2.h
 create mode 100644 src/maths/vec2.cpp

diff --git a/include/main.h b/include/main.h
index efab701..729d69e 100644
--- a/include/main.h
+++ b/include/main.h
@@ -6,7 +6,8 @@
 
 enum GenerationMethod
 {
-	Random
+	Random,
+	Cave
 };
 
 #include "save-manager.h"
@@ -15,5 +16,6 @@ enum GenerationMethod
 #include "world-map-3d.h"
 #include "chunk.h"
 #include "logger.h"
+#include "maths/maths.h"
 
 #endif // MAIN_H
diff --git a/include/maths/maths.h b/include/maths/maths.h
new file mode 100644
index 0000000..fea450c
--- /dev/null
+++ b/include/maths/maths.h
@@ -0,0 +1,6 @@
+#ifndef __MATHEMATICS_INCLUDE_H__
+#define __MATHEMATICS_INCLUDE_H__
+
+#include "maths/vec2.h"
+
+#endif //  __MATHEMATICS_INCLUDE_H__
diff --git a/include/maths/vec2.h b/include/maths/vec2.h
new file mode 100644
index 0000000..e01f0f7
--- /dev/null
+++ b/include/maths/vec2.h
@@ -0,0 +1,27 @@
+#ifndef __MATHS__VEC2_H__
+#define __MATHS__VEC2_H__
+
+#include <cmath>
+
+class Vec2
+{
+	public:
+		float x = 0, y = 0;
+		Vec2();
+		Vec2( float xIn, float yIn );
+		
+		bool operator == ( const Vec2 rhs ) const;
+		Vec2 operator + ( const Vec2 rhs ) const;
+		Vec2 operator * ( const Vec2 rhs ) const;
+		Vec2 operator - ( const Vec2 rhs ) const;
+		Vec2 operator * ( const float scale ) const;
+		void operator += ( const Vec2 & rhs );
+		void operator -= ( const Vec2 & rhs );
+		void operator *= ( const Vec2 & rhs );
+		void operator *= ( const float rhs );
+
+		float length();
+		void normalise();
+};
+
+#endif // __MATHS__VEC2_H__
diff --git a/src/maths/vec2.cpp b/src/maths/vec2.cpp
new file mode 100644
index 0000000..aee6719
--- /dev/null
+++ b/src/maths/vec2.cpp
@@ -0,0 +1,32 @@
+#include "maths/vec2.h"
+
+Vec2::Vec2()
+	: Vec2( 0.0, 0.0 ) {}
+Vec2::Vec2( float xIn, float yIn )
+	: x( xIn ), y( yIn )
+{};
+		
+bool Vec2::operator == ( const Vec2 rhs ) const {
+	return (
+		abs( this->x - rhs.x ) < 0.01
+	) && (
+		abs( this->y - rhs.y ) < 0.01
+	);
+}
+Vec2 Vec2::operator + ( const Vec2 rhs ) const { return Vec2( this->x + rhs.x, this->y + rhs.y ); }
+Vec2 Vec2::operator - ( const Vec2 rhs ) const { return Vec2( this->x - rhs.x, this->y - rhs.y ); }
+Vec2 Vec2::operator * ( const Vec2 rhs ) const { return Vec2( this->x * rhs.x, this->y * rhs.y ); }
+Vec2 Vec2::operator * ( const float scale ) const { return Vec2( this->x * scale, this->y * scale ); }
+void Vec2::operator += ( const Vec2 & rhs ) { this->x += rhs.x; this->y += rhs.y; }
+void Vec2::operator -= ( const Vec2 & rhs ) { this->x -= rhs.x; this->y -= rhs.y; }
+void Vec2::operator *= ( const Vec2 & rhs ) { this->x *= rhs.x; this->y *= rhs.y; }
+void Vec2::operator *= ( const float scale ) { this->x *= scale; this->y *= scale; }
+
+float Vec2::length()
+	{ return sqrtf( this->x*this->x + this->y*this->y ); }
+void Vec2::normalise()
+{
+	float mag = this->length();
+	this->x /= mag;
+	this->y /= mag;
+}
-- 
GitLab