/
ResidualWrapper.cs
164 lines (139 loc) · 3.51 KB
/
ResidualWrapper.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
/*
* 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
{
public class ResidualWrapper : IDisposable
{
private static readonly ObjectPool<ResidualWrapper> _pool = new ObjectPool<ResidualWrapper>(New, Clear);
private IList<double> _list;
public const int RESIDUAL_WRAPPER_LEN = 15;
private ResidualWrapper()
{
_list = null!;
}
private static ResidualWrapper New()
{
return new ResidualWrapper();
}
// r0 constraint
public V3 R
{
set
{
this[0] = value[0];
this[1] = value[1];
this[2] = value[2];
}
}
// v0 constraint
public V3 V
{
set
{
this[3] = value[0];
this[4] = value[1];
this[5] = value[2];
}
}
// m0 constraint
public double M
{
set => this[6] = value;
}
public (double a, double b, double c, double d, double e, double f) Terminal
{
set
{
this[7] = value.a;
this[8] = value.b;
this[9] = value.c;
this[10] = value.d;
this[11] = value.e;
this[12] = value.f;
}
}
public double Bt
{
set => this[13] = value;
}
public double Pm_transversality
{
set => this[14] = value;
}
public V3 RContinuity
{
set
{
this[0] = value[0];
this[1] = value[1];
this[2] = value[2];
}
}
public V3 VContinuity
{
set
{
this[3] = value[0];
this[4] = value[1];
this[5] = value[2];
}
}
public V3 PvContinuity
{
set
{
this[6] = value[0];
this[7] = value[1];
this[8] = value[2];
}
}
public V3 PrContinuity
{
set
{
this[9] = value[0];
this[10] = value[1];
this[11] = value[2];
}
}
public double M_continuity
{
set => this[12] = value;
}
public double Pm_continuity
{
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 < RESIDUAL_WRAPPER_LEN; i++)
other[i] = this[i];
}
public static ResidualWrapper Rent(IList<double> list)
{
Check.True(list.Count >= RESIDUAL_WRAPPER_LEN);
ResidualWrapper wrapper = _pool.Borrow();
wrapper._list = list;
return wrapper;
}
public void Dispose()
{
_pool.Release(this);
}
public static void Clear(ResidualWrapper obj)
{
}
}
}