using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// Throughout this class a 2 or 3 after a function name means Vector2 and Vector3 respectively.

namespace com.deeperbeige.lib
{
    public class Maths
    {
		// Pick a whole number between the limits (inclusive)
		public static int RandomInt(int min, int max)
		{
			return UnityEngine.Random.Range(min, max + 1);
		}
		
		// Pick a floating point between the limits (inclusive)
		public static Vector2 RandomFloat2(float min, float max) { float v = RandomFloat(min, max); return new Vector2(v, v); }
		public static Vector3 RandomFloat3(float min, float max) { float v = RandomFloat(min, max); return new Vector3(v, v, v); }
		public static float   RandomFloat (float min, float max)
		{
			return UnityEngine.Random.Range(min, max);
		}
		
		// Returns -1f or 1f at random
		public static float RandomSign()
		{
			if (UnityEngine.Random.Range(0f, 1f) < 0.5f) return 1f;
			return -1f;
		}
		
		// Add/subtract all sorts of vector types together to defined return types (useful for modifying transforms directly)
		// Crushes 'missing' properties
		public static Vector3 Add2(Vector2 a, Vector2 b) { return a + b; }
		public static Vector3 Add2(Vector2 a, Vector3 b) { return a + new Vector2(b.x, b.y); }
		public static Vector3 Add2(Vector3 a, Vector2 b) { return new Vector2(a.x, a.y) + b; }
		public static Vector3 Add2(Vector3 a, Vector3 b) { return new Vector2(a.x + b.x, a.y + b.y); }
		
		public static Vector3 Add3(Vector2 a, Vector2 b) { return new Vector3(a.x + b.x, a.y + b.y, 0); }
		public static Vector3 Add3(Vector2 a, Vector3 b) { return new Vector3(a.x, a.y, 0) + b; }
		public static Vector3 Add3(Vector3 a, Vector2 b) { return a + new Vector3(b.x, b.y, 0); }
		public static Vector3 Add3(Vector3 a, Vector3 b) { return a + b; }
		
		public static Vector3 Subtract2(Vector2 a, Vector2 b) { return a - b; }
		public static Vector3 Subtract2(Vector2 a, Vector3 b) { return a - new Vector2(b.x, b.y); }
		public static Vector3 Subtract2(Vector3 a, Vector2 b) { return new Vector2(a.x, a.y) - b; }
		public static Vector3 Subtract2(Vector3 a, Vector3 b) { return new Vector2(a.x - b.x, a.y - b.y); }
		
		public static Vector3 Subtract3(Vector2 a, Vector2 b) { return new Vector3(a.x - b.x, a.y - b.y, 0); }
		public static Vector3 Subtract3(Vector2 a, Vector3 b) { return new Vector3(a.x, a.y, 0) - b; }
		public static Vector3 Subtract3(Vector3 a, Vector2 b) { return a - new Vector3(b.x, b.y, 0); }
		public static Vector3 Subtract3(Vector3 a, Vector3 b) { return a - b; }
	}
}