public ColorF(float r, float g, float b) { this.R = FlaiMath.Clamp((byte)(r * 255), byte.MinValue, byte.MaxValue); this.G = FlaiMath.Clamp((byte)(g * 255), byte.MinValue, byte.MaxValue); this.B = FlaiMath.Clamp((byte)(b * 255), byte.MinValue, byte.MaxValue); this.A = 255; }
public SerializableColorF(float r, float g, float b, float a) { this.R = FlaiMath.Clamp((byte)(r * 255), byte.MinValue, byte.MaxValue); this.G = FlaiMath.Clamp((byte)(g * 255), byte.MinValue, byte.MaxValue); this.B = FlaiMath.Clamp((byte)(b * 255), byte.MinValue, byte.MaxValue); this.A = FlaiMath.Clamp((byte)(a * 255), byte.MinValue, byte.MaxValue); }
public static Direction2D FromRotation(float degrees, Direction2D startDirection = Direction2D.Right) // { degrees = FlaiMath.RealModulus(degrees, 360); int step = (int)FlaiMath.Round(degrees / 90); return((Direction2D)FlaiMath.RealModulus((int)(step + startDirection), 4)); }
public static Vector2 NormalizeOrZero(Vector2i value) { if (value.X == 0 && value.Y == 0) { return(Vector2.zero); } return(FlaiMath.Normalize(value)); }
public static Vector2d Rotate(Vector2d point, double radians) { double cosRadians = FlaiMath.Cos(radians); double sinRadians = FlaiMath.Sin(radians); return(new Vector2d( point.X * cosRadians - point.Y * sinRadians, point.X * sinRadians + point.Y * cosRadians)); }
public static Vector2 Normalize(Vector2i value) { int sum = value.X * value.X + value.Y * value.Y; float divider = 1f / FlaiMath.Sqrt(sum); return(new Vector2 { x = value.X * divider, y = value.Y * divider }); }
public static Vector2f Rotate(Vector2f point, float radians) { float cosRadians = FlaiMath.Cos(radians * Mathf.Deg2Rad); float sinRadians = FlaiMath.Sin(radians * Mathf.Deg2Rad); return(new Vector2( point.X * cosRadians - point.Y * sinRadians, point.X * sinRadians + point.Y * cosRadians)); }
public static ColorF operator -(ColorF a, ColorF b) { return(new ColorF { R = (byte)FlaiMath.Max(0, a.R - b.R), G = (byte)FlaiMath.Max(0, a.G - b.G), B = (byte)FlaiMath.Max(0, a.B - b.B), A = (byte)FlaiMath.Max(0, a.A - b.A), }); }
public static ColorF operator +(ColorF a, ColorF b) { return(new ColorF { R = (byte)FlaiMath.Min(255, a.R + b.R), G = (byte)FlaiMath.Min(255, a.G + b.G), B = (byte)FlaiMath.Min(255, a.B + b.B), A = (byte)FlaiMath.Min(255, a.A + b.A), }); }
public static float MinimumDistance(Segment2D segment, Circle circle) { if (Segment2D.Intersects(segment, circle)) { return(0); } // okay this Max *should be* unnecessary, but lets keep it just for sure return(FlaiMath.Max(0, Segment2D.MinimumDistance(segment, circle.Position) - circle.Radius)); }
// is this accurate? could be... public static float MaximumDistance(Segment2D segment, RectangleF rectangle) { if (Segment2D.Intersects(segment, rectangle)) { return(0); } return(FlaiMath.Max( Segment2D.MaximumDistance(segment, rectangle.TopLeft), Segment2D.MaximumDistance(segment, rectangle.TopRight), Segment2D.MaximumDistance(segment, rectangle.BottomLeft), Segment2D.MaximumDistance(segment, rectangle.BottomRight))); }
public static float Lerp(LerpType lerpType, float value1, float value2, float amount) { if (lerpType == LerpType.Lerp) { return(FlaiMath.Lerp(value1, value2, amount)); } else if (lerpType == LerpType.Instant) { return(value2); } return(FlaiMath.SmoothStep(value1, value2, amount)); }
// radians public static float ShortestAngleDistance(float angle1, float angle2) { angle1 = FlaiMath.WrapAngle(angle1); angle2 = FlaiMath.WrapAngle(angle2); if (angle1 <= angle2) { return((angle2 - angle1) <= FlaiMath.Pi ? (angle2 - angle1) : (-angle1 - (FlaiMath.TwoPi - angle2))); } else // angle1 > angle2 { return((angle1 - angle2) <= FlaiMath.Pi ? -(angle1 - angle2) : (angle2 + (FlaiMath.TwoPi - angle1))); } }
public static float Round(this RoundingOptions roundingOptions, float value) { switch (roundingOptions) { case RoundingOptions.Default: return((int)value); case RoundingOptions.Floor: return(FlaiMath.Floor(value)); case RoundingOptions.Ceiling: return(FlaiMath.Ceiling(value)); case RoundingOptions.Round: return(FlaiMath.Round(value)); default: throw new ArgumentException("roundingOptions"); } }
public static Vector2f ClampY(Vector2f vec, float min, float max) { Ensure.True(min <= max); vec.Y = FlaiMath.Clamp(vec.Y, min, max); return(vec); }
public static Vector2f Clamp(Vector2f value, Vector2f min, Vector2f max) { return(new Vector2f(FlaiMath.Clamp(value.X, min.X, max.X), FlaiMath.Clamp(value.Y, min.Y, max.Y))); }
public static Vector2f Max(Vector2f value1, Vector2f value2, Vector2f value3, Vector2f value4) { return(new Vector2f(FlaiMath.Max(value1.X, value2.X, value3.X, value4.X), FlaiMath.Max(value1.Y, value2.Y, value3.Y, value4.Y))); }
public static Vector2f Min(Vector2f value1, Vector2f value2, Vector2f value3) { return(new Vector2f(FlaiMath.Min(value1.X, value2.X, value3.X), FlaiMath.Min(value1.Y, value2.Y, value3.Y))); }
public static Vector2f Abs(Vector2f value) { return(new Vector2f(FlaiMath.Abs(value.X), FlaiMath.Abs(value.Y))); }
public static float Distance(Vector2f value1, Vector2f value2) { return(FlaiMath.Sqrt(Vector2f.DistanceSquared(value1, value2))); }
public static Vector2f GetAngleVectorDeg(float degrees) { return(FlaiMath.GetAngleVector(FlaiMath.ToRadians(degrees))); }
public static float GetAngleDeg(Vector2f vector) { return(FlaiMath.ToDegrees(FlaiMath.GetAngle(vector))); }
public static float WrapAngleDeg(float angle) { return(FlaiMath.ToDegrees(FlaiMath.WrapAngle(FlaiMath.ToRadians(angle)))); }
public byte NextByte() { return((byte)FlaiMath.Round(base.NextDouble() * 255)); // 255 or 256? }
public static double SmoothStep(double value1, double value2, double amount) { double num = FlaiMath.Clamp(amount, 0f, 1f); return(FlaiMath.Lerp(value1, value2, num * num * (3f - 2f * num))); }
public static Vector2f SmoothStep(Vector2f current, Vector2f target, float amount) { return(new Vector2f { X = FlaiMath.SmoothStep(current.X, target.X, amount), Y = FlaiMath.SmoothStep(current.Y, target.Y, amount) }); }
// deg public static float AngleLerp(float angle1, float angle2, float amount) { return(angle1 + FlaiMath.ShortestAngleDistanceDeg(angle1, angle2) * amount); }
public static Vector2d GetAngleVectorDeg(double degrees) { return(FlaiMath.GetAngleVector(FlaiMath.ToRadians(degrees))); }
public byte NextByte(byte min, byte max) { return((byte)FlaiMath.Round(min + base.NextDouble() * (max - min))); // 255 or 256? }
// deg public static float AngleSmoothstep(float angle1, float angle2, float amount) { amount = amount * amount * (3f - 2f * amount); return(angle1 + FlaiMath.ShortestAngleDistanceDeg(angle1, angle2) * amount); }