forked from ThatDamnPineapple/Skyware-stock-trading-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cs
89 lines (76 loc) · 2.03 KB
/
Utilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using SpiritMod.Items.Halloween;
using Terraria.Utilities;
namespace SpiritMod
{
public static class Utililties
{
public static float GetDamageBoost(this Player player)
{
float min = player.meleeDamage;
if (player.magicDamage < min)
min = player.magicDamage;
if (player.rangedDamage < min)
min = player.rangedDamage;
if (player.thrownDamage < min)
min = player.thrownDamage;
if (player.minionDamage < min)
min = player.minionDamage;
return min;
}
public static Vector2 NextVec2CircularEven(this UnifiedRandom rand, float halfWidth, float halfHeight)
{
double x = rand.NextDouble();
double y = rand.NextDouble();
if (x + y > 1)
{
x = 1 - x;
y = 1 - y;
}
double s = 1 / (x + y);
if (double.IsInfinity(s))
return Vector2.Zero;
s *= s;
s = Math.Sqrt(x * x * s + y * y * s);
s = 1 / s;
x *= s;
y *= s;
double r = rand.NextDouble() * (2 * Math.PI);
double cos = Math.Cos(r);
double sin = Math.Sin(r);
return new Vector2((float)(x * cos - y * sin) * halfWidth, (float)(x * sin + y * cos) * halfHeight);
}
public static bool LeftOf(this Vector2 point, Vector2 heading)
{
return heading.X * point.Y - heading.Y * point.X < 0;
}
public static float SideOfNormalize(this Vector2 point, Vector2 heading)
{
float length = heading.Length();
length = (heading.X * point.Y - heading.Y * point.X) / length;
if (float.IsInfinity(length))
return 0f;
return length;
}
public static float SideOf(this Vector2 point, Vector2 normalHeading)
{
return normalHeading.X * point.Y - normalHeading.Y * point.X;
}
public static Vector2 TurnRight(this Vector2 vec)
{
return new Vector2(-vec.Y, vec.X);
}
public static Vector2 TurnLeft(this Vector2 vec)
{
return new Vector2(vec.Y, -vec.X);
}
public static bool Nearing(this Vector2 vec, Vector2 target)
{
return 0 < vec.X * target.X + vec.Y * target.Y;
}
}
}