-
Notifications
You must be signed in to change notification settings - Fork 249
/
ArrayWrapper.cs
218 lines (182 loc) · 4.55 KB
/
ArrayWrapper.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* Copyright Lamont Granquist, Sebastien Gaggini and the MechJeb contributors
* SPDX-License-Identifier: LicenseRef-PD-hp OR Unlicense OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT OR LGPL-2.1+
*/
#nullable enable
using System;
using System.Collections.Generic;
using MechJebLib.Primitives;
using MechJebLib.Utils;
namespace MechJebLib.PVG
{
// FIXME: rename this and bust it up into inputwrapper/outputwrapper and a base class
public class ArrayWrapper : IDisposable
{
private static readonly ObjectPool<ArrayWrapper> _pool = new ObjectPool<ArrayWrapper>(New, Clear);
private IList<double> _list;
public const int ARRAY_WRAPPER_LEN = 15;
private ArrayWrapper()
{
_list = null!;
}
private static ArrayWrapper New()
{
return new ArrayWrapper();
}
public double Rx
{
get => this[0];
set => this[0] = value;
}
public double Ry
{
get => this[1];
set => this[1] = value;
}
public double Rz
{
get => this[2];
set => this[2] = value;
}
public V3 R
{
get => new V3(Rx, Ry, Rz);
set
{
Rx = value[0];
Ry = value[1];
Rz = value[2];
}
}
public double Vx
{
get => this[3];
set => this[3] = value;
}
public double Vy
{
get => this[4];
set => this[4] = value;
}
public double Vz
{
get => this[5];
set => this[5] = value;
}
public V3 V
{
get => new V3(Vx, Vy, Vz);
set
{
Vx = value[0];
Vy = value[1];
Vz = value[2];
}
}
public double PVx
{
get => this[6];
set => this[6] = value;
}
public double PVy
{
get => this[7];
set => this[7] = value;
}
public double PVz
{
get => this[8];
set => this[8] = value;
}
public V3 PV
{
get => new V3(PVx, PVy, PVz);
set
{
PVx = value[0];
PVy = value[1];
PVz = value[2];
}
}
public double PRx
{
get => this[9];
set => this[9] = value;
}
public double PRy
{
get => this[10];
set => this[10] = value;
}
public double PRz
{
get => this[11];
set => this[11] = value;
}
public V3 PR
{
get => new V3(this[9], this[10], this[11]);
set
{
this[9] = value[0];
this[10] = value[1];
this[11] = value[2];
}
}
public double CostateMagnitude =>
Math.Sqrt(PRx * PRx + PRy * PRy + PRz * PRz + PVx * PVx + PVy * PVy + PVz * PVz);
public double M
{
get => this[12];
set => this[12] = value;
}
public double Pm
{
get => this[13];
set => this[13] = value;
}
public double H0
{
get
{
double rm = R.magnitude;
return V3.Dot(PR, V) -
V3.Dot(PV, R) / (rm * rm * rm); // FIXME: this changes for linear gravity model??!?!?
}
}
public double Bt
{
get => this[14];
set => this[14] = value;
}
public double DV
{
get => this[14];
set => this[14] = value;
}
public double this[int i]
{
get => _list[i];
set => _list[i] = value;
}
public void CopyTo(IList<double> other)
{
for (int i = 0; i < ARRAY_WRAPPER_LEN; i++)
other[i] = this[i];
}
public static ArrayWrapper Rent(IList<double> list)
{
Check.True(list.Count >= ARRAY_WRAPPER_LEN);
ArrayWrapper wrapper = _pool.Borrow();
wrapper._list = list;
return wrapper;
}
public void Dispose()
{
_pool.Release(this);
}
public static void Clear(ArrayWrapper obj)
{
}
}
}