<commit_before>#ifndef __TYPES_H__
#define __TYPES_H__

#include <stdlib.h>
#include <memory.h>
#include <math.h>

#define sqre(x) (x*x)
#define sign(x) (x>0?1:(x<0?-1:0))

namespace sarklib{

	//=============== Vector Types =================

	/**
		Type of vector 2D
	*/
	class Vector2{
	public:
		float x,y;

		Vector2() :x(0.0f), y(0.0f)
		{ }
		Vector2(float val) :x(val), y(val)
		{ }
		Vector2(float _x, float _y)
			: x(_x), y(_y)
		{ }
		Vector2(const Vector2& v){
			x=v.x; y=v.y;
		}
		void operator=(const Vector2& v){
			x=v.x; y=v.y;
		}

		void Set(float _x, float _y){
			x = _x; y = _y;
		}

		// vector magnitude
		float Magnitude() const{
			return sqrtf( MagnitudeSq() );
		}

		float MagnitudeSq() const{
			return sqre(x) + sqre(y);
		}

		// unary - operator
		const Vector2 operator-() const{
			return Vector2(-x, -y);
		}


		// vector plus operator
		const Vector2 operator+(const Vector2& v) const{
			return Vector2(x + v.x, y + v.y);
		}

		const Vector2 operator+(float fConstant) const{
			return Vector2(x + fConstant, y + fConstant);
		}

		friend const Vector2 operator+(float fConstant, const Vector2& v);

		const Vector2& operator+=(const Vector2& v){
			x += v.x; y += v.y;
			return *this;
		}

		const Vector2& operator+=(float fConstant){
			x += fConstant; y += fConstant;
			return *this;
		}


		// vector minus operator
		const Vector2 operator-(const Vector2& v) const{
			return Vector2(x - v.x, y - v.y);
		}

		const Vector2 operator-(float fConstant) const{
			return Vector2(x - fConstant, y - fConstant);
		}

		const Vector2& operator-=(const Vector2& v){
			x -= v.x; y -= v.y;
			return *this;
		}

		const Vector2& operator-=(float fConstant){
			x -= fConstant; y -= fConstant;
			return *this;
		}


		// vector constant multiplication operator (it is not cross operation)
		const Vector2 operator*(float fConstant) const{
			return Vector2(x*fConstant, y*fConstant);
		}

		friend const Vector2 operator*(float fConstant, const Vector2& v);

		const Vector2& operator*=(float fConstant){
			x *= fConstant; y *= fConstant;
			return *this;
		}


		// vector constnat division operator
		const Vector2 operator/(float fConstant) const{
			return Vector2(x/fConstant, y/fConstant);
		}

		const Vector2& operator/=(float fConstant){
			x /= fConstant; y /= fConstant;
			return *this;
		}

		// boolean operators
		bool operator==(const Vector2& v) const{
			return (x==v.x && y==v.y);
		}

		bool operator!=(const Vector2& v) const{
			return (x!=v.x || y!=v.y);
		}


		// dot product
		float Dot(const Vector2& v) const{
			return x*v.x + y*v.y;
		}


		// normalization
		void Normalize(){
			float mag = Magnitude();
			if( mag == 0 )
				return;
			x /= mag;
			y /= mag;
		}
	};
	typedef Vector2 Vertex2;
	typedef Vector2 Position2;

	// Vector2 friend operators
	const Vector2 operator+(float fConstant, const Vector2& v){
		return Vector2(fConstant + v.x, fConstant + v.y);
	}

	const Vector2 operator*(float fConstant, const Vector2& v){
		return Vector2(fConstant * v.x, fConstant * v.y);
	}



	/**
		Type of vector 3D
	*/
	class Vector3{
	public:
		float x,y,z;

		Vector3() :x(0.0f), y(0.0f), z(0.0f)
		{ }
		Vector3(float val) :x(val), y(val), z(val)
		{ }
		Vector3(float _x, float _y, float _z)
			: x(_x), y(_y), z(_z)
		{ }
		Vector3(const Vector3& v){
			x=v.x; y=v.y; z=v.z;
		}
		void operator=(const Vector3& v){
			x=v.x; y=v.y; z=v.z;
		}

		void Set(float _x, float _y, float _z){
			x=_x; y=_y; z=_z;
		}

		// explicitly type cast
		explicit Vector3(const Vector2& v){
			x=v.x; y=v.y; z=0.0f;
		}


		// vector magnitude
		float Magnitude() const{
			return sqrtf( MagnitudeSq() );
		}

		float MagnitudeSq() const{
			return sqre(x) + sqre(y) + sqre(z);
		}

		// unary - operator
		const Vector3 operator-() const{
			return Vector3(-x, -y, -z);
		}


		// vector plus operator
		const Vector3 operator+(const Vector3& v) const{
			return Vector3(x + v.x, y + v.y, z + v.z);
		}

		const Vector3 operator+(float fConstant) const{
			return Vector3(x + fConstant, y + fConstant, z + fConstant);
		}

		friend const Vector3 operator+(float fConstant, const Vector3& v);

		const Vector3& operator+=(const Vector3& v){
			x += v.x; y += v.y; z += v.z;
			return *this;
		}

		const Vector3& operator+=(float fConstant){
			x += fConstant; y += fConstant; z += fConstant;
			return *this;
		}


		// vector minus operator
		const Vector3 operator-(const Vector3& v) const{
			return Vector3(x - v.x, y - v.y, z - v.z);
		}

		const Vector3 operator-(float fConstant) const{
			return Vector3(x - fConstant, y - fConstant, z - fConstant);
		}

		const Vector3& operator-=(const Vector3& v){
			x -= v.x; y -= v.y; z -= v.z;
			return *this;
		}

		const Vector3& operator-=(float fConstant){
			x -= fConstant; y -= fConstant; z -= fConstant;
			return *this;
		}


		// vector constant multiplication operator (it is not cross operation)
		const Vector3 operator*(float fConstant) const{
			return Vector3(x*fConstant, y*fConstant, z*fConstant);
		}

		friend const Vector3 operator*(float fConstant, const Vector3& v);

		const Vector3& operator*=(float fConstant){
			x *= fConstant; y *= fConstant; z *= fConstant;
			return *this;
		}


		// vector constnat division operator
		const Vector3 operator/(float fConstant) const{
			return Vector3(x/fConstant, y/fConstant, z/fConstant);
		}

		const Vector3& operator/=(float fConstant){
			x /= fConstant; y /= fConstant; z /= fConstant;
			return *this;
		}

		// boolean operators
		bool operator==(const Vector3& v) const{
			return (x==v.x && y==v.y && z==v.z);
		}

		bool operator!=(const Vector3& v) const{
			return (x!=v.x || y!=v.y || z!=v.z);
		}


		// dot product
		float Dot(const Vector3& v) const{
			return x*v.x + y*v.y + z*v.z;
		}

		// cross product
		const Vector3 Cross(const Vector3& v) const{
			return Vector3(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
		}

		// normalization
		void Normalize(){
			float mag = Magnitude();
			if( mag == 0 )
				return;
			x /= mag;
			y /= mag;
			z /= mag;
		}
	};
	typedef Vector3 Vertex3;
	typedef Vector3 Position3;

	// Vector3 friend operators
	const Vector3 operator+(float fConstant, const Vector3& v){
		return Vector3(fConstant + v.x, fConstant + v.y, fConstant + v.z);
	}
<commit_msg>add Normal() method into Vector2, 3<commit_after>#ifndef __TYPES_H__
#define __TYPES_H__

#include <stdlib.h>
#include <memory.h>
#include <math.h>

#define sqre(x) (x*x)
#define sign(x) (x>0?1:(x<0?-1:0))

namespace sarklib{

	//=============== Vector Types =================

	/**
		Type of vector 2D
	*/
	class Vector2{
	public:
		float x,y;

		Vector2() :x(0.0f), y(0.0f)
		{ }
		Vector2(float val) :x(val), y(val)
		{ }
		Vector2(float _x, float _y)
			: x(_x), y(_y)
		{ }
		Vector2(const Vector2& v){
			x=v.x; y=v.y;
		}
		void operator=(const Vector2& v){
			x=v.x; y=v.y;
		}

		void Set(float _x, float _y){
			x = _x; y = _y;
		}

		// vector magnitude
		float Magnitude() const{
			return sqrtf( sqre(x) + sqre(y) );
		}

		float MagnitudeSq() const{
			return sqre(x) + sqre(y);
		}

		// unary - operator
		const Vector2 operator-() const{
			return Vector2(-x, -y);
		}


		// vector plus operator
		const Vector2 operator+(const Vector2& v) const{
			return Vector2(x + v.x, y + v.y);
		}

		const Vector2 operator+(float fConstant) const{
			return Vector2(x + fConstant, y + fConstant);
		}

		friend const Vector2 operator+(float fConstant, const Vector2& v);

		const Vector2& operator+=(const Vector2& v){
			x += v.x; y += v.y;
			return *this;
		}

		const Vector2& operator+=(float fConstant){
			x += fConstant; y += fConstant;
			return *this;
		}


		// vector minus operator
		const Vector2 operator-(const Vector2& v) const{
			return Vector2(x - v.x, y - v.y);
		}

		const Vector2 operator-(float fConstant) const{
			return Vector2(x - fConstant, y - fConstant);
		}

		const Vector2& operator-=(const Vector2& v){
			x -= v.x; y -= v.y;
			return *this;
		}

		const Vector2& operator-=(float fConstant){
			x -= fConstant; y -= fConstant;
			return *this;
		}


		// vector constant multiplication operator (it is not cross operation)
		const Vector2 operator*(float fConstant) const{
			return Vector2(x*fConstant, y*fConstant);
		}

		friend const Vector2 operator*(float fConstant, const Vector2& v);

		const Vector2& operator*=(float fConstant){
			x *= fConstant; y *= fConstant;
			return *this;
		}


		// vector constnat division operator
		const Vector2 operator/(float fConstant) const{
			return Vector2(x/fConstant, y/fConstant);
		}

		const Vector2& operator/=(float fConstant){
			x /= fConstant; y /= fConstant;
			return *this;
		}

		// boolean operators
		bool operator==(const Vector2& v) const{
			return (x==v.x && y==v.y);
		}

		bool operator!=(const Vector2& v) const{
			return (x!=v.x || y!=v.y);
		}


		// dot product
		float Dot(const Vector2& v) const{
			return x*v.x + y*v.y;
		}


		// get normal and normalize this
		const Vector2 Normal() const{
			float mag = Magnitude();
			return Vector2(x/mag, y/mag);
		}
		void Normalize(){
			float mag = Magnitude();
			x /= mag;
			y /= mag;
		}
	};
	typedef Vector2 Vertex2;
	typedef Vector2 Position2;

	// Vector2 friend operators
	const Vector2 operator+(float fConstant, const Vector2& v){
		return Vector2(fConstant + v.x, fConstant + v.y);
	}

	const Vector2 operator*(float fConstant, const Vector2& v){
		return Vector2(fConstant * v.x, fConstant * v.y);
	}



	/**
		Type of vector 3D
	*/
	class Vector3{
	public:
		float x,y,z;

		Vector3() :x(0.0f), y(0.0f), z(0.0f)
		{ }
		Vector3(float val) :x(val), y(val), z(val)
		{ }
		Vector3(float _x, float _y, float _z)
			: x(_x), y(_y), z(_z)
		{ }
		Vector3(const Vector3& v){
			x=v.x; y=v.y; z=v.z;
		}
		void operator=(const Vector3& v){
			x=v.x; y=v.y; z=v.z;
		}

		void Set(float _x, float _y, float _z){
			x=_x; y=_y; z=_z;
		}

		// explicitly type cast
		explicit Vector3(const Vector2& v){
			x=v.x; y=v.y; z=0.0f;
		}


		// vector magnitude
		float Magnitude() const{
			return sqrtf( sqre(x) + sqre(y) + sqre(z) );
		}

		float MagnitudeSq() const{
			return sqre(x) + sqre(y) + sqre(z);
		}

		// unary - operator
		const Vector3 operator-() const{
			return Vector3(-x, -y, -z);
		}


		// vector plus operator
		const Vector3 operator+(const Vector3& v) const{
			return Vector3(x + v.x, y + v.y, z + v.z);
		}

		const Vector3 operator+(float fConstant) const{
			return Vector3(x + fConstant, y + fConstant, z + fConstant);
		}

		friend const Vector3 operator+(float fConstant, const Vector3& v);

		const Vector3& operator+=(const Vector3& v){
			x += v.x; y += v.y; z += v.z;
			return *this;
		}

		const Vector3& operator+=(float fConstant){
			x += fConstant; y += fConstant; z += fConstant;
			return *this;
		}


		// vector minus operator
		const Vector3 operator-(const Vector3& v) const{
			return Vector3(x - v.x, y - v.y, z - v.z);
		}

		const Vector3 operator-(float fConstant) const{
			return Vector3(x - fConstant, y - fConstant, z - fConstant);
		}

		const Vector3& operator-=(const Vector3& v){
			x -= v.x; y -= v.y; z -= v.z;
			return *this;
		}

		const Vector3& operator-=(float fConstant){
			x -= fConstant; y -= fConstant; z -= fConstant;
			return *this;
		}


		// vector constant multiplication operator (it is not cross operation)
		const Vector3 operator*(float fConstant) const{
			return Vector3(x*fConstant, y*fConstant, z*fConstant);
		}

		friend const Vector3 operator*(float fConstant, const Vector3& v);

		const Vector3& operator*=(float fConstant){
			x *= fConstant; y *= fConstant; z *= fConstant;
			return *this;
		}


		// vector constnat division operator
		const Vector3 operator/(float fConstant) const{
			return Vector3(x/fConstant, y/fConstant, z/fConstant);
		}

		const Vector3& operator/=(float fConstant){
			x /= fConstant; y /= fConstant; z /= fConstant;
			return *this;
		}

		// boolean operators
		bool operator==(const Vector3& v) const{
			return (x==v.x && y==v.y && z==v.z);
		}

		bool operator!=(const Vector3& v) const{
			return (x!=v.x || y!=v.y || z!=v.z);
		}


		// dot product
		float Dot(const Vector3& v) const{
			return x*v.x + y*v.y + z*v.z;
		}

		// cross product
		const Vector3 Cross(const Vector3& v) const{
			return Vector3(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
		}

		// get normal and normalize this
		const Vector3 Normal() const{
			float mag = Magnitude();
			return Vector3(x/mag, y/mag, z/mag);
		}
		void Normalize(){
			float mag = Magnitude();
			x /= mag;
			y /= mag;
			z /= mag;
		}
	};
	typedef Vector3 Vertex3;
	typedef Vector3 Position3;

	// Vector3 friend operators
	const Vector3 operator+(float fConstant, const Vector3& v){
		return Vector3(fConstant + v.x, fConstant + v.y, fConstant + v.z);
	}

{'fraction_non_alphanumeric': 0.1577178585384916, 'fraction_numerical': 0.01922626025791325, 'mean_word_length': 2.968982630272953, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6569137', 'n_tokens_mistral': 5524, 'n_tokens_neox': 4820, 'n_words': 1347}