-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUtils.cs
More file actions
90 lines (78 loc) · 2.61 KB
/
Copy pathUtils.cs
File metadata and controls
90 lines (78 loc) · 2.61 KB
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
90
using Sandbox.Game.EntityComponents;
using Sandbox.ModAPI.Ingame;
using Sandbox.ModAPI.Interfaces;
using SpaceEngineers.Game.ModAPI.Ingame;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System;
using VRage;
using VRage.Collections;
using VRage.Game.Components;
using VRage.Game.ModAPI.Ingame;
using VRage.Game.ModAPI.Ingame.Utilities;
using VRage.Game.ObjectBuilders.Definitions;
using VRage.Game;
using VRageMath;
namespace IngameScript
{
partial class Program
{
const float degToRad = (float)Math.PI / 180;
const float radToDeg = 180.0f / (float)Math.PI;
public static bool IsEqual(float value1, float value2, float epsilon = 0.0001f)
{
return Math.Abs(NotNaN(value1 - value2)) <= epsilon;
}
public static float NotNaN(float value)
{
return float.IsNaN(value) ? 0 : value;
}
public static float MinAbs(float value1, float value2)
{
return Math.Min(Math.Abs(value1), Math.Abs(value2)) * (value1 < 0 ? -1 : 1);
}
class ConfigSection
{
Dictionary<string, string> config;
string name;
public ConfigSection(string name)
{
this.config = new Dictionary<string, string>();
this.name = name;
}
public void Read(string text)
{
config.Clear();
var ini = new MyIni();
MyIniParseResult parseResult;
if (!ini.TryParse(text, out parseResult))
throw new Exception("Failed To Read Config: " + parseResult.Error + " on line" + parseResult.LineNo.ToString());
var keys = new List<MyIniKey>();
ini.GetKeys(name, keys);
foreach (var key in keys)
{
config.Add(key.Name, ini.Get(key).ToString());
}
}
public string write()
{
MyIni ini = new MyIni();
ini.AddSection(name);
foreach (var kv in config) { ini.Set(name, kv.Key, kv.Value); }
return ini.ToString();
}
public T Get<T>(string key, T value)
{
if (!config.ContainsKey(key))
{
config.Add(key, value.ToString());
return value;
}
string result; config.TryGetValue(key, out result);
return (T)Convert.ChangeType(result, typeof(T));
}
}
}
}