gd_core/addons/core/math/MathUtil.cs

68 lines
1.3 KiB
C#

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// D E R E L I C T
//
/// // (c) 2003..2025
using Godot;
using Godot.Sharp.Extras;
using System;
static public class MathExtensions
{
static public int Range( this Random rand, int top )
{
return rand.Range( 0, top );
}
static public float Range( this Random rand, float top )
{
return rand.Range( 0.0f, top );
}
static public double Range( this Random rand, double top )
{
return rand.Range( 0.0, top );
}
static public int Range( this Random rand, int bot, int top )
{
var range = top - bot;
var r = ( rand.Next() % range ) + bot;
return r;
}
static public float Range( this Random rand, float bot, float top )
{
var range = top - bot;
var r = ( rand.NextSingle() * range ) + bot;
return r;
}
static public double Range( this Random rand, double bot, double top )
{
var range = top - bot;
var r = ( rand.NextDouble() * range ) + bot;
return r;
}
//static public string ToLog(this Vector2 v) => $"{v.X:0.00}, {v.Y:0.00}";
extension( Vector2 v )
{
public string Log => $"{v.X:0.00}, {v.Y:0.00}";
}
extension( Vector3 v )
{
public string Log => $"{v.X:0.00}, {v.Y:0.00}, {v.Z:0.00}";
}
}