using System.Collections; using System.Collections.Generic; using Godot; using System.Text; using System; namespace Rokojori { public class Math2D { public static float Dot( Vector2 a, Vector2 b ) { return a.Dot( b ); } public static Vector2 XZ( Vector3 v ) { return new Vector2( v.X, v.Z ); } public static Vector2 Map( Vector2 value, Vector2 inMin, Vector2 inMax, Vector2 outMin, Vector2 outMax ) { return new Vector2( MathX.Map( value.X, inMin.X, inMax.X, outMin.X, outMax.X ), MathX.Map( value.Y, inMin.Y, inMax.Y, outMin.Y, outMax.Y ) ); } public static Vector2 Clamp01( Vector2 v ) { return new Vector2( MathX.Clamp01( v.X ), MathX.Clamp01( v.Y ) ); } public static Vector2 Circle( float radians, float size = 1 ) { var x = Mathf.Cos( radians ) * size; var y = Mathf.Sin( radians ) * size; return new Vector2( x, y ); } public static Vector2 Fract( Vector2 a ) { return new Vector2( MathX.Fract( a.X ), MathX.Fract( a.Y ) ); } public static Vector2 SmoothStep( Vector2 a, Vector2 b, Vector2 t ) { var x = MathX.Smoothstep( a.X, b.X, t.X ); var y = MathX.Smoothstep( a.Y, b.Y, t.Y ); return new Vector2( x, y ); } public static Vector2 Rotate90DegreesRight( Vector2 v ) { // 1, 0.5 => -0.5, 1 : -y, x return new Vector2( -v.Y, v.X ); } public static Vector2 Rotate90DegreesLeft( Vector2 v ) { // -0.5, 1 => 1, 0.5 : y, -x return new Vector2( v.Y, -v.X ); } public static Vector2 Rotate90Degrees( Vector2 v, bool clockwise ) { return clockwise ? Rotate90DegreesRight( v ) : Rotate90DegreesLeft( v ); } } }