laymur 0.1.73 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/Passes/UIPass.d.ts +2 -2
- package/dist/{Builders → builders}/UIConstraint2DBuilder.d.ts +14 -14
- package/dist/{Builders → builders}/UIConstraintContainerBuilder.d.ts +5 -5
- package/dist/{Builders → builders}/UIConstraintStackBuilder.d.ts +7 -7
- package/dist/{Constraints → constraints}/UIAspectConstraint.d.ts +5 -5
- package/dist/{Constraints → constraints}/UIConstraint.d.ts +3 -3
- package/dist/{Constraints → constraints}/UIConstraintRule.d.ts +1 -1
- package/dist/{Constraints → constraints}/UICoverConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIFitConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIHeightConstraint.d.ts +2 -2
- package/dist/{Constraints → constraints}/UIHorizontalDistanceConstraint.d.ts +7 -7
- package/dist/{Constraints → constraints}/UIHorizontalProportionConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIVerticalDistanceConstraint.d.ts +7 -7
- package/dist/{Constraints → constraints}/UIVerticalProportionConstraint.d.ts +6 -6
- package/dist/{Constraints → constraints}/UIWidthConstraint.d.ts +2 -2
- package/dist/{Elements → elements}/UIAnchor.d.ts +5 -6
- package/dist/{Elements → elements}/UIDummy.d.ts +1 -1
- package/dist/{Elements → elements}/UIElement.d.ts +9 -10
- package/dist/{Elements → elements}/UIImage.d.ts +2 -2
- package/dist/{Elements → elements}/UIProgress.d.ts +1 -1
- package/dist/{Elements → elements}/UIScene.d.ts +1 -1
- package/dist/{Elements → elements}/UIText.d.ts +4 -4
- package/dist/index.d.ts +28 -29
- package/dist/index.js +782 -862
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/{Layers → layers}/UILayer.d.ts +20 -21
- package/dist/{Materials → materials}/UIMaterial.d.ts +1 -1
- package/dist/{Miscellaneous → miscellaneous}/UIMicro.d.ts +1 -1
- package/dist/{Miscellaneous → miscellaneous}/asserts.d.ts +3 -3
- package/package.json +3 -3
- package/dist/Miscellaneous/symbols.d.ts +0 -1
- /package/dist/{Constraints → constraints}/UIConstraintPower.d.ts +0 -0
- /package/dist/{Layers → layers}/UIFullScreenLayer.d.ts +0 -0
- /package/dist/{Materials → materials}/UIProgressMaterial.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UIBlending.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UIMode.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UIOrientation.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/UITextInterfaces.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/math.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/microTransformationTools.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/textTools.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/threeInstances.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,57 +1,48 @@
|
|
|
1
1
|
import { MathUtils, Vector2, Box2, Matrix3, Vector3, ShaderMaterial, Color, AddEquation, SrcAlphaFactor, OneMinusSrcAlphaFactor, NormalBlending, CustomBlending, OneMinusDstColorFactor, OneFactor, MultiplyBlending, SubtractiveBlending, AdditiveBlending, PlaneGeometry, Scene, Mesh, OrthographicCamera, WebGLRenderTarget, UnsignedByteType, LinearFilter, RGBAFormat, NoBlending, Object3D, UniformsUtils, PerspectiveCamera, CanvasTexture } from 'three';
|
|
2
2
|
|
|
3
|
-
/*-----------------------------------------------------------------------------
|
|
4
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
5
|
-
|
|
|
6
|
-
| Distributed under the terms of the Modified BSD License.
|
|
7
|
-
|
|
|
8
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
9
|
-
|----------------------------------------------------------------------------*/
|
|
10
3
|
function createMap() {
|
|
11
4
|
return new IndexedMap();
|
|
12
5
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.array = [];
|
|
17
|
-
}
|
|
6
|
+
class IndexedMap {
|
|
7
|
+
index = {};
|
|
8
|
+
array = [];
|
|
18
9
|
/**
|
|
19
10
|
* Returns the number of items in the array.
|
|
20
11
|
*/
|
|
21
|
-
|
|
12
|
+
size() {
|
|
22
13
|
return this.array.length;
|
|
23
|
-
}
|
|
14
|
+
}
|
|
24
15
|
/**
|
|
25
16
|
* Returns true if the array is empty.
|
|
26
17
|
*/
|
|
27
|
-
|
|
18
|
+
empty() {
|
|
28
19
|
return this.array.length === 0;
|
|
29
|
-
}
|
|
20
|
+
}
|
|
30
21
|
/**
|
|
31
22
|
* Returns the item at the given array index.
|
|
32
23
|
*
|
|
33
24
|
* @param index The integer index of the desired item.
|
|
34
25
|
*/
|
|
35
|
-
|
|
26
|
+
itemAt(index) {
|
|
36
27
|
return this.array[index];
|
|
37
|
-
}
|
|
28
|
+
}
|
|
38
29
|
/**
|
|
39
30
|
* Returns true if the key is in the array, false otherwise.
|
|
40
31
|
*
|
|
41
32
|
* @param key The key to locate in the array.
|
|
42
33
|
*/
|
|
43
|
-
|
|
34
|
+
contains(key) {
|
|
44
35
|
return this.index[key.id()] !== undefined;
|
|
45
|
-
}
|
|
36
|
+
}
|
|
46
37
|
/**
|
|
47
38
|
* Returns the pair associated with the given key, or undefined.
|
|
48
39
|
*
|
|
49
40
|
* @param key The key to locate in the array.
|
|
50
41
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
find(key) {
|
|
43
|
+
const i = this.index[key.id()];
|
|
53
44
|
return i === undefined ? undefined : this.array[i];
|
|
54
|
-
}
|
|
45
|
+
}
|
|
55
46
|
/**
|
|
56
47
|
* Returns the pair associated with the key if it exists.
|
|
57
48
|
*
|
|
@@ -61,10 +52,10 @@ var IndexedMap = /** @class */ (function () {
|
|
|
61
52
|
* @param key The key to locate in the array.
|
|
62
53
|
* @param factory The function which creates the default value.
|
|
63
54
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
setDefault(key, factory) {
|
|
56
|
+
const i = this.index[key.id()];
|
|
66
57
|
if (i === undefined) {
|
|
67
|
-
|
|
58
|
+
const pair = new Pair(key, factory());
|
|
68
59
|
this.index[key.id()] = this.array.length;
|
|
69
60
|
this.array.push(pair);
|
|
70
61
|
return pair;
|
|
@@ -72,7 +63,7 @@ var IndexedMap = /** @class */ (function () {
|
|
|
72
63
|
else {
|
|
73
64
|
return this.array[i];
|
|
74
65
|
}
|
|
75
|
-
}
|
|
66
|
+
}
|
|
76
67
|
/**
|
|
77
68
|
* Insert the pair into the array and return the pair.
|
|
78
69
|
*
|
|
@@ -81,9 +72,9 @@ var IndexedMap = /** @class */ (function () {
|
|
|
81
72
|
* @param key The key portion of the pair.
|
|
82
73
|
* @param value The value portion of the pair.
|
|
83
74
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
insert(key, value) {
|
|
76
|
+
const pair = new Pair(key, value);
|
|
77
|
+
const i = this.index[key.id()];
|
|
87
78
|
if (i === undefined) {
|
|
88
79
|
this.index[key.id()] = this.array.length;
|
|
89
80
|
this.array.push(pair);
|
|
@@ -92,136 +83,127 @@ var IndexedMap = /** @class */ (function () {
|
|
|
92
83
|
this.array[i] = pair;
|
|
93
84
|
}
|
|
94
85
|
return pair;
|
|
95
|
-
}
|
|
86
|
+
}
|
|
96
87
|
/**
|
|
97
88
|
* Removes and returns the pair for the given key, or undefined.
|
|
98
89
|
*
|
|
99
90
|
* @param key The key to remove from the map.
|
|
100
91
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
erase(key) {
|
|
93
|
+
const i = this.index[key.id()];
|
|
103
94
|
if (i === undefined) {
|
|
104
95
|
return undefined;
|
|
105
96
|
}
|
|
106
97
|
this.index[key.id()] = undefined;
|
|
107
|
-
|
|
108
|
-
|
|
98
|
+
const pair = this.array[i];
|
|
99
|
+
const last = this.array.pop();
|
|
109
100
|
if (pair !== last) {
|
|
110
101
|
this.array[i] = last;
|
|
111
102
|
this.index[last.first.id()] = i;
|
|
112
103
|
}
|
|
113
104
|
return pair;
|
|
114
|
-
}
|
|
105
|
+
}
|
|
115
106
|
/**
|
|
116
107
|
* Create a copy of this associative array.
|
|
117
108
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
for (
|
|
121
|
-
|
|
109
|
+
copy() {
|
|
110
|
+
const copy = new IndexedMap();
|
|
111
|
+
for (let i = 0; i < this.array.length; i++) {
|
|
112
|
+
const pair = this.array[i].copy();
|
|
122
113
|
copy.array[i] = pair;
|
|
123
114
|
copy.index[pair.first.id()] = i;
|
|
124
115
|
}
|
|
125
116
|
return copy;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
129
119
|
/**
|
|
130
120
|
* A class which defines a generic pair object.
|
|
131
121
|
* @private
|
|
132
122
|
*/
|
|
133
123
|
// tslint:disable: max-classes-per-file
|
|
134
|
-
|
|
124
|
+
class Pair {
|
|
125
|
+
first;
|
|
126
|
+
second;
|
|
135
127
|
/**
|
|
136
128
|
* Construct a new Pair object.
|
|
137
129
|
*
|
|
138
130
|
* @param first The first item of the pair.
|
|
139
131
|
* @param second The second item of the pair.
|
|
140
132
|
*/
|
|
141
|
-
|
|
133
|
+
constructor(first, second) {
|
|
142
134
|
this.first = first;
|
|
143
135
|
this.second = second;
|
|
144
136
|
}
|
|
145
137
|
/**
|
|
146
138
|
* Create a copy of the pair.
|
|
147
139
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
140
|
+
copy() {
|
|
141
|
+
return new Pair(this.first, this.second);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
151
144
|
|
|
152
|
-
/*-----------------------------------------------------------------------------
|
|
153
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
154
|
-
|
|
|
155
|
-
| Distributed under the terms of the Modified BSD License.
|
|
156
|
-
|
|
|
157
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
158
|
-
|----------------------------------------------------------------------------*/
|
|
159
145
|
/**
|
|
160
146
|
* The primary user constraint variable.
|
|
161
147
|
*
|
|
162
148
|
* @class
|
|
163
149
|
* @param {String} [name=""] The name to associated with the variable.
|
|
164
150
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (name === void 0) { name = ""; }
|
|
168
|
-
this._value = 0.0;
|
|
169
|
-
this._context = null;
|
|
170
|
-
this._id = VarId++;
|
|
151
|
+
class Variable {
|
|
152
|
+
constructor(name = '') {
|
|
171
153
|
this._name = name;
|
|
172
154
|
}
|
|
173
155
|
/**
|
|
174
156
|
* Returns the unique id number of the variable.
|
|
175
157
|
* @private
|
|
176
158
|
*/
|
|
177
|
-
|
|
159
|
+
id() {
|
|
178
160
|
return this._id;
|
|
179
|
-
}
|
|
161
|
+
}
|
|
180
162
|
/**
|
|
181
163
|
* Returns the name of the variable.
|
|
182
164
|
*
|
|
183
165
|
* @return {String} name of the variable
|
|
184
166
|
*/
|
|
185
|
-
|
|
167
|
+
name() {
|
|
186
168
|
return this._name;
|
|
187
|
-
}
|
|
169
|
+
}
|
|
188
170
|
/**
|
|
189
171
|
* Set the name of the variable.
|
|
190
172
|
*
|
|
191
173
|
* @param {String} name Name of the variable
|
|
192
174
|
*/
|
|
193
|
-
|
|
175
|
+
setName(name) {
|
|
194
176
|
this._name = name;
|
|
195
|
-
}
|
|
177
|
+
}
|
|
196
178
|
/**
|
|
197
179
|
* Returns the user context object of the variable.
|
|
198
180
|
* @private
|
|
199
181
|
*/
|
|
200
|
-
|
|
182
|
+
context() {
|
|
201
183
|
return this._context;
|
|
202
|
-
}
|
|
184
|
+
}
|
|
203
185
|
/**
|
|
204
186
|
* Set the user context object of the variable.
|
|
205
187
|
* @private
|
|
206
188
|
*/
|
|
207
|
-
|
|
189
|
+
setContext(context) {
|
|
208
190
|
this._context = context;
|
|
209
|
-
}
|
|
191
|
+
}
|
|
210
192
|
/**
|
|
211
193
|
* Returns the value of the variable.
|
|
212
194
|
*
|
|
213
195
|
* @return {Number} Calculated value
|
|
214
196
|
*/
|
|
215
|
-
|
|
197
|
+
value() {
|
|
216
198
|
return this._value;
|
|
217
|
-
}
|
|
199
|
+
}
|
|
218
200
|
/**
|
|
219
201
|
* Set the value of the variable.
|
|
220
202
|
* @private
|
|
221
203
|
*/
|
|
222
|
-
|
|
204
|
+
setValue(value) {
|
|
223
205
|
this._value = value;
|
|
224
|
-
}
|
|
206
|
+
}
|
|
225
207
|
/**
|
|
226
208
|
* Creates a new Expression by adding a number, variable or expression
|
|
227
209
|
* to the variable.
|
|
@@ -229,9 +211,9 @@ var Variable = /** @class */ (function () {
|
|
|
229
211
|
* @param {Number|Variable|Expression} value Value to add.
|
|
230
212
|
* @return {Expression} expression
|
|
231
213
|
*/
|
|
232
|
-
|
|
214
|
+
plus(value) {
|
|
233
215
|
return new Expression(this, value);
|
|
234
|
-
}
|
|
216
|
+
}
|
|
235
217
|
/**
|
|
236
218
|
* Creates a new Expression by substracting a number, variable or expression
|
|
237
219
|
* from the variable.
|
|
@@ -239,55 +221,51 @@ var Variable = /** @class */ (function () {
|
|
|
239
221
|
* @param {Number|Variable|Expression} value Value to substract.
|
|
240
222
|
* @return {Expression} expression
|
|
241
223
|
*/
|
|
242
|
-
|
|
243
|
-
return new Expression(this, typeof value ===
|
|
244
|
-
}
|
|
224
|
+
minus(value) {
|
|
225
|
+
return new Expression(this, typeof value === 'number' ? -value : [-1, value]);
|
|
226
|
+
}
|
|
245
227
|
/**
|
|
246
228
|
* Creates a new Expression by multiplying with a fixed number.
|
|
247
229
|
*
|
|
248
230
|
* @param {Number} coefficient Coefficient to multiply with.
|
|
249
231
|
* @return {Expression} expression
|
|
250
232
|
*/
|
|
251
|
-
|
|
233
|
+
multiply(coefficient) {
|
|
252
234
|
return new Expression([coefficient, this]);
|
|
253
|
-
}
|
|
235
|
+
}
|
|
254
236
|
/**
|
|
255
237
|
* Creates a new Expression by dividing with a fixed number.
|
|
256
238
|
*
|
|
257
239
|
* @param {Number} coefficient Coefficient to divide by.
|
|
258
240
|
* @return {Expression} expression
|
|
259
241
|
*/
|
|
260
|
-
|
|
242
|
+
divide(coefficient) {
|
|
261
243
|
return new Expression([1 / coefficient, this]);
|
|
262
|
-
}
|
|
244
|
+
}
|
|
263
245
|
/**
|
|
264
246
|
* Returns the JSON representation of the variable.
|
|
265
247
|
* @private
|
|
266
248
|
*/
|
|
267
|
-
|
|
249
|
+
toJSON() {
|
|
268
250
|
return {
|
|
269
251
|
name: this._name,
|
|
270
252
|
value: this._value,
|
|
271
253
|
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return this._context +
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
254
|
+
}
|
|
255
|
+
toString() {
|
|
256
|
+
return this._context + '[' + this._name + ':' + this._value + ']';
|
|
257
|
+
}
|
|
258
|
+
_name;
|
|
259
|
+
_value = 0.0;
|
|
260
|
+
_context = null;
|
|
261
|
+
_id = VarId++;
|
|
262
|
+
}
|
|
278
263
|
/**
|
|
279
264
|
* The internal variable id counter.
|
|
280
265
|
* @private
|
|
281
266
|
*/
|
|
282
|
-
|
|
267
|
+
let VarId = 0;
|
|
283
268
|
|
|
284
|
-
/*-----------------------------------------------------------------------------
|
|
285
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
286
|
-
|
|
|
287
|
-
| Distributed under the terms of the Modified BSD License.
|
|
288
|
-
|
|
|
289
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
290
|
-
|----------------------------------------------------------------------------*/
|
|
291
269
|
/**
|
|
292
270
|
* An expression of variable terms and a constant.
|
|
293
271
|
*
|
|
@@ -303,9 +281,9 @@ var VarId = 0;
|
|
|
303
281
|
* @class
|
|
304
282
|
* @param {...(number|Variable|Expression|Array)} args
|
|
305
283
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
284
|
+
class Expression {
|
|
285
|
+
constructor() {
|
|
286
|
+
let parsed = parseArgs(arguments);
|
|
309
287
|
this._terms = parsed.terms;
|
|
310
288
|
this._constant = parsed.constant;
|
|
311
289
|
}
|
|
@@ -315,30 +293,30 @@ var Expression = /** @class */ (function () {
|
|
|
315
293
|
* This *must* be treated as const.
|
|
316
294
|
* @private
|
|
317
295
|
*/
|
|
318
|
-
|
|
296
|
+
terms() {
|
|
319
297
|
return this._terms;
|
|
320
|
-
}
|
|
298
|
+
}
|
|
321
299
|
/**
|
|
322
300
|
* Returns the constant of the expression.
|
|
323
301
|
* @private
|
|
324
302
|
*/
|
|
325
|
-
|
|
303
|
+
constant() {
|
|
326
304
|
return this._constant;
|
|
327
|
-
}
|
|
305
|
+
}
|
|
328
306
|
/**
|
|
329
307
|
* Returns the computed value of the expression.
|
|
330
308
|
*
|
|
331
309
|
* @private
|
|
332
310
|
* @return {Number} computed value of the expression
|
|
333
311
|
*/
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
for (
|
|
337
|
-
|
|
312
|
+
value() {
|
|
313
|
+
let result = this._constant;
|
|
314
|
+
for (let i = 0, n = this._terms.size(); i < n; i++) {
|
|
315
|
+
let pair = this._terms.itemAt(i);
|
|
338
316
|
result += pair.first.value() * pair.second;
|
|
339
317
|
}
|
|
340
318
|
return result;
|
|
341
|
-
}
|
|
319
|
+
}
|
|
342
320
|
/**
|
|
343
321
|
* Creates a new Expression by adding a number, variable or expression
|
|
344
322
|
* to the expression.
|
|
@@ -346,9 +324,9 @@ var Expression = /** @class */ (function () {
|
|
|
346
324
|
* @param {Number|Variable|Expression} value Value to add.
|
|
347
325
|
* @return {Expression} expression
|
|
348
326
|
*/
|
|
349
|
-
|
|
327
|
+
plus(value) {
|
|
350
328
|
return new Expression(this, value);
|
|
351
|
-
}
|
|
329
|
+
}
|
|
352
330
|
/**
|
|
353
331
|
* Creates a new Expression by substracting a number, variable or expression
|
|
354
332
|
* from the expression.
|
|
@@ -356,53 +334,56 @@ var Expression = /** @class */ (function () {
|
|
|
356
334
|
* @param {Number|Variable|Expression} value Value to substract.
|
|
357
335
|
* @return {Expression} expression
|
|
358
336
|
*/
|
|
359
|
-
|
|
360
|
-
return new Expression(this, typeof value ===
|
|
361
|
-
}
|
|
337
|
+
minus(value) {
|
|
338
|
+
return new Expression(this, typeof value === 'number' ? -value : [-1, value]);
|
|
339
|
+
}
|
|
362
340
|
/**
|
|
363
341
|
* Creates a new Expression by multiplying with a fixed number.
|
|
364
342
|
*
|
|
365
343
|
* @param {Number} coefficient Coefficient to multiply with.
|
|
366
344
|
* @return {Expression} expression
|
|
367
345
|
*/
|
|
368
|
-
|
|
346
|
+
multiply(coefficient) {
|
|
369
347
|
return new Expression([coefficient, this]);
|
|
370
|
-
}
|
|
348
|
+
}
|
|
371
349
|
/**
|
|
372
350
|
* Creates a new Expression by dividing with a fixed number.
|
|
373
351
|
*
|
|
374
352
|
* @param {Number} coefficient Coefficient to divide by.
|
|
375
353
|
* @return {Expression} expression
|
|
376
354
|
*/
|
|
377
|
-
|
|
355
|
+
divide(coefficient) {
|
|
378
356
|
return new Expression([1 / coefficient, this]);
|
|
379
|
-
}
|
|
380
|
-
|
|
357
|
+
}
|
|
358
|
+
isConstant() {
|
|
381
359
|
return this._terms.size() == 0;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
360
|
+
}
|
|
361
|
+
toString() {
|
|
362
|
+
let result = this._terms.array
|
|
363
|
+
.map(function (pair) {
|
|
364
|
+
return pair.second + '*' + pair.first.toString();
|
|
365
|
+
})
|
|
366
|
+
.join(' + ');
|
|
387
367
|
if (!this.isConstant() && this._constant !== 0) {
|
|
388
|
-
result +=
|
|
368
|
+
result += ' + ';
|
|
389
369
|
}
|
|
390
370
|
result += this._constant;
|
|
391
371
|
return result;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
372
|
+
}
|
|
373
|
+
_terms;
|
|
374
|
+
_constant;
|
|
375
|
+
}
|
|
395
376
|
/**
|
|
396
377
|
* An internal argument parsing function.
|
|
397
378
|
* @private
|
|
398
379
|
*/
|
|
399
380
|
function parseArgs(args) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
for (
|
|
404
|
-
|
|
405
|
-
if (typeof item ===
|
|
381
|
+
let constant = 0.0;
|
|
382
|
+
let factory = () => 0.0;
|
|
383
|
+
let terms = createMap();
|
|
384
|
+
for (let i = 0, n = args.length; i < n; ++i) {
|
|
385
|
+
let item = args[i];
|
|
386
|
+
if (typeof item === 'number') {
|
|
406
387
|
constant += item;
|
|
407
388
|
}
|
|
408
389
|
else if (item instanceof Variable) {
|
|
@@ -410,56 +391,47 @@ function parseArgs(args) {
|
|
|
410
391
|
}
|
|
411
392
|
else if (item instanceof Expression) {
|
|
412
393
|
constant += item.constant();
|
|
413
|
-
|
|
414
|
-
for (
|
|
415
|
-
|
|
394
|
+
let terms2 = item.terms();
|
|
395
|
+
for (let j = 0, k = terms2.size(); j < k; j++) {
|
|
396
|
+
let termPair = terms2.itemAt(j);
|
|
416
397
|
terms.setDefault(termPair.first, factory).second += termPair.second;
|
|
417
398
|
}
|
|
418
399
|
}
|
|
419
400
|
else if (item instanceof Array) {
|
|
420
401
|
if (item.length !== 2) {
|
|
421
|
-
throw new Error(
|
|
402
|
+
throw new Error('array must have length 2');
|
|
422
403
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (typeof value !==
|
|
426
|
-
throw new Error(
|
|
404
|
+
let value = item[0];
|
|
405
|
+
let value2 = item[1];
|
|
406
|
+
if (typeof value !== 'number') {
|
|
407
|
+
throw new Error('array item 0 must be a number');
|
|
427
408
|
}
|
|
428
409
|
if (value2 instanceof Variable) {
|
|
429
410
|
terms.setDefault(value2, factory).second += value;
|
|
430
411
|
}
|
|
431
412
|
else if (value2 instanceof Expression) {
|
|
432
|
-
constant +=
|
|
433
|
-
|
|
434
|
-
for (
|
|
435
|
-
|
|
436
|
-
terms.setDefault(termPair.first, factory).second +=
|
|
413
|
+
constant += value2.constant() * value;
|
|
414
|
+
let terms2 = value2.terms();
|
|
415
|
+
for (let j = 0, k = terms2.size(); j < k; j++) {
|
|
416
|
+
let termPair = terms2.itemAt(j);
|
|
417
|
+
terms.setDefault(termPair.first, factory).second += termPair.second * value;
|
|
437
418
|
}
|
|
438
419
|
}
|
|
439
420
|
else {
|
|
440
|
-
throw new Error(
|
|
421
|
+
throw new Error('array item 1 must be a variable or expression');
|
|
441
422
|
}
|
|
442
423
|
}
|
|
443
424
|
else {
|
|
444
|
-
throw new Error(
|
|
425
|
+
throw new Error('invalid Expression argument: ' + item);
|
|
445
426
|
}
|
|
446
427
|
}
|
|
447
|
-
return { terms
|
|
428
|
+
return { terms, constant };
|
|
448
429
|
}
|
|
449
430
|
|
|
450
|
-
/*-----------------------------------------------------------------------------
|
|
451
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
452
|
-
|
|
|
453
|
-
| Distributed under the terms of the Modified BSD License.
|
|
454
|
-
|
|
|
455
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
456
|
-
|----------------------------------------------------------------------------*/
|
|
457
431
|
/**
|
|
458
432
|
* @class Strength
|
|
459
433
|
*/
|
|
460
|
-
|
|
461
|
-
function Strength() {
|
|
462
|
-
}
|
|
434
|
+
class Strength {
|
|
463
435
|
/**
|
|
464
436
|
* Create a new symbolic strength.
|
|
465
437
|
*
|
|
@@ -468,48 +440,39 @@ var Strength = /** @class */ (function () {
|
|
|
468
440
|
* @param c weak
|
|
469
441
|
* @param [w] weight
|
|
470
442
|
* @return strength
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
var result = 0.0;
|
|
443
|
+
*/
|
|
444
|
+
static create(a, b, c, w = 1.0) {
|
|
445
|
+
let result = 0.0;
|
|
475
446
|
result += Math.max(0.0, Math.min(1000.0, a * w)) * 1000000.0;
|
|
476
447
|
result += Math.max(0.0, Math.min(1000.0, b * w)) * 1000.0;
|
|
477
448
|
result += Math.max(0.0, Math.min(1000.0, c * w));
|
|
478
449
|
return result;
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Clip a symbolic strength to the allowed min and max.
|
|
482
|
-
* @private
|
|
483
|
-
*/
|
|
484
|
-
Strength.clip = function (value) {
|
|
485
|
-
return Math.max(0.0, Math.min(Strength.required, value));
|
|
486
|
-
};
|
|
450
|
+
}
|
|
487
451
|
/**
|
|
488
452
|
* The 'required' symbolic strength.
|
|
489
453
|
*/
|
|
490
|
-
|
|
454
|
+
static required = Strength.create(1000.0, 1000.0, 1000.0);
|
|
491
455
|
/**
|
|
492
456
|
* The 'strong' symbolic strength.
|
|
493
457
|
*/
|
|
494
|
-
|
|
458
|
+
static strong = Strength.create(1.0, 0.0, 0.0);
|
|
495
459
|
/**
|
|
496
460
|
* The 'medium' symbolic strength.
|
|
497
461
|
*/
|
|
498
|
-
|
|
462
|
+
static medium = Strength.create(0.0, 1.0, 0.0);
|
|
499
463
|
/**
|
|
500
464
|
* The 'weak' symbolic strength.
|
|
501
465
|
*/
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
466
|
+
static weak = Strength.create(0.0, 0.0, 1.0);
|
|
467
|
+
/**
|
|
468
|
+
* Clip a symbolic strength to the allowed min and max.
|
|
469
|
+
* @private
|
|
470
|
+
*/
|
|
471
|
+
static clip(value) {
|
|
472
|
+
return Math.max(0.0, Math.min(Strength.required, value));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
505
475
|
|
|
506
|
-
/*-----------------------------------------------------------------------------
|
|
507
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
508
|
-
|
|
|
509
|
-
| Distributed under the terms of the Modified BSD License.
|
|
510
|
-
|
|
|
511
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
512
|
-
|----------------------------------------------------------------------------*/
|
|
513
476
|
/**
|
|
514
477
|
* An enum defining the linear constraint operators.
|
|
515
478
|
*
|
|
@@ -539,13 +502,11 @@ var Operator;
|
|
|
539
502
|
* @param {Expression} [rhs] Right hand side of the expression.
|
|
540
503
|
* @param {Number} [strength=Strength.required] The strength of the constraint.
|
|
541
504
|
*/
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (strength === void 0) { strength = Strength.required; }
|
|
545
|
-
this._id = CnId++;
|
|
505
|
+
class Constraint {
|
|
506
|
+
constructor(expression, operator, rhs, strength = Strength.required) {
|
|
546
507
|
this._operator = operator;
|
|
547
508
|
this._strength = Strength.clip(strength);
|
|
548
|
-
if (
|
|
509
|
+
if (rhs === undefined && expression instanceof Expression) {
|
|
549
510
|
this._expression = expression;
|
|
550
511
|
}
|
|
551
512
|
else {
|
|
@@ -556,70 +517,62 @@ var Constraint = /** @class */ (function () {
|
|
|
556
517
|
* Returns the unique id number of the constraint.
|
|
557
518
|
* @private
|
|
558
519
|
*/
|
|
559
|
-
|
|
520
|
+
id() {
|
|
560
521
|
return this._id;
|
|
561
|
-
}
|
|
522
|
+
}
|
|
562
523
|
/**
|
|
563
524
|
* Returns the expression of the constraint.
|
|
564
525
|
*
|
|
565
526
|
* @return {Expression} expression
|
|
566
527
|
*/
|
|
567
|
-
|
|
528
|
+
expression() {
|
|
568
529
|
return this._expression;
|
|
569
|
-
}
|
|
530
|
+
}
|
|
570
531
|
/**
|
|
571
532
|
* Returns the relational operator of the constraint.
|
|
572
533
|
*
|
|
573
534
|
* @return {Operator} linear constraint operator
|
|
574
535
|
*/
|
|
575
|
-
|
|
536
|
+
op() {
|
|
576
537
|
return this._operator;
|
|
577
|
-
}
|
|
538
|
+
}
|
|
578
539
|
/**
|
|
579
540
|
* Returns the strength of the constraint.
|
|
580
541
|
*
|
|
581
542
|
* @return {Number} strength
|
|
582
543
|
*/
|
|
583
|
-
|
|
544
|
+
strength() {
|
|
584
545
|
return this._strength;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
return this._expression.toString() +
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
|
|
546
|
+
}
|
|
547
|
+
toString() {
|
|
548
|
+
return (this._expression.toString() + ' ' + ['<=', '>=', '='][this._operator] + ' 0 (' + this._strength.toString() + ')');
|
|
549
|
+
}
|
|
550
|
+
_expression;
|
|
551
|
+
_operator;
|
|
552
|
+
_strength;
|
|
553
|
+
_id = CnId++;
|
|
554
|
+
}
|
|
591
555
|
/**
|
|
592
556
|
* The internal constraint id counter.
|
|
593
557
|
* @private
|
|
594
558
|
*/
|
|
595
|
-
|
|
559
|
+
let CnId = 0;
|
|
596
560
|
|
|
597
|
-
/*-----------------------------------------------------------------------------
|
|
598
|
-
| Copyright (c) 2014, Nucleic Development Team.
|
|
599
|
-
|
|
|
600
|
-
| Distributed under the terms of the Modified BSD License.
|
|
601
|
-
|
|
|
602
|
-
| The full license is in the file COPYING.txt, distributed with this software.
|
|
603
|
-
|----------------------------------------------------------------------------*/
|
|
604
561
|
/**
|
|
605
562
|
* The constraint solver class.
|
|
606
563
|
*
|
|
607
564
|
* @class
|
|
608
565
|
*/
|
|
609
|
-
|
|
566
|
+
class Solver {
|
|
567
|
+
/**
|
|
568
|
+
* @type {number} - The max number of solver iterations before an error
|
|
569
|
+
* is thrown, in order to prevent infinite iteration. Default: `10,000`.
|
|
570
|
+
*/
|
|
571
|
+
maxIterations = 1000;
|
|
610
572
|
/**
|
|
611
573
|
* Construct a new Solver.
|
|
612
574
|
*/
|
|
613
|
-
|
|
614
|
-
this._cnMap = createCnMap();
|
|
615
|
-
this._rowMap = createRowMap();
|
|
616
|
-
this._varMap = createVarMap();
|
|
617
|
-
this._editMap = createEditMap();
|
|
618
|
-
this._infeasibleRows = [];
|
|
619
|
-
this._objective = new Row();
|
|
620
|
-
this._artificial = null;
|
|
621
|
-
this._idTick = 0;
|
|
622
|
-
}
|
|
575
|
+
constructor() { }
|
|
623
576
|
/**
|
|
624
577
|
* Creates and add a constraint to the solver.
|
|
625
578
|
*
|
|
@@ -628,21 +581,20 @@ var Solver = /** @class */ (function () {
|
|
|
628
581
|
* @param {Expression|Variable|Number} rhs Right hand side of the expression
|
|
629
582
|
* @param {Number} [strength=Strength.required] Strength
|
|
630
583
|
*/
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
var cn = new Constraint(lhs, operator, rhs, strength);
|
|
584
|
+
createConstraint(lhs, operator, rhs, strength = Strength.required) {
|
|
585
|
+
let cn = new Constraint(lhs, operator, rhs, strength);
|
|
634
586
|
this.addConstraint(cn);
|
|
635
587
|
return cn;
|
|
636
|
-
}
|
|
588
|
+
}
|
|
637
589
|
/**
|
|
638
590
|
* Add a constraint to the solver.
|
|
639
591
|
*
|
|
640
592
|
* @param {Constraint} constraint Constraint to add to the solver
|
|
641
593
|
*/
|
|
642
|
-
|
|
643
|
-
|
|
594
|
+
addConstraint(constraint) {
|
|
595
|
+
let cnPair = this._cnMap.find(constraint);
|
|
644
596
|
if (cnPair !== undefined) {
|
|
645
|
-
throw new Error(
|
|
597
|
+
throw new Error('duplicate constraint');
|
|
646
598
|
}
|
|
647
599
|
// Creating a row causes symbols to be reserved for the variables
|
|
648
600
|
// in the constraint. If this method exits with an exception,
|
|
@@ -650,10 +602,10 @@ var Solver = /** @class */ (function () {
|
|
|
650
602
|
// Since its likely that those variables will be used in other
|
|
651
603
|
// constraints and since exceptional conditions are uncommon,
|
|
652
604
|
// i'm not too worried about aggressive cleanup of the var map.
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
605
|
+
let data = this._createRow(constraint);
|
|
606
|
+
let row = data.row;
|
|
607
|
+
let tag = data.tag;
|
|
608
|
+
let subject = this._chooseSubject(row, tag);
|
|
657
609
|
// If chooseSubject couldnt find a valid entering symbol, one
|
|
658
610
|
// last option is available if the entire row is composed of
|
|
659
611
|
// dummy variables. If the constant of the row is zero, then
|
|
@@ -662,7 +614,7 @@ var Solver = /** @class */ (function () {
|
|
|
662
614
|
// then it represents an unsatisfiable constraint.
|
|
663
615
|
if (subject.type() === SymbolType.Invalid && row.allDummies()) {
|
|
664
616
|
if (!nearZero(row.constant())) {
|
|
665
|
-
throw new Error(
|
|
617
|
+
throw new Error('unsatisfiable constraint');
|
|
666
618
|
}
|
|
667
619
|
else {
|
|
668
620
|
subject = tag.marker;
|
|
@@ -673,7 +625,7 @@ var Solver = /** @class */ (function () {
|
|
|
673
625
|
// the row represents an unsatisfiable constraint.
|
|
674
626
|
if (subject.type() === SymbolType.Invalid) {
|
|
675
627
|
if (!this._addWithArtificialVariable(row)) {
|
|
676
|
-
throw new Error(
|
|
628
|
+
throw new Error('unsatisfiable constraint');
|
|
677
629
|
}
|
|
678
630
|
}
|
|
679
631
|
else {
|
|
@@ -686,16 +638,16 @@ var Solver = /** @class */ (function () {
|
|
|
686
638
|
// aggregate work due to a smaller average system size. It
|
|
687
639
|
// also ensures the solver remains in a consistent state.
|
|
688
640
|
this._optimize(this._objective);
|
|
689
|
-
}
|
|
641
|
+
}
|
|
690
642
|
/**
|
|
691
643
|
* Remove a constraint from the solver.
|
|
692
644
|
*
|
|
693
645
|
* @param {Constraint} constraint Constraint to remove from the solver
|
|
694
646
|
*/
|
|
695
|
-
|
|
696
|
-
|
|
647
|
+
removeConstraint(constraint) {
|
|
648
|
+
let cnPair = this._cnMap.erase(constraint);
|
|
697
649
|
if (cnPair === undefined) {
|
|
698
|
-
throw new Error(
|
|
650
|
+
throw new Error('unknown constraint');
|
|
699
651
|
}
|
|
700
652
|
// Remove the error effects from the objective function
|
|
701
653
|
// *before* pivoting, or substitutions into the objective
|
|
@@ -703,12 +655,12 @@ var Solver = /** @class */ (function () {
|
|
|
703
655
|
this._removeConstraintEffects(constraint, cnPair.second);
|
|
704
656
|
// If the marker is basic, simply drop the row. Otherwise,
|
|
705
657
|
// pivot the marker into the basis and then drop the row.
|
|
706
|
-
|
|
707
|
-
|
|
658
|
+
let marker = cnPair.second.marker;
|
|
659
|
+
let rowPair = this._rowMap.erase(marker);
|
|
708
660
|
if (rowPair === undefined) {
|
|
709
|
-
|
|
661
|
+
let leaving = this._getMarkerLeavingSymbol(marker);
|
|
710
662
|
if (leaving.type() === SymbolType.Invalid) {
|
|
711
|
-
throw new Error(
|
|
663
|
+
throw new Error('failed to find leaving row');
|
|
712
664
|
}
|
|
713
665
|
rowPair = this._rowMap.erase(leaving);
|
|
714
666
|
rowPair.second.solveForEx(leaving, marker);
|
|
@@ -718,77 +670,85 @@ var Solver = /** @class */ (function () {
|
|
|
718
670
|
// solver remains consistent. It makes the solver api easier to
|
|
719
671
|
// use at a small tradeoff for speed.
|
|
720
672
|
this._optimize(this._objective);
|
|
721
|
-
}
|
|
673
|
+
}
|
|
722
674
|
/**
|
|
723
675
|
* Test whether the solver contains the constraint.
|
|
724
676
|
*
|
|
725
677
|
* @param {Constraint} constraint Constraint to test for
|
|
726
678
|
* @return {Bool} true or false
|
|
727
679
|
*/
|
|
728
|
-
|
|
680
|
+
hasConstraint(constraint) {
|
|
729
681
|
return this._cnMap.contains(constraint);
|
|
730
|
-
}
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Get an array of the current constraints.
|
|
685
|
+
*
|
|
686
|
+
* @return {Constraint[]}
|
|
687
|
+
*/
|
|
688
|
+
getConstraints() {
|
|
689
|
+
return this._cnMap.array.map(({ first }) => first);
|
|
690
|
+
}
|
|
731
691
|
/**
|
|
732
692
|
* Add an edit variable to the solver.
|
|
733
693
|
*
|
|
734
694
|
* @param {Variable} variable Edit variable to add to the solver
|
|
735
695
|
* @param {Number} strength Strength, should be less than `Strength.required`
|
|
736
696
|
*/
|
|
737
|
-
|
|
738
|
-
|
|
697
|
+
addEditVariable(variable, strength) {
|
|
698
|
+
let editPair = this._editMap.find(variable);
|
|
739
699
|
if (editPair !== undefined) {
|
|
740
|
-
throw new Error(
|
|
700
|
+
throw new Error('duplicate edit variable');
|
|
741
701
|
}
|
|
742
702
|
strength = Strength.clip(strength);
|
|
743
703
|
if (strength === Strength.required) {
|
|
744
|
-
throw new Error(
|
|
704
|
+
throw new Error('bad required strength');
|
|
745
705
|
}
|
|
746
|
-
|
|
747
|
-
|
|
706
|
+
let expr = new Expression(variable);
|
|
707
|
+
let cn = new Constraint(expr, Operator.Eq, undefined, strength);
|
|
748
708
|
this.addConstraint(cn);
|
|
749
|
-
|
|
750
|
-
|
|
709
|
+
let tag = this._cnMap.find(cn).second;
|
|
710
|
+
let info = { tag, constraint: cn, constant: 0.0 };
|
|
751
711
|
this._editMap.insert(variable, info);
|
|
752
|
-
}
|
|
712
|
+
}
|
|
753
713
|
/**
|
|
754
714
|
* Remove an edit variable from the solver.
|
|
755
715
|
*
|
|
756
716
|
* @param {Variable} variable Edit variable to remove from the solver
|
|
757
717
|
*/
|
|
758
|
-
|
|
759
|
-
|
|
718
|
+
removeEditVariable(variable) {
|
|
719
|
+
let editPair = this._editMap.erase(variable);
|
|
760
720
|
if (editPair === undefined) {
|
|
761
|
-
throw new Error(
|
|
721
|
+
throw new Error('unknown edit variable');
|
|
762
722
|
}
|
|
763
723
|
this.removeConstraint(editPair.second.constraint);
|
|
764
|
-
}
|
|
724
|
+
}
|
|
765
725
|
/**
|
|
766
726
|
* Test whether the solver contains the edit variable.
|
|
767
727
|
*
|
|
768
728
|
* @param {Variable} variable Edit variable to test for
|
|
769
729
|
* @return {Bool} true or false
|
|
770
730
|
*/
|
|
771
|
-
|
|
731
|
+
hasEditVariable(variable) {
|
|
772
732
|
return this._editMap.contains(variable);
|
|
773
|
-
}
|
|
733
|
+
}
|
|
774
734
|
/**
|
|
775
735
|
* Suggest the value of an edit variable.
|
|
776
736
|
*
|
|
777
737
|
* @param {Variable} variable Edit variable to suggest a value for
|
|
778
738
|
* @param {Number} value Suggested value
|
|
779
739
|
*/
|
|
780
|
-
|
|
781
|
-
|
|
740
|
+
suggestValue(variable, value) {
|
|
741
|
+
let editPair = this._editMap.find(variable);
|
|
782
742
|
if (editPair === undefined) {
|
|
783
|
-
throw new Error(
|
|
743
|
+
throw new Error('unknown edit variable');
|
|
784
744
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
745
|
+
let rows = this._rowMap;
|
|
746
|
+
let info = editPair.second;
|
|
747
|
+
let delta = value - info.constant;
|
|
788
748
|
info.constant = value;
|
|
789
749
|
// Check first if the positive error variable is basic.
|
|
790
|
-
|
|
791
|
-
|
|
750
|
+
let marker = info.tag.marker;
|
|
751
|
+
let rowPair = rows.find(marker);
|
|
792
752
|
if (rowPair !== undefined) {
|
|
793
753
|
if (rowPair.second.add(-delta) < 0.0) {
|
|
794
754
|
this._infeasibleRows.push(marker);
|
|
@@ -797,7 +757,7 @@ var Solver = /** @class */ (function () {
|
|
|
797
757
|
return;
|
|
798
758
|
}
|
|
799
759
|
// Check next if the negative error variable is basic.
|
|
800
|
-
|
|
760
|
+
let other = info.tag.other;
|
|
801
761
|
rowPair = rows.find(other);
|
|
802
762
|
if (rowPair !== undefined) {
|
|
803
763
|
if (rowPair.second.add(delta) < 0.0) {
|
|
@@ -807,26 +767,25 @@ var Solver = /** @class */ (function () {
|
|
|
807
767
|
return;
|
|
808
768
|
}
|
|
809
769
|
// Otherwise update each row where the error variables exist.
|
|
810
|
-
for (
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
if (coeff !== 0.0 && row.add(delta * coeff) < 0.0 &&
|
|
815
|
-
|
|
816
|
-
this._infeasibleRows.push(rowPair_1.first);
|
|
770
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
771
|
+
let rowPair = rows.itemAt(i);
|
|
772
|
+
let row = rowPair.second;
|
|
773
|
+
let coeff = row.coefficientFor(marker);
|
|
774
|
+
if (coeff !== 0.0 && row.add(delta * coeff) < 0.0 && rowPair.first.type() !== SymbolType.External) {
|
|
775
|
+
this._infeasibleRows.push(rowPair.first);
|
|
817
776
|
}
|
|
818
777
|
}
|
|
819
778
|
this._dualOptimize();
|
|
820
|
-
}
|
|
779
|
+
}
|
|
821
780
|
/**
|
|
822
781
|
* Update the values of the variables.
|
|
823
782
|
*/
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
for (
|
|
828
|
-
|
|
829
|
-
|
|
783
|
+
updateVariables() {
|
|
784
|
+
let vars = this._varMap;
|
|
785
|
+
let rows = this._rowMap;
|
|
786
|
+
for (let i = 0, n = vars.size(); i < n; ++i) {
|
|
787
|
+
let pair = vars.itemAt(i);
|
|
788
|
+
let rowPair = rows.find(pair.second);
|
|
830
789
|
if (rowPair !== undefined) {
|
|
831
790
|
pair.first.setValue(rowPair.second.constant());
|
|
832
791
|
}
|
|
@@ -834,18 +793,17 @@ var Solver = /** @class */ (function () {
|
|
|
834
793
|
pair.first.setValue(0.0);
|
|
835
794
|
}
|
|
836
795
|
}
|
|
837
|
-
}
|
|
796
|
+
}
|
|
838
797
|
/**
|
|
839
798
|
* Get the symbol for the given variable.
|
|
840
799
|
*
|
|
841
800
|
* If a symbol does not exist for the variable, one will be created.
|
|
842
801
|
* @private
|
|
843
802
|
*/
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
var factory = function () { return _this._makeSymbol(SymbolType.External); };
|
|
803
|
+
_getVarSymbol(variable) {
|
|
804
|
+
let factory = () => this._makeSymbol(SymbolType.External);
|
|
847
805
|
return this._varMap.setDefault(variable, factory).second;
|
|
848
|
-
}
|
|
806
|
+
}
|
|
849
807
|
/**
|
|
850
808
|
* Create a new Row object for the given constraint.
|
|
851
809
|
*
|
|
@@ -863,16 +821,16 @@ var Solver = /** @class */ (function () {
|
|
|
863
821
|
* Returns the created Row and the tag for tracking the constraint.
|
|
864
822
|
* @private
|
|
865
823
|
*/
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
824
|
+
_createRow(constraint) {
|
|
825
|
+
let expr = constraint.expression();
|
|
826
|
+
let row = new Row(expr.constant());
|
|
869
827
|
// Substitute the current basic variables into the row.
|
|
870
|
-
|
|
871
|
-
for (
|
|
872
|
-
|
|
828
|
+
let terms = expr.terms();
|
|
829
|
+
for (let i = 0, n = terms.size(); i < n; ++i) {
|
|
830
|
+
let termPair = terms.itemAt(i);
|
|
873
831
|
if (!nearZero(termPair.second)) {
|
|
874
|
-
|
|
875
|
-
|
|
832
|
+
let symbol = this._getVarSymbol(termPair.first);
|
|
833
|
+
let basicPair = this._rowMap.find(symbol);
|
|
876
834
|
if (basicPair !== undefined) {
|
|
877
835
|
row.insertRow(basicPair.second, termPair.second);
|
|
878
836
|
}
|
|
@@ -882,51 +840,49 @@ var Solver = /** @class */ (function () {
|
|
|
882
840
|
}
|
|
883
841
|
}
|
|
884
842
|
// Add the necessary slack, error, and dummy variables.
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
843
|
+
let objective = this._objective;
|
|
844
|
+
let strength = constraint.strength();
|
|
845
|
+
let tag = { marker: INVALID_SYMBOL, other: INVALID_SYMBOL };
|
|
888
846
|
switch (constraint.op()) {
|
|
889
847
|
case Operator.Le:
|
|
890
|
-
case Operator.Ge:
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
objective.insertSymbol(error, strength);
|
|
901
|
-
}
|
|
902
|
-
break;
|
|
848
|
+
case Operator.Ge: {
|
|
849
|
+
let coeff = constraint.op() === Operator.Le ? 1.0 : -1;
|
|
850
|
+
let slack = this._makeSymbol(SymbolType.Slack);
|
|
851
|
+
tag.marker = slack;
|
|
852
|
+
row.insertSymbol(slack, coeff);
|
|
853
|
+
if (strength < Strength.required) {
|
|
854
|
+
let error = this._makeSymbol(SymbolType.Error);
|
|
855
|
+
tag.other = error;
|
|
856
|
+
row.insertSymbol(error, -coeff);
|
|
857
|
+
objective.insertSymbol(error, strength);
|
|
903
858
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
break;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
case Operator.Eq: {
|
|
862
|
+
if (strength < Strength.required) {
|
|
863
|
+
let errplus = this._makeSymbol(SymbolType.Error);
|
|
864
|
+
let errminus = this._makeSymbol(SymbolType.Error);
|
|
865
|
+
tag.marker = errplus;
|
|
866
|
+
tag.other = errminus;
|
|
867
|
+
row.insertSymbol(errplus, -1); // v = eplus - eminus
|
|
868
|
+
row.insertSymbol(errminus, 1.0); // v - eplus + eminus = 0
|
|
869
|
+
objective.insertSymbol(errplus, strength);
|
|
870
|
+
objective.insertSymbol(errminus, strength);
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
let dummy = this._makeSymbol(SymbolType.Dummy);
|
|
874
|
+
tag.marker = dummy;
|
|
875
|
+
row.insertSymbol(dummy);
|
|
922
876
|
}
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
923
879
|
}
|
|
924
880
|
// Ensure the row has a positive constant.
|
|
925
881
|
if (row.constant() < 0.0) {
|
|
926
882
|
row.reverseSign();
|
|
927
883
|
}
|
|
928
|
-
return { row
|
|
929
|
-
}
|
|
884
|
+
return { row, tag };
|
|
885
|
+
}
|
|
930
886
|
/**
|
|
931
887
|
* Choose the subject for solving for the row.
|
|
932
888
|
*
|
|
@@ -943,15 +899,15 @@ var Solver = /** @class */ (function () {
|
|
|
943
899
|
*
|
|
944
900
|
* @private
|
|
945
901
|
*/
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
for (
|
|
949
|
-
|
|
902
|
+
_chooseSubject(row, tag) {
|
|
903
|
+
let cells = row.cells();
|
|
904
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
905
|
+
let pair = cells.itemAt(i);
|
|
950
906
|
if (pair.first.type() === SymbolType.External) {
|
|
951
907
|
return pair.first;
|
|
952
908
|
}
|
|
953
909
|
}
|
|
954
|
-
|
|
910
|
+
let type = tag.marker.type();
|
|
955
911
|
if (type === SymbolType.Slack || type === SymbolType.Error) {
|
|
956
912
|
if (row.coefficientFor(tag.marker) < 0.0) {
|
|
957
913
|
return tag.marker;
|
|
@@ -964,7 +920,7 @@ var Solver = /** @class */ (function () {
|
|
|
964
920
|
}
|
|
965
921
|
}
|
|
966
922
|
return INVALID_SYMBOL;
|
|
967
|
-
}
|
|
923
|
+
}
|
|
968
924
|
/**
|
|
969
925
|
* Add the row to the tableau using an artificial variable.
|
|
970
926
|
*
|
|
@@ -972,25 +928,25 @@ var Solver = /** @class */ (function () {
|
|
|
972
928
|
*
|
|
973
929
|
* @private
|
|
974
930
|
*/
|
|
975
|
-
|
|
931
|
+
_addWithArtificialVariable(row) {
|
|
976
932
|
// Create and add the artificial variable to the tableau.
|
|
977
|
-
|
|
933
|
+
let art = this._makeSymbol(SymbolType.Slack);
|
|
978
934
|
this._rowMap.insert(art, row.copy());
|
|
979
935
|
this._artificial = row.copy();
|
|
980
936
|
// Optimize the artificial objective. This is successful
|
|
981
937
|
// only if the artificial objective is optimized to zero.
|
|
982
938
|
this._optimize(this._artificial);
|
|
983
|
-
|
|
939
|
+
let success = nearZero(this._artificial.constant());
|
|
984
940
|
this._artificial = null;
|
|
985
941
|
// If the artificial variable is basic, pivot the row so that
|
|
986
942
|
// it becomes non-basic. If the row is constant, exit early.
|
|
987
|
-
|
|
943
|
+
let pair = this._rowMap.erase(art);
|
|
988
944
|
if (pair !== undefined) {
|
|
989
|
-
|
|
945
|
+
let basicRow = pair.second;
|
|
990
946
|
if (basicRow.isConstant()) {
|
|
991
947
|
return success;
|
|
992
948
|
}
|
|
993
|
-
|
|
949
|
+
let entering = this._anyPivotableSymbol(basicRow);
|
|
994
950
|
if (entering.type() === SymbolType.Invalid) {
|
|
995
951
|
return false; // unsatisfiable (will this ever happen?)
|
|
996
952
|
}
|
|
@@ -999,13 +955,13 @@ var Solver = /** @class */ (function () {
|
|
|
999
955
|
this._rowMap.insert(entering, basicRow);
|
|
1000
956
|
}
|
|
1001
957
|
// Remove the artificial variable from the tableau.
|
|
1002
|
-
|
|
1003
|
-
for (
|
|
958
|
+
let rows = this._rowMap;
|
|
959
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
1004
960
|
rows.itemAt(i).second.removeSymbol(art);
|
|
1005
961
|
}
|
|
1006
962
|
this._objective.removeSymbol(art);
|
|
1007
963
|
return success;
|
|
1008
|
-
}
|
|
964
|
+
}
|
|
1009
965
|
/**
|
|
1010
966
|
* Substitute the parametric symbol with the given row.
|
|
1011
967
|
*
|
|
@@ -1014,13 +970,12 @@ var Solver = /** @class */ (function () {
|
|
|
1014
970
|
*
|
|
1015
971
|
* @private
|
|
1016
972
|
*/
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
for (
|
|
1020
|
-
|
|
973
|
+
_substitute(symbol, row) {
|
|
974
|
+
let rows = this._rowMap;
|
|
975
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
976
|
+
let pair = rows.itemAt(i);
|
|
1021
977
|
pair.second.substitute(symbol, row);
|
|
1022
|
-
if (pair.second.constant() < 0.0 &&
|
|
1023
|
-
pair.first.type() !== SymbolType.External) {
|
|
978
|
+
if (pair.second.constant() < 0.0 && pair.first.type() !== SymbolType.External) {
|
|
1024
979
|
this._infeasibleRows.push(pair.first);
|
|
1025
980
|
}
|
|
1026
981
|
}
|
|
@@ -1028,7 +983,7 @@ var Solver = /** @class */ (function () {
|
|
|
1028
983
|
if (this._artificial) {
|
|
1029
984
|
this._artificial.substitute(symbol, row);
|
|
1030
985
|
}
|
|
1031
|
-
}
|
|
986
|
+
}
|
|
1032
987
|
/**
|
|
1033
988
|
* Optimize the system for the given objective function.
|
|
1034
989
|
*
|
|
@@ -1037,23 +992,26 @@ var Solver = /** @class */ (function () {
|
|
|
1037
992
|
*
|
|
1038
993
|
* @private
|
|
1039
994
|
*/
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
995
|
+
_optimize(objective) {
|
|
996
|
+
let iterations = 0;
|
|
997
|
+
while (iterations < this.maxIterations) {
|
|
998
|
+
let entering = this._getEnteringSymbol(objective);
|
|
1043
999
|
if (entering.type() === SymbolType.Invalid) {
|
|
1044
1000
|
return;
|
|
1045
1001
|
}
|
|
1046
|
-
|
|
1002
|
+
let leaving = this._getLeavingSymbol(entering);
|
|
1047
1003
|
if (leaving.type() === SymbolType.Invalid) {
|
|
1048
|
-
throw new Error(
|
|
1004
|
+
throw new Error('the objective is unbounded');
|
|
1049
1005
|
}
|
|
1050
1006
|
// pivot the entering symbol into the basis
|
|
1051
|
-
|
|
1007
|
+
let row = this._rowMap.erase(leaving).second;
|
|
1052
1008
|
row.solveForEx(leaving, entering);
|
|
1053
1009
|
this._substitute(entering, row);
|
|
1054
1010
|
this._rowMap.insert(entering, row);
|
|
1011
|
+
iterations++;
|
|
1055
1012
|
}
|
|
1056
|
-
|
|
1013
|
+
throw new Error('solver iterations exceeded');
|
|
1014
|
+
}
|
|
1057
1015
|
/**
|
|
1058
1016
|
* Optimize the system using the dual of the simplex method.
|
|
1059
1017
|
*
|
|
@@ -1064,26 +1022,26 @@ var Solver = /** @class */ (function () {
|
|
|
1064
1022
|
*
|
|
1065
1023
|
* @private
|
|
1066
1024
|
*/
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1025
|
+
_dualOptimize() {
|
|
1026
|
+
let rows = this._rowMap;
|
|
1027
|
+
let infeasible = this._infeasibleRows;
|
|
1070
1028
|
while (infeasible.length !== 0) {
|
|
1071
|
-
|
|
1072
|
-
|
|
1029
|
+
let leaving = infeasible.pop();
|
|
1030
|
+
let pair = rows.find(leaving);
|
|
1073
1031
|
if (pair !== undefined && pair.second.constant() < 0.0) {
|
|
1074
|
-
|
|
1032
|
+
let entering = this._getDualEnteringSymbol(pair.second);
|
|
1075
1033
|
if (entering.type() === SymbolType.Invalid) {
|
|
1076
|
-
throw new Error(
|
|
1034
|
+
throw new Error('dual optimize failed');
|
|
1077
1035
|
}
|
|
1078
1036
|
// pivot the entering symbol into the basis
|
|
1079
|
-
|
|
1037
|
+
let row = pair.second;
|
|
1080
1038
|
rows.erase(leaving);
|
|
1081
1039
|
row.solveForEx(leaving, entering);
|
|
1082
1040
|
this._substitute(entering, row);
|
|
1083
1041
|
rows.insert(entering, row);
|
|
1084
1042
|
}
|
|
1085
1043
|
}
|
|
1086
|
-
}
|
|
1044
|
+
}
|
|
1087
1045
|
/**
|
|
1088
1046
|
* Compute the entering variable for a pivot operation.
|
|
1089
1047
|
*
|
|
@@ -1094,17 +1052,17 @@ var Solver = /** @class */ (function () {
|
|
|
1094
1052
|
*
|
|
1095
1053
|
* @private
|
|
1096
1054
|
*/
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
for (
|
|
1100
|
-
|
|
1101
|
-
|
|
1055
|
+
_getEnteringSymbol(objective) {
|
|
1056
|
+
let cells = objective.cells();
|
|
1057
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1058
|
+
let pair = cells.itemAt(i);
|
|
1059
|
+
let symbol = pair.first;
|
|
1102
1060
|
if (pair.second < 0.0 && symbol.type() !== SymbolType.Dummy) {
|
|
1103
1061
|
return symbol;
|
|
1104
1062
|
}
|
|
1105
1063
|
}
|
|
1106
1064
|
return INVALID_SYMBOL;
|
|
1107
|
-
}
|
|
1065
|
+
}
|
|
1108
1066
|
/**
|
|
1109
1067
|
* Compute the entering symbol for the dual optimize operation.
|
|
1110
1068
|
*
|
|
@@ -1116,17 +1074,17 @@ var Solver = /** @class */ (function () {
|
|
|
1116
1074
|
*
|
|
1117
1075
|
* @private
|
|
1118
1076
|
*/
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
for (
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1077
|
+
_getDualEnteringSymbol(row) {
|
|
1078
|
+
let ratio = Number.MAX_VALUE;
|
|
1079
|
+
let entering = INVALID_SYMBOL;
|
|
1080
|
+
let cells = row.cells();
|
|
1081
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1082
|
+
let pair = cells.itemAt(i);
|
|
1083
|
+
let symbol = pair.first;
|
|
1084
|
+
let c = pair.second;
|
|
1127
1085
|
if (c > 0.0 && symbol.type() !== SymbolType.Dummy) {
|
|
1128
|
-
|
|
1129
|
-
|
|
1086
|
+
let coeff = this._objective.coefficientFor(symbol);
|
|
1087
|
+
let r = coeff / c;
|
|
1130
1088
|
if (r < ratio) {
|
|
1131
1089
|
ratio = r;
|
|
1132
1090
|
entering = symbol;
|
|
@@ -1134,7 +1092,7 @@ var Solver = /** @class */ (function () {
|
|
|
1134
1092
|
}
|
|
1135
1093
|
}
|
|
1136
1094
|
return entering;
|
|
1137
|
-
}
|
|
1095
|
+
}
|
|
1138
1096
|
/**
|
|
1139
1097
|
* Compute the symbol for pivot exit row.
|
|
1140
1098
|
*
|
|
@@ -1145,18 +1103,18 @@ var Solver = /** @class */ (function () {
|
|
|
1145
1103
|
*
|
|
1146
1104
|
* @private
|
|
1147
1105
|
*/
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
for (
|
|
1153
|
-
|
|
1154
|
-
|
|
1106
|
+
_getLeavingSymbol(entering) {
|
|
1107
|
+
let ratio = Number.MAX_VALUE;
|
|
1108
|
+
let found = INVALID_SYMBOL;
|
|
1109
|
+
let rows = this._rowMap;
|
|
1110
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
1111
|
+
let pair = rows.itemAt(i);
|
|
1112
|
+
let symbol = pair.first;
|
|
1155
1113
|
if (symbol.type() !== SymbolType.External) {
|
|
1156
|
-
|
|
1157
|
-
|
|
1114
|
+
let row = pair.second;
|
|
1115
|
+
let temp = row.coefficientFor(entering);
|
|
1158
1116
|
if (temp < 0.0) {
|
|
1159
|
-
|
|
1117
|
+
let temp_ratio = -row.constant() / temp;
|
|
1160
1118
|
if (temp_ratio < ratio) {
|
|
1161
1119
|
ratio = temp_ratio;
|
|
1162
1120
|
found = symbol;
|
|
@@ -1165,7 +1123,7 @@ var Solver = /** @class */ (function () {
|
|
|
1165
1123
|
}
|
|
1166
1124
|
}
|
|
1167
1125
|
return found;
|
|
1168
|
-
}
|
|
1126
|
+
}
|
|
1169
1127
|
/**
|
|
1170
1128
|
* Compute the leaving symbol for a marker variable.
|
|
1171
1129
|
*
|
|
@@ -1187,35 +1145,35 @@ var Solver = /** @class */ (function () {
|
|
|
1187
1145
|
*
|
|
1188
1146
|
* @private
|
|
1189
1147
|
*/
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
for (
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1148
|
+
_getMarkerLeavingSymbol(marker) {
|
|
1149
|
+
let dmax = Number.MAX_VALUE;
|
|
1150
|
+
let r1 = dmax;
|
|
1151
|
+
let r2 = dmax;
|
|
1152
|
+
let invalid = INVALID_SYMBOL;
|
|
1153
|
+
let first = invalid;
|
|
1154
|
+
let second = invalid;
|
|
1155
|
+
let third = invalid;
|
|
1156
|
+
let rows = this._rowMap;
|
|
1157
|
+
for (let i = 0, n = rows.size(); i < n; ++i) {
|
|
1158
|
+
let pair = rows.itemAt(i);
|
|
1159
|
+
let row = pair.second;
|
|
1160
|
+
let c = row.coefficientFor(marker);
|
|
1203
1161
|
if (c === 0.0) {
|
|
1204
1162
|
continue;
|
|
1205
1163
|
}
|
|
1206
|
-
|
|
1164
|
+
let symbol = pair.first;
|
|
1207
1165
|
if (symbol.type() === SymbolType.External) {
|
|
1208
1166
|
third = symbol;
|
|
1209
1167
|
}
|
|
1210
1168
|
else if (c < 0.0) {
|
|
1211
|
-
|
|
1169
|
+
let r = -row.constant() / c;
|
|
1212
1170
|
if (r < r1) {
|
|
1213
1171
|
r1 = r;
|
|
1214
1172
|
first = symbol;
|
|
1215
1173
|
}
|
|
1216
1174
|
}
|
|
1217
1175
|
else {
|
|
1218
|
-
|
|
1176
|
+
let r = row.constant() / c;
|
|
1219
1177
|
if (r < r2) {
|
|
1220
1178
|
r2 = r;
|
|
1221
1179
|
second = symbol;
|
|
@@ -1229,34 +1187,34 @@ var Solver = /** @class */ (function () {
|
|
|
1229
1187
|
return second;
|
|
1230
1188
|
}
|
|
1231
1189
|
return third;
|
|
1232
|
-
}
|
|
1190
|
+
}
|
|
1233
1191
|
/**
|
|
1234
1192
|
* Remove the effects of a constraint on the objective function.
|
|
1235
1193
|
*
|
|
1236
1194
|
* @private
|
|
1237
1195
|
*/
|
|
1238
|
-
|
|
1196
|
+
_removeConstraintEffects(cn, tag) {
|
|
1239
1197
|
if (tag.marker.type() === SymbolType.Error) {
|
|
1240
1198
|
this._removeMarkerEffects(tag.marker, cn.strength());
|
|
1241
1199
|
}
|
|
1242
1200
|
if (tag.other.type() === SymbolType.Error) {
|
|
1243
1201
|
this._removeMarkerEffects(tag.other, cn.strength());
|
|
1244
1202
|
}
|
|
1245
|
-
}
|
|
1203
|
+
}
|
|
1246
1204
|
/**
|
|
1247
1205
|
* Remove the effects of an error marker on the objective function.
|
|
1248
1206
|
*
|
|
1249
1207
|
* @private
|
|
1250
1208
|
*/
|
|
1251
|
-
|
|
1252
|
-
|
|
1209
|
+
_removeMarkerEffects(marker, strength) {
|
|
1210
|
+
let pair = this._rowMap.find(marker);
|
|
1253
1211
|
if (pair !== undefined) {
|
|
1254
1212
|
this._objective.insertRow(pair.second, -strength);
|
|
1255
1213
|
}
|
|
1256
1214
|
else {
|
|
1257
1215
|
this._objective.insertSymbol(marker, -strength);
|
|
1258
1216
|
}
|
|
1259
|
-
}
|
|
1217
|
+
}
|
|
1260
1218
|
/**
|
|
1261
1219
|
* Get the first Slack or Error symbol in the row.
|
|
1262
1220
|
*
|
|
@@ -1264,33 +1222,40 @@ var Solver = /** @class */ (function () {
|
|
|
1264
1222
|
*
|
|
1265
1223
|
* @private
|
|
1266
1224
|
*/
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
for (
|
|
1270
|
-
|
|
1271
|
-
|
|
1225
|
+
_anyPivotableSymbol(row) {
|
|
1226
|
+
let cells = row.cells();
|
|
1227
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1228
|
+
let pair = cells.itemAt(i);
|
|
1229
|
+
let type = pair.first.type();
|
|
1272
1230
|
if (type === SymbolType.Slack || type === SymbolType.Error) {
|
|
1273
1231
|
return pair.first;
|
|
1274
1232
|
}
|
|
1275
1233
|
}
|
|
1276
1234
|
return INVALID_SYMBOL;
|
|
1277
|
-
}
|
|
1235
|
+
}
|
|
1278
1236
|
/**
|
|
1279
1237
|
* Returns a new Symbol of the given type.
|
|
1280
1238
|
*
|
|
1281
1239
|
* @private
|
|
1282
1240
|
*/
|
|
1283
|
-
|
|
1284
|
-
return new Symbol
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1241
|
+
_makeSymbol(type) {
|
|
1242
|
+
return new Symbol(type, this._idTick++);
|
|
1243
|
+
}
|
|
1244
|
+
_cnMap = createCnMap();
|
|
1245
|
+
_rowMap = createRowMap();
|
|
1246
|
+
_varMap = createVarMap();
|
|
1247
|
+
_editMap = createEditMap();
|
|
1248
|
+
_infeasibleRows = [];
|
|
1249
|
+
_objective = new Row();
|
|
1250
|
+
_artificial = null;
|
|
1251
|
+
_idTick = 0;
|
|
1252
|
+
}
|
|
1288
1253
|
/**
|
|
1289
1254
|
* Test whether a value is approximately zero.
|
|
1290
1255
|
* @private
|
|
1291
1256
|
*/
|
|
1292
1257
|
function nearZero(value) {
|
|
1293
|
-
|
|
1258
|
+
let eps = 1.0e-8;
|
|
1294
1259
|
return value < 0.0 ? -value < eps : value < eps;
|
|
1295
1260
|
}
|
|
1296
1261
|
/**
|
|
@@ -1337,96 +1302,95 @@ var SymbolType;
|
|
|
1337
1302
|
* An internal class representing a symbol in the solver.
|
|
1338
1303
|
* @private
|
|
1339
1304
|
*/
|
|
1340
|
-
|
|
1305
|
+
class Symbol {
|
|
1341
1306
|
/**
|
|
1342
1307
|
* Construct a new Symbol
|
|
1343
1308
|
*
|
|
1344
1309
|
* @param [type] The type of the symbol.
|
|
1345
1310
|
* @param [id] The unique id number of the symbol.
|
|
1346
1311
|
*/
|
|
1347
|
-
|
|
1312
|
+
constructor(type, id) {
|
|
1348
1313
|
this._id = id;
|
|
1349
1314
|
this._type = type;
|
|
1350
1315
|
}
|
|
1351
1316
|
/**
|
|
1352
1317
|
* Returns the unique id number of the symbol.
|
|
1353
1318
|
*/
|
|
1354
|
-
|
|
1319
|
+
id() {
|
|
1355
1320
|
return this._id;
|
|
1356
|
-
}
|
|
1321
|
+
}
|
|
1357
1322
|
/**
|
|
1358
1323
|
* Returns the type of the symbol.
|
|
1359
1324
|
*/
|
|
1360
|
-
|
|
1325
|
+
type() {
|
|
1361
1326
|
return this._type;
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1327
|
+
}
|
|
1328
|
+
_id;
|
|
1329
|
+
_type;
|
|
1330
|
+
}
|
|
1365
1331
|
/**
|
|
1366
1332
|
* A static invalid symbol
|
|
1367
1333
|
* @private
|
|
1368
1334
|
*/
|
|
1369
|
-
|
|
1335
|
+
let INVALID_SYMBOL = new Symbol(SymbolType.Invalid, -1);
|
|
1370
1336
|
/**
|
|
1371
1337
|
* An internal row class used by the solver.
|
|
1372
1338
|
* @private
|
|
1373
1339
|
*/
|
|
1374
|
-
|
|
1340
|
+
class Row {
|
|
1375
1341
|
/**
|
|
1376
1342
|
* Construct a new Row.
|
|
1377
1343
|
*/
|
|
1378
|
-
|
|
1379
|
-
if (constant === void 0) { constant = 0.0; }
|
|
1380
|
-
this._cellMap = createMap();
|
|
1344
|
+
constructor(constant = 0.0) {
|
|
1381
1345
|
this._constant = constant;
|
|
1382
1346
|
}
|
|
1383
1347
|
/**
|
|
1384
1348
|
* Returns the mapping of symbols to coefficients.
|
|
1385
1349
|
*/
|
|
1386
|
-
|
|
1350
|
+
cells() {
|
|
1387
1351
|
return this._cellMap;
|
|
1388
|
-
}
|
|
1352
|
+
}
|
|
1389
1353
|
/**
|
|
1390
1354
|
* Returns the constant for the row.
|
|
1391
1355
|
*/
|
|
1392
|
-
|
|
1356
|
+
constant() {
|
|
1393
1357
|
return this._constant;
|
|
1394
|
-
}
|
|
1358
|
+
}
|
|
1395
1359
|
/**
|
|
1396
1360
|
* Returns true if the row is a constant value.
|
|
1397
1361
|
*/
|
|
1398
|
-
|
|
1362
|
+
isConstant() {
|
|
1399
1363
|
return this._cellMap.empty();
|
|
1400
|
-
}
|
|
1364
|
+
}
|
|
1401
1365
|
/**
|
|
1402
1366
|
* Returns true if the Row has all dummy symbols.
|
|
1403
1367
|
*/
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
for (
|
|
1407
|
-
|
|
1368
|
+
allDummies() {
|
|
1369
|
+
let cells = this._cellMap;
|
|
1370
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1371
|
+
let pair = cells.itemAt(i);
|
|
1408
1372
|
if (pair.first.type() !== SymbolType.Dummy) {
|
|
1409
1373
|
return false;
|
|
1410
1374
|
}
|
|
1411
1375
|
}
|
|
1412
1376
|
return true;
|
|
1413
|
-
}
|
|
1377
|
+
}
|
|
1414
1378
|
/**
|
|
1415
1379
|
* Create a copy of the row.
|
|
1416
1380
|
*/
|
|
1417
|
-
|
|
1418
|
-
|
|
1381
|
+
copy() {
|
|
1382
|
+
let theCopy = new Row(this._constant);
|
|
1419
1383
|
theCopy._cellMap = this._cellMap.copy();
|
|
1420
1384
|
return theCopy;
|
|
1421
|
-
}
|
|
1385
|
+
}
|
|
1422
1386
|
/**
|
|
1423
1387
|
* Add a constant value to the row constant.
|
|
1424
1388
|
*
|
|
1425
1389
|
* Returns the new value of the constant.
|
|
1426
1390
|
*/
|
|
1427
|
-
|
|
1428
|
-
return this._constant += value;
|
|
1429
|
-
}
|
|
1391
|
+
add(value) {
|
|
1392
|
+
return (this._constant += value);
|
|
1393
|
+
}
|
|
1430
1394
|
/**
|
|
1431
1395
|
* Insert the symbol into the row with the given coefficient.
|
|
1432
1396
|
*
|
|
@@ -1434,13 +1398,12 @@ var Row = /** @class */ (function () {
|
|
|
1434
1398
|
* will be added to the existing coefficient. If the resulting
|
|
1435
1399
|
* coefficient is zero, the symbol will be removed from the row.
|
|
1436
1400
|
*/
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
if (nearZero(pair.second += coefficient)) {
|
|
1401
|
+
insertSymbol(symbol, coefficient = 1.0) {
|
|
1402
|
+
let pair = this._cellMap.setDefault(symbol, () => 0.0);
|
|
1403
|
+
if (nearZero((pair.second += coefficient))) {
|
|
1441
1404
|
this._cellMap.erase(symbol);
|
|
1442
1405
|
}
|
|
1443
|
-
}
|
|
1406
|
+
}
|
|
1444
1407
|
/**
|
|
1445
1408
|
* Insert a row into this row with a given coefficient.
|
|
1446
1409
|
*
|
|
@@ -1449,32 +1412,31 @@ var Row = /** @class */ (function () {
|
|
|
1449
1412
|
* cell with a resulting coefficient of zero will be removed
|
|
1450
1413
|
* from the row.
|
|
1451
1414
|
*/
|
|
1452
|
-
|
|
1453
|
-
if (coefficient === void 0) { coefficient = 1.0; }
|
|
1415
|
+
insertRow(other, coefficient = 1.0) {
|
|
1454
1416
|
this._constant += other._constant * coefficient;
|
|
1455
|
-
|
|
1456
|
-
for (
|
|
1457
|
-
|
|
1417
|
+
let cells = other._cellMap;
|
|
1418
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1419
|
+
let pair = cells.itemAt(i);
|
|
1458
1420
|
this.insertSymbol(pair.first, pair.second * coefficient);
|
|
1459
1421
|
}
|
|
1460
|
-
}
|
|
1422
|
+
}
|
|
1461
1423
|
/**
|
|
1462
1424
|
* Remove a symbol from the row.
|
|
1463
1425
|
*/
|
|
1464
|
-
|
|
1426
|
+
removeSymbol(symbol) {
|
|
1465
1427
|
this._cellMap.erase(symbol);
|
|
1466
|
-
}
|
|
1428
|
+
}
|
|
1467
1429
|
/**
|
|
1468
1430
|
* Reverse the sign of the constant and cells in the row.
|
|
1469
1431
|
*/
|
|
1470
|
-
|
|
1432
|
+
reverseSign() {
|
|
1471
1433
|
this._constant = -this._constant;
|
|
1472
|
-
|
|
1473
|
-
for (
|
|
1474
|
-
|
|
1434
|
+
let cells = this._cellMap;
|
|
1435
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1436
|
+
let pair = cells.itemAt(i);
|
|
1475
1437
|
pair.second = -pair.second;
|
|
1476
1438
|
}
|
|
1477
|
-
}
|
|
1439
|
+
}
|
|
1478
1440
|
/**
|
|
1479
1441
|
* Solve the row for the given symbol.
|
|
1480
1442
|
*
|
|
@@ -1487,15 +1449,15 @@ var Row = /** @class */ (function () {
|
|
|
1487
1449
|
*
|
|
1488
1450
|
* The given symbol *must* exist in the row.
|
|
1489
1451
|
*/
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1452
|
+
solveFor(symbol) {
|
|
1453
|
+
let cells = this._cellMap;
|
|
1454
|
+
let pair = cells.erase(symbol);
|
|
1455
|
+
let coeff = -1 / pair.second;
|
|
1494
1456
|
this._constant *= coeff;
|
|
1495
|
-
for (
|
|
1457
|
+
for (let i = 0, n = cells.size(); i < n; ++i) {
|
|
1496
1458
|
cells.itemAt(i).second *= coeff;
|
|
1497
1459
|
}
|
|
1498
|
-
}
|
|
1460
|
+
}
|
|
1499
1461
|
/**
|
|
1500
1462
|
* Solve the row for the given symbols.
|
|
1501
1463
|
*
|
|
@@ -1508,17 +1470,17 @@ var Row = /** @class */ (function () {
|
|
|
1508
1470
|
* The lhs symbol *must not* exist in the row, and the rhs
|
|
1509
1471
|
* symbol must* exist in the row.
|
|
1510
1472
|
*/
|
|
1511
|
-
|
|
1473
|
+
solveForEx(lhs, rhs) {
|
|
1512
1474
|
this.insertSymbol(lhs, -1);
|
|
1513
1475
|
this.solveFor(rhs);
|
|
1514
|
-
}
|
|
1476
|
+
}
|
|
1515
1477
|
/**
|
|
1516
1478
|
* Returns the coefficient for the given symbol.
|
|
1517
1479
|
*/
|
|
1518
|
-
|
|
1519
|
-
|
|
1480
|
+
coefficientFor(symbol) {
|
|
1481
|
+
let pair = this._cellMap.find(symbol);
|
|
1520
1482
|
return pair !== undefined ? pair.second : 0.0;
|
|
1521
|
-
}
|
|
1483
|
+
}
|
|
1522
1484
|
/**
|
|
1523
1485
|
* Substitute a symbol with the data from another row.
|
|
1524
1486
|
*
|
|
@@ -1528,53 +1490,15 @@ var Row = /** @class */ (function () {
|
|
|
1528
1490
|
*
|
|
1529
1491
|
* If the symbol does not exist in the row, this is a no-op.
|
|
1530
1492
|
*/
|
|
1531
|
-
|
|
1532
|
-
|
|
1493
|
+
substitute(symbol, row) {
|
|
1494
|
+
let pair = this._cellMap.erase(symbol);
|
|
1533
1495
|
if (pair !== undefined) {
|
|
1534
1496
|
this.insertRow(row, pair.second);
|
|
1535
1497
|
}
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
/** @internal */
|
|
1541
|
-
const xSymbol = Symbol("xSymbol");
|
|
1542
|
-
/** @internal */
|
|
1543
|
-
const ySymbol = Symbol("ySymbol");
|
|
1544
|
-
/** @internal */
|
|
1545
|
-
const widthSymbol = Symbol("widthSymbol");
|
|
1546
|
-
/** @internal */
|
|
1547
|
-
const heightSymbol = Symbol("heightSymbol");
|
|
1548
|
-
/** @internal */
|
|
1549
|
-
const addUIElementSymbol = Symbol("addUIElementSymbol");
|
|
1550
|
-
/** @internal */
|
|
1551
|
-
const removeUIElementSymbol = Symbol("removeUIElementSymbol");
|
|
1552
|
-
/** @internal */
|
|
1553
|
-
const addUIConstraintSymbol = Symbol("addConstraintSymbol");
|
|
1554
|
-
/** @internal */
|
|
1555
|
-
const removeUIConstraintSymbol = Symbol("removeUIConstraintSymbol");
|
|
1556
|
-
/** @internal */
|
|
1557
|
-
const addConstraintSymbol = Symbol("addConstraintSymbol");
|
|
1558
|
-
/** @internal */
|
|
1559
|
-
const removeConstraintSymbol = Symbol("removeConstraintSymbol");
|
|
1560
|
-
/** @internal */
|
|
1561
|
-
const addVariableSymbol = Symbol("addVariableSymbol");
|
|
1562
|
-
/** @internal */
|
|
1563
|
-
const removeVariableSymbol = Symbol("removeVariableSymbol");
|
|
1564
|
-
/** @internal */
|
|
1565
|
-
const suggestVariableSymbol = Symbol("suggestVariableSymbol");
|
|
1566
|
-
/** @internal */
|
|
1567
|
-
const disableConstraintSymbol = Symbol("disableConstraintSymbol");
|
|
1568
|
-
/** @internal */
|
|
1569
|
-
const enableConstraintSymbol = Symbol("enableConstraintSymbol");
|
|
1570
|
-
/** @internal */
|
|
1571
|
-
const needsRecalculation = Symbol("needsRecalculation");
|
|
1572
|
-
/** @internal */
|
|
1573
|
-
const renderSymbol = Symbol("renderSymbol");
|
|
1574
|
-
/** @internal */
|
|
1575
|
-
const clickSymbol = Symbol("clickSymbol");
|
|
1576
|
-
/** @internal */
|
|
1577
|
-
const sortSymbol = Symbol("sortSymbol");
|
|
1498
|
+
}
|
|
1499
|
+
_cellMap = createMap();
|
|
1500
|
+
_constant;
|
|
1501
|
+
}
|
|
1578
1502
|
|
|
1579
1503
|
/**
|
|
1580
1504
|
* Defines the screen orientation states for UI constraints.
|
|
@@ -1642,14 +1566,14 @@ class UIConstraint {
|
|
|
1642
1566
|
* Useful for debugging and identifying constraints.
|
|
1643
1567
|
*/
|
|
1644
1568
|
this.name = "";
|
|
1645
|
-
this.layer[
|
|
1569
|
+
this.layer["addUIConstraintInternal"](this, elements);
|
|
1646
1570
|
}
|
|
1647
1571
|
/**
|
|
1648
1572
|
* Destroys the constraint, removing it from the layer and solver.
|
|
1649
1573
|
* This should be called when the constraint is no longer needed.
|
|
1650
1574
|
*/
|
|
1651
1575
|
destroy() {
|
|
1652
|
-
this.layer[
|
|
1576
|
+
this.layer["removeUIConstraintInternal"](this);
|
|
1653
1577
|
}
|
|
1654
1578
|
}
|
|
1655
1579
|
|
|
@@ -1825,14 +1749,14 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1825
1749
|
* @param element - The UI element to constrain
|
|
1826
1750
|
* @param options - Configuration options
|
|
1827
1751
|
*/
|
|
1828
|
-
constructor(_private_element, options) {
|
|
1752
|
+
constructor(_private_element, options = {}) {
|
|
1829
1753
|
super(_private_element.layer, new Set([_private_element]));
|
|
1830
1754
|
this._private_element = _private_element;
|
|
1831
1755
|
this._private_options = {
|
|
1832
|
-
height: options
|
|
1833
|
-
power: resolvePower(options
|
|
1834
|
-
rule: resolveRule(options
|
|
1835
|
-
orientation: resolveOrientation(options
|
|
1756
|
+
height: options.height ?? _private_element.height,
|
|
1757
|
+
power: resolvePower(options.power),
|
|
1758
|
+
rule: resolveRule(options.rule),
|
|
1759
|
+
orientation: resolveOrientation(options.orientation),
|
|
1836
1760
|
};
|
|
1837
1761
|
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
1838
1762
|
this._private_options.orientation === this.layer.orientation) {
|
|
@@ -1852,9 +1776,9 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1852
1776
|
* @param orientation - The new screen orientation
|
|
1853
1777
|
* @internal
|
|
1854
1778
|
*/
|
|
1855
|
-
[
|
|
1779
|
+
["disableConstraintInternal"](newOrientation) {
|
|
1856
1780
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
1857
|
-
|
|
1781
|
+
newOrientation !== this._private_options.orientation) {
|
|
1858
1782
|
this.destroyConstraints();
|
|
1859
1783
|
}
|
|
1860
1784
|
}
|
|
@@ -1864,9 +1788,9 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1864
1788
|
* @param orientation - The new screen orientation
|
|
1865
1789
|
* @internal
|
|
1866
1790
|
*/
|
|
1867
|
-
[
|
|
1791
|
+
["enableConstraintInternal"](newOrientation) {
|
|
1868
1792
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
1869
|
-
|
|
1793
|
+
newOrientation === this._private_options.orientation) {
|
|
1870
1794
|
this.buildConstraints();
|
|
1871
1795
|
}
|
|
1872
1796
|
}
|
|
@@ -1878,8 +1802,8 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1878
1802
|
*
|
|
1879
1803
|
*/
|
|
1880
1804
|
buildConstraints() {
|
|
1881
|
-
this._private_constraint = new Constraint(new Expression(this._private_element[
|
|
1882
|
-
this.layer[
|
|
1805
|
+
this._private_constraint = new Constraint(new Expression(this._private_element["heightInternal"]), convertRuleToOperator(this._private_options.rule), this._private_options.height, convertPowerToStrength(this._private_options.power));
|
|
1806
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
1883
1807
|
}
|
|
1884
1808
|
/**
|
|
1885
1809
|
* Removes the height constraint from the constraint solver.
|
|
@@ -1887,7 +1811,7 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1887
1811
|
*/
|
|
1888
1812
|
destroyConstraints() {
|
|
1889
1813
|
if (this._private_constraint) {
|
|
1890
|
-
this.layer[
|
|
1814
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
1891
1815
|
this._private_constraint = undefined;
|
|
1892
1816
|
}
|
|
1893
1817
|
}
|
|
@@ -1895,7 +1819,6 @@ class UIHeightConstraint extends UIConstraint {
|
|
|
1895
1819
|
|
|
1896
1820
|
class t{constructor(t,i,r=0){this.t=new WeakMap,this.i=new Map,void 0!==t&&(void 0===i?this.i.set(t,r):this.t.set(i,new Map([[t,r]])));}insert(t,i,r=0){if(void 0===i){if(this.i.has(t))return;return void this.i.set(t,r)}const s=this.t.get(i);void 0===s?this.t.set(i,new Map([[t,r]])):s.has(t)||s.set(t,r);}remove(t,i){if(void 0===i)return void this.i.delete(t);const r=this.t.get(i);void 0!==r&&(r.delete(t),0===r.size&&this.t.delete(i));}has(t,i){if(void 0===i)return this.i.has(t);const r=this.t.get(i);return void 0!==r&&r.has(t)}getPriority(t,i){if(void 0===i)return this.i.get(t);const r=this.t.get(i);return void 0!==r?r.get(t):void 0}}class i{constructor(){this.o=new Map;}on(t,i,r,s=0){return this.h(t,false,s,i,r),this}once(t,i,r,s=0){return this.h(t,true,s,i,r),this}off(t,i,r){const s=this.o.get(t);if(void 0===s)return this;s.u&&(s.u=false,s.v=s.v.slice());const o=s.v;if(0===o.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;t<o.length;t++){const i=o[t];s.l.remove(i._,i.p);}return this}{const e=o.length;if(o[0]._===i&&o[0].p===r)return 1===e?this.o.delete(t):o.shift(),this;const n=e-1;if(o[n]._===i&&o[n].p===r)return o.pop(),this;if(e<10||o[0].M===o[n].M)for(let t=1;t<n;t++){const s=o[t];if(s._===i&&s.p===r)return o.splice(t,1),this}else {const t=s.l.getPriority(i,r);if(void 0===t)return this;let e=0,n=o.length-1;for(;e<=n;){const i=e+n>>>1;o[i].M<t?e=i+1:n=i-1;}const c=e;for(n=o.length-1;e<=n;){const i=e+n>>>1;o[i].M<=t?e=i+1:n=i-1;}const h=n;for(let t=c;t<=h;t++)if(o[t]._===i&&o[t].p===r)return o.splice(t,1),this}}return this}emit(t,...i){const r=this.o.get(t);if(void 0===r)return false;if(0===r.v.length)return false;r.u?r.v=r.v.slice():r.u=true;const s=r.v;let o=false;for(let t=0;t<s.length;t++){const r=s[t];r._.apply(r.p,i),r.k&&(o=true,r.m=true);}const e=this.o.get(t);if(void 0===e)return true;e.v===s&&(e.u=false);const n=e.v;if(o){let i=0;for(let t=0;t<n.length;t++){const r=n[t];r.m?e.l.remove(r._,r.p):n[i++]=r;}0===i?this.o.delete(t):n.length=i;}return true}h(i,r,s,o,e){let n=this.o.get(i);if(void 0===n)return void this.o.set(i,{v:[{_:o,p:e,M:s,k:r,m:false}],u:false,l:new t(o,e,s)});if(n.l.has(o,e))throw Error("Event listener already exists");n.l.insert(o,e,s);const c={_:o,p:e,M:s,k:r,m:false};n.u&&(n.u=false,n.v=n.v.slice());{const t=n.v,i=c.M;if(0===t.length||t[t.length-1].M<=i)return void t.push(c);if(t[0].M>=i)return void t.unshift(c);{let r=0,s=t.length;for(;r<s;){const o=r+s>>>1;t[o].M<i?r=o+1:s=o;}t.splice(r,0,c);}}}}
|
|
1897
1821
|
|
|
1898
|
-
var _a$2, _b$2, _c$2;
|
|
1899
1822
|
class UIAnchor extends i {
|
|
1900
1823
|
/**
|
|
1901
1824
|
* Creates a new UI element.
|
|
@@ -1909,31 +1832,31 @@ class UIAnchor extends i {
|
|
|
1909
1832
|
this.layer = layer;
|
|
1910
1833
|
this.object = object;
|
|
1911
1834
|
/** X position variable for constraint system */
|
|
1912
|
-
this[
|
|
1835
|
+
this["xInternal"] = new Variable("x");
|
|
1913
1836
|
/** Y position variable for constraint system */
|
|
1914
|
-
this[
|
|
1837
|
+
this["yInternal"] = new Variable("y");
|
|
1915
1838
|
/** Flag indicating whether the element needs recalculation */
|
|
1916
|
-
this[
|
|
1839
|
+
this["needsRecalculationInternal"] = false;
|
|
1917
1840
|
/** Unique identifier for the element */
|
|
1918
1841
|
this.name = MathUtils.generateUUID();
|
|
1919
1842
|
if (this.object) {
|
|
1920
1843
|
this.object.matrixAutoUpdate = false;
|
|
1921
1844
|
}
|
|
1922
|
-
this.layer[
|
|
1923
|
-
this.layer[
|
|
1924
|
-
this.layer[
|
|
1925
|
-
this[
|
|
1926
|
-
this[
|
|
1927
|
-
this.layer[
|
|
1928
|
-
this.layer[
|
|
1845
|
+
this.layer["addUIElementInternal"](this, object);
|
|
1846
|
+
this.layer["addVariableInternal"](this, this["xInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
1847
|
+
this.layer["addVariableInternal"](this, this["yInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
1848
|
+
this["xInternal"].setValue(x);
|
|
1849
|
+
this["yInternal"].setValue(y);
|
|
1850
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], x);
|
|
1851
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], y);
|
|
1929
1852
|
}
|
|
1930
1853
|
/** Gets the current x position of the anchor */
|
|
1931
1854
|
get x() {
|
|
1932
|
-
return this[
|
|
1855
|
+
return this["xInternal"].value();
|
|
1933
1856
|
}
|
|
1934
1857
|
/** Gets the current y position of the anchor */
|
|
1935
1858
|
get y() {
|
|
1936
|
-
return this[
|
|
1859
|
+
return this["yInternal"].value();
|
|
1937
1860
|
}
|
|
1938
1861
|
/** Gets the current z-index (depth) of the element */
|
|
1939
1862
|
get zIndex() {
|
|
@@ -1941,21 +1864,21 @@ class UIAnchor extends i {
|
|
|
1941
1864
|
}
|
|
1942
1865
|
/** Gets whether the element needs recalculation */
|
|
1943
1866
|
get needsRecalculation() {
|
|
1944
|
-
return this[
|
|
1867
|
+
return this["needsRecalculationInternal"];
|
|
1945
1868
|
}
|
|
1946
1869
|
/**
|
|
1947
1870
|
* Sets the x position of the element
|
|
1948
1871
|
* @param value - New x position
|
|
1949
1872
|
*/
|
|
1950
1873
|
set x(value) {
|
|
1951
|
-
this.layer[
|
|
1874
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], value);
|
|
1952
1875
|
}
|
|
1953
1876
|
/**
|
|
1954
1877
|
* Sets the y position of the element
|
|
1955
1878
|
* @param value - New y position
|
|
1956
1879
|
*/
|
|
1957
1880
|
set y(value) {
|
|
1958
|
-
this.layer[
|
|
1881
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], value);
|
|
1959
1882
|
}
|
|
1960
1883
|
/**
|
|
1961
1884
|
* Sets the z-index (depth) of the element
|
|
@@ -1965,7 +1888,7 @@ class UIAnchor extends i {
|
|
|
1965
1888
|
if (this.object && this.object.renderOrder !== value) {
|
|
1966
1889
|
this.object.position.z = value;
|
|
1967
1890
|
this.object.renderOrder = value;
|
|
1968
|
-
this.layer[
|
|
1891
|
+
this.layer["sortInternal"]();
|
|
1969
1892
|
this.object.updateMatrix();
|
|
1970
1893
|
}
|
|
1971
1894
|
}
|
|
@@ -1974,9 +1897,9 @@ class UIAnchor extends i {
|
|
|
1974
1897
|
* This should be called when the anchor is no longer needed.
|
|
1975
1898
|
*/
|
|
1976
1899
|
destroy() {
|
|
1977
|
-
this.layer[
|
|
1978
|
-
this.layer[
|
|
1979
|
-
this.layer[
|
|
1900
|
+
this.layer["removeVariableInternal"](this, this["yInternal"]);
|
|
1901
|
+
this.layer["removeVariableInternal"](this, this["xInternal"]);
|
|
1902
|
+
this.layer["removeUIElementInternal"](this);
|
|
1980
1903
|
}
|
|
1981
1904
|
/**
|
|
1982
1905
|
* Internal method called by the rendering system to render this element.
|
|
@@ -1985,7 +1908,7 @@ class UIAnchor extends i {
|
|
|
1985
1908
|
* @param deltaTime - Time elapsed since the last frame
|
|
1986
1909
|
* @internal
|
|
1987
1910
|
*/
|
|
1988
|
-
[
|
|
1911
|
+
["renderInternal"](renderer, deltaTime) {
|
|
1989
1912
|
this.render(renderer, deltaTime);
|
|
1990
1913
|
}
|
|
1991
1914
|
/**
|
|
@@ -1993,11 +1916,11 @@ class UIAnchor extends i {
|
|
|
1993
1916
|
* This is called when the element's position, size, or other properties change.
|
|
1994
1917
|
*/
|
|
1995
1918
|
applyTransformations() {
|
|
1996
|
-
if (this[
|
|
1919
|
+
if (this["needsRecalculationInternal"]) {
|
|
1997
1920
|
if (this.object) {
|
|
1998
1921
|
this.object.updateMatrix();
|
|
1999
1922
|
}
|
|
2000
|
-
this[
|
|
1923
|
+
this["needsRecalculationInternal"] = false;
|
|
2001
1924
|
}
|
|
2002
1925
|
}
|
|
2003
1926
|
}
|
|
@@ -2554,7 +2477,7 @@ class UIComposerInternal {
|
|
|
2554
2477
|
this._private_paddingHasChangedInternal = false;
|
|
2555
2478
|
/** Current padding value in pixels */
|
|
2556
2479
|
this._private_paddingInternal = 0;
|
|
2557
|
-
const
|
|
2480
|
+
const options = {
|
|
2558
2481
|
format: RGBAFormat,
|
|
2559
2482
|
minFilter: LinearFilter,
|
|
2560
2483
|
magFilter: LinearFilter,
|
|
@@ -2562,8 +2485,8 @@ class UIComposerInternal {
|
|
|
2562
2485
|
depthBuffer: false,
|
|
2563
2486
|
stencilBuffer: false,
|
|
2564
2487
|
};
|
|
2565
|
-
this._private_fromRenderTarget = new WebGLRenderTarget(1, 1,
|
|
2566
|
-
this._private_toRenderTarget = new WebGLRenderTarget(1, 1,
|
|
2488
|
+
this._private_fromRenderTarget = new WebGLRenderTarget(1, 1, options);
|
|
2489
|
+
this._private_toRenderTarget = new WebGLRenderTarget(1, 1, options);
|
|
2567
2490
|
this._private_fromRenderTarget.texture.generateMipmaps = false;
|
|
2568
2491
|
this._private_toRenderTarget.texture.generateMipmaps = false;
|
|
2569
2492
|
}
|
|
@@ -2635,13 +2558,12 @@ class UIComposerInternal {
|
|
|
2635
2558
|
this._private_screen.render(renderer, material);
|
|
2636
2559
|
material.blending = originalBlending;
|
|
2637
2560
|
const options = { width, height, padding };
|
|
2638
|
-
for (
|
|
2639
|
-
const pass = this.passes[i];
|
|
2561
|
+
for (const pass of this.passes) {
|
|
2640
2562
|
if (pass.needsUpdate || pass.isValuable) {
|
|
2641
2563
|
this._private_reverseRenderTargets();
|
|
2642
2564
|
renderer.setRenderTarget(this._private_toRenderTarget);
|
|
2643
2565
|
renderer.clear(true, false, false);
|
|
2644
|
-
|
|
2566
|
+
pass.render(renderer, this._private_fromRenderTarget.texture, options);
|
|
2645
2567
|
}
|
|
2646
2568
|
}
|
|
2647
2569
|
this._private_needsUpdateInternal = false;
|
|
@@ -2720,7 +2642,6 @@ class UIComposer {
|
|
|
2720
2642
|
}
|
|
2721
2643
|
}
|
|
2722
2644
|
|
|
2723
|
-
var _a$1, _b$1, _c$1, _d$1, _e;
|
|
2724
2645
|
/**
|
|
2725
2646
|
* Events that can be emitted by UI elements.
|
|
2726
2647
|
*/
|
|
@@ -2756,15 +2677,15 @@ class UIElement extends i {
|
|
|
2756
2677
|
this.layer = layer;
|
|
2757
2678
|
this.object = object;
|
|
2758
2679
|
/** X position variable for constraint system */
|
|
2759
|
-
this[
|
|
2680
|
+
this["xInternal"] = new Variable("x");
|
|
2760
2681
|
/** Y position variable for constraint system */
|
|
2761
|
-
this[
|
|
2682
|
+
this["yInternal"] = new Variable("y");
|
|
2762
2683
|
/** Width variable for constraint system */
|
|
2763
|
-
this[
|
|
2684
|
+
this["widthInternal"] = new Variable("width");
|
|
2764
2685
|
/** Height variable for constraint system */
|
|
2765
|
-
this[
|
|
2686
|
+
this["heightInternal"] = new Variable("height");
|
|
2766
2687
|
/** Flag indicating whether the element needs recalculation */
|
|
2767
|
-
this[
|
|
2688
|
+
this["needsRecalculationInternal"] = false;
|
|
2768
2689
|
/** Unique identifier for the element */
|
|
2769
2690
|
this.name = MathUtils.generateUUID();
|
|
2770
2691
|
/** Internal micro transformation implementation */
|
|
@@ -2776,35 +2697,35 @@ class UIElement extends i {
|
|
|
2776
2697
|
this.micro = new UIMicro(this.microInternal, this);
|
|
2777
2698
|
this.composer = new UIComposer(this.composerInternal);
|
|
2778
2699
|
this.object.matrixAutoUpdate = false;
|
|
2779
|
-
this.layer[
|
|
2780
|
-
this.layer[
|
|
2781
|
-
this.layer[
|
|
2782
|
-
this.layer[
|
|
2783
|
-
this.layer[
|
|
2784
|
-
this[
|
|
2785
|
-
this[
|
|
2786
|
-
this[
|
|
2787
|
-
this[
|
|
2788
|
-
this.layer[
|
|
2789
|
-
this.layer[
|
|
2790
|
-
this.layer[
|
|
2791
|
-
this.layer[
|
|
2700
|
+
this.layer["addUIElementInternal"](this, this.object);
|
|
2701
|
+
this.layer["addVariableInternal"](this, this["xInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
2702
|
+
this.layer["addVariableInternal"](this, this["yInternal"], convertPowerToStrength(UIConstraintPower.P7));
|
|
2703
|
+
this.layer["addVariableInternal"](this, this["widthInternal"], convertPowerToStrength(UIConstraintPower.P5));
|
|
2704
|
+
this.layer["addVariableInternal"](this, this["heightInternal"], convertPowerToStrength(UIConstraintPower.P5));
|
|
2705
|
+
this["xInternal"].setValue(x);
|
|
2706
|
+
this["yInternal"].setValue(y);
|
|
2707
|
+
this["widthInternal"].setValue(width);
|
|
2708
|
+
this["heightInternal"].setValue(height);
|
|
2709
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], x);
|
|
2710
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], y);
|
|
2711
|
+
this.layer["suggestVariableInternal"](this, this["widthInternal"], width);
|
|
2712
|
+
this.layer["suggestVariableInternal"](this, this["heightInternal"], height);
|
|
2792
2713
|
}
|
|
2793
2714
|
/** Gets the current x position of the element */
|
|
2794
2715
|
get x() {
|
|
2795
|
-
return this[
|
|
2716
|
+
return this["xInternal"].value();
|
|
2796
2717
|
}
|
|
2797
2718
|
/** Gets the current y position of the element */
|
|
2798
2719
|
get y() {
|
|
2799
|
-
return this[
|
|
2720
|
+
return this["yInternal"].value();
|
|
2800
2721
|
}
|
|
2801
2722
|
/** Gets the current width of the element */
|
|
2802
2723
|
get width() {
|
|
2803
|
-
return this[
|
|
2724
|
+
return this["widthInternal"].value();
|
|
2804
2725
|
}
|
|
2805
2726
|
/** Gets the current height of the element */
|
|
2806
2727
|
get height() {
|
|
2807
|
-
return this[
|
|
2728
|
+
return this["heightInternal"].value();
|
|
2808
2729
|
}
|
|
2809
2730
|
/** Gets the current z-index (depth) of the element */
|
|
2810
2731
|
get zIndex() {
|
|
@@ -2816,35 +2737,35 @@ class UIElement extends i {
|
|
|
2816
2737
|
}
|
|
2817
2738
|
/** Gets whether the element needs recalculation */
|
|
2818
2739
|
get needsRecalculation() {
|
|
2819
|
-
return this[
|
|
2740
|
+
return this["needsRecalculationInternal"];
|
|
2820
2741
|
}
|
|
2821
2742
|
/**
|
|
2822
2743
|
* Sets the x position of the element
|
|
2823
2744
|
* @param value - New x position
|
|
2824
2745
|
*/
|
|
2825
2746
|
set x(value) {
|
|
2826
|
-
this.layer[
|
|
2747
|
+
this.layer["suggestVariableInternal"](this, this["xInternal"], value);
|
|
2827
2748
|
}
|
|
2828
2749
|
/**
|
|
2829
2750
|
* Sets the y position of the element
|
|
2830
2751
|
* @param value - New y position
|
|
2831
2752
|
*/
|
|
2832
2753
|
set y(value) {
|
|
2833
|
-
this.layer[
|
|
2754
|
+
this.layer["suggestVariableInternal"](this, this["yInternal"], value);
|
|
2834
2755
|
}
|
|
2835
2756
|
/**
|
|
2836
2757
|
* Sets the width of the element
|
|
2837
2758
|
* @param value - New width
|
|
2838
2759
|
*/
|
|
2839
2760
|
set width(value) {
|
|
2840
|
-
this.layer[
|
|
2761
|
+
this.layer["suggestVariableInternal"](this, this["widthInternal"], value);
|
|
2841
2762
|
}
|
|
2842
2763
|
/**
|
|
2843
2764
|
* Sets the height of the element
|
|
2844
2765
|
* @param value - New height
|
|
2845
2766
|
*/
|
|
2846
2767
|
set height(value) {
|
|
2847
|
-
this.layer[
|
|
2768
|
+
this.layer["suggestVariableInternal"](this, this["heightInternal"], value);
|
|
2848
2769
|
}
|
|
2849
2770
|
/**
|
|
2850
2771
|
* Sets the z-index (depth) of the element
|
|
@@ -2854,7 +2775,7 @@ class UIElement extends i {
|
|
|
2854
2775
|
if (this.object.renderOrder !== value) {
|
|
2855
2776
|
this.object.position.z = value;
|
|
2856
2777
|
this.object.renderOrder = value;
|
|
2857
|
-
this.layer[
|
|
2778
|
+
this.layer["sortInternal"]();
|
|
2858
2779
|
this.object.updateMatrix();
|
|
2859
2780
|
}
|
|
2860
2781
|
}
|
|
@@ -2872,11 +2793,11 @@ class UIElement extends i {
|
|
|
2872
2793
|
*/
|
|
2873
2794
|
destroy() {
|
|
2874
2795
|
this.composerInternal.destroy();
|
|
2875
|
-
this.layer[
|
|
2876
|
-
this.layer[
|
|
2877
|
-
this.layer[
|
|
2878
|
-
this.layer[
|
|
2879
|
-
this.layer[
|
|
2796
|
+
this.layer["removeVariableInternal"](this, this["heightInternal"]);
|
|
2797
|
+
this.layer["removeVariableInternal"](this, this["widthInternal"]);
|
|
2798
|
+
this.layer["removeVariableInternal"](this, this["yInternal"]);
|
|
2799
|
+
this.layer["removeVariableInternal"](this, this["xInternal"]);
|
|
2800
|
+
this.layer["removeUIElementInternal"](this);
|
|
2880
2801
|
}
|
|
2881
2802
|
/**
|
|
2882
2803
|
* Internal method called by the rendering system to render this element.
|
|
@@ -2885,7 +2806,7 @@ class UIElement extends i {
|
|
|
2885
2806
|
* @param deltaTime - Time elapsed since the last frame
|
|
2886
2807
|
* @internal
|
|
2887
2808
|
*/
|
|
2888
|
-
[
|
|
2809
|
+
["renderInternal"](renderer, deltaTime) {
|
|
2889
2810
|
this.render(renderer, deltaTime);
|
|
2890
2811
|
}
|
|
2891
2812
|
/**
|
|
@@ -2896,7 +2817,7 @@ class UIElement extends i {
|
|
|
2896
2817
|
* @returns Whether the click was handled by this element
|
|
2897
2818
|
* @internal
|
|
2898
2819
|
*/
|
|
2899
|
-
[
|
|
2820
|
+
["clickInternal"](x, y) {
|
|
2900
2821
|
return this.click(x, y);
|
|
2901
2822
|
}
|
|
2902
2823
|
/**
|
|
@@ -2904,12 +2825,12 @@ class UIElement extends i {
|
|
|
2904
2825
|
* This is called when the element's position, size, or other properties change.
|
|
2905
2826
|
*/
|
|
2906
2827
|
applyTransformations() {
|
|
2907
|
-
if (this[
|
|
2828
|
+
if (this["needsRecalculationInternal"] ||
|
|
2908
2829
|
this.microInternal.needsRecalculation ||
|
|
2909
2830
|
this.composerInternal.paddingHasChanged) {
|
|
2910
2831
|
applyMicroTransformations(this.object, this.microInternal, this.x, this.y, this.width, this.height, this.composerInternal.padding);
|
|
2911
2832
|
this.object.updateMatrix();
|
|
2912
|
-
this[
|
|
2833
|
+
this["needsRecalculationInternal"] = false;
|
|
2913
2834
|
this.microInternal.needsRecalculation = false;
|
|
2914
2835
|
}
|
|
2915
2836
|
}
|
|
@@ -2933,7 +2854,6 @@ class UIElement extends i {
|
|
|
2933
2854
|
}
|
|
2934
2855
|
}
|
|
2935
2856
|
|
|
2936
|
-
var _a, _b, _c, _d;
|
|
2937
2857
|
const clearColor = new Color(0x000000);
|
|
2938
2858
|
var UILayerEvent;
|
|
2939
2859
|
(function (UILayerEvent) {
|
|
@@ -2944,10 +2864,10 @@ class UILayer extends i {
|
|
|
2944
2864
|
constructor() {
|
|
2945
2865
|
super(...arguments);
|
|
2946
2866
|
this.mode = UIMode.VISIBLE;
|
|
2947
|
-
this[
|
|
2948
|
-
this[
|
|
2949
|
-
this[
|
|
2950
|
-
this[
|
|
2867
|
+
this["xInternal"] = new Variable();
|
|
2868
|
+
this["yInternal"] = new Variable();
|
|
2869
|
+
this["widthInternal"] = new Variable();
|
|
2870
|
+
this["heightInternal"] = new Variable();
|
|
2951
2871
|
this.scene = new Scene();
|
|
2952
2872
|
this.camera = new OrthographicCamera();
|
|
2953
2873
|
this.solver = new Solver();
|
|
@@ -2960,10 +2880,10 @@ class UILayer extends i {
|
|
|
2960
2880
|
return this.orientationPrivate;
|
|
2961
2881
|
}
|
|
2962
2882
|
get width() {
|
|
2963
|
-
return this[
|
|
2883
|
+
return this["widthInternal"].value();
|
|
2964
2884
|
}
|
|
2965
2885
|
get height() {
|
|
2966
|
-
return this[
|
|
2886
|
+
return this["heightInternal"].value();
|
|
2967
2887
|
}
|
|
2968
2888
|
destroy() {
|
|
2969
2889
|
this.solver = undefined;
|
|
@@ -2974,7 +2894,7 @@ class UILayer extends i {
|
|
|
2974
2894
|
element.destroy();
|
|
2975
2895
|
}
|
|
2976
2896
|
}
|
|
2977
|
-
[
|
|
2897
|
+
["addUIElementInternal"](element, object, renderOrder) {
|
|
2978
2898
|
if (this.elements.has(element)) {
|
|
2979
2899
|
throw new Error("Element already added");
|
|
2980
2900
|
}
|
|
@@ -2988,10 +2908,10 @@ class UILayer extends i {
|
|
|
2988
2908
|
object.position.z = zIndex;
|
|
2989
2909
|
object.renderOrder = zIndex;
|
|
2990
2910
|
this.scene.add(object);
|
|
2991
|
-
this[
|
|
2911
|
+
this["sortInternal"]();
|
|
2992
2912
|
}
|
|
2993
2913
|
}
|
|
2994
|
-
[
|
|
2914
|
+
["removeUIElementInternal"](element) {
|
|
2995
2915
|
const dependencies = this.elements.get(element);
|
|
2996
2916
|
if (dependencies === undefined) {
|
|
2997
2917
|
throw new Error("Element not found");
|
|
@@ -3007,7 +2927,7 @@ class UILayer extends i {
|
|
|
3007
2927
|
this.scene.remove(dependencies.object);
|
|
3008
2928
|
}
|
|
3009
2929
|
}
|
|
3010
|
-
[
|
|
2930
|
+
["addUIConstraintInternal"](constraint, elements) {
|
|
3011
2931
|
if (this.constraints.has(constraint)) {
|
|
3012
2932
|
throw new Error("Constraint already added");
|
|
3013
2933
|
}
|
|
@@ -3027,7 +2947,7 @@ class UILayer extends i {
|
|
|
3027
2947
|
constraints: new Set(),
|
|
3028
2948
|
});
|
|
3029
2949
|
}
|
|
3030
|
-
[
|
|
2950
|
+
["removeUIConstraintInternal"](constraint) {
|
|
3031
2951
|
const dependencies = this.constraints.get(constraint);
|
|
3032
2952
|
if (dependencies === undefined) {
|
|
3033
2953
|
throw new Error("Constraint not found");
|
|
@@ -3050,7 +2970,7 @@ class UILayer extends i {
|
|
|
3050
2970
|
}
|
|
3051
2971
|
this.constraints.delete(constraint);
|
|
3052
2972
|
}
|
|
3053
|
-
[
|
|
2973
|
+
["addConstraintInternal"](owner, constraint) {
|
|
3054
2974
|
const dependencies = this.constraints.get(owner);
|
|
3055
2975
|
if (dependencies === undefined) {
|
|
3056
2976
|
throw new Error("Before adding constraint you need to add it's owner");
|
|
@@ -3067,7 +2987,7 @@ class UILayer extends i {
|
|
|
3067
2987
|
}
|
|
3068
2988
|
this.needsRecalculation = true;
|
|
3069
2989
|
}
|
|
3070
|
-
[
|
|
2990
|
+
["removeConstraintInternal"](owner, constraint) {
|
|
3071
2991
|
const dependencies = this.constraints.get(owner);
|
|
3072
2992
|
if (dependencies === undefined) {
|
|
3073
2993
|
throw new Error("Before removing constraint you need to add it's owner");
|
|
@@ -3084,7 +3004,7 @@ class UILayer extends i {
|
|
|
3084
3004
|
}
|
|
3085
3005
|
this.needsRecalculation = true;
|
|
3086
3006
|
}
|
|
3087
|
-
[
|
|
3007
|
+
["addVariableInternal"](owner, variable, strength) {
|
|
3088
3008
|
const dependencies = owner instanceof UIElement || owner instanceof UIAnchor
|
|
3089
3009
|
? this.elements.get(owner)
|
|
3090
3010
|
: this.constraints.get(owner);
|
|
@@ -3106,7 +3026,7 @@ class UILayer extends i {
|
|
|
3106
3026
|
}
|
|
3107
3027
|
this.needsRecalculation = true;
|
|
3108
3028
|
}
|
|
3109
|
-
[
|
|
3029
|
+
["removeVariableInternal"](owner, variable) {
|
|
3110
3030
|
const dependencies = owner instanceof UIElement || owner instanceof UIAnchor
|
|
3111
3031
|
? this.elements.get(owner)
|
|
3112
3032
|
: this.constraints.get(owner);
|
|
@@ -3125,7 +3045,7 @@ class UILayer extends i {
|
|
|
3125
3045
|
}
|
|
3126
3046
|
this.needsRecalculation = true;
|
|
3127
3047
|
}
|
|
3128
|
-
[
|
|
3048
|
+
["suggestVariableInternal"](owner, variable, value) {
|
|
3129
3049
|
const dependencies = owner instanceof UIElement || owner instanceof UIAnchor
|
|
3130
3050
|
? this.elements.get(owner)
|
|
3131
3051
|
: this.constraints.get(owner);
|
|
@@ -3147,7 +3067,7 @@ class UILayer extends i {
|
|
|
3147
3067
|
this.needsRecalculation = true;
|
|
3148
3068
|
}
|
|
3149
3069
|
}
|
|
3150
|
-
[
|
|
3070
|
+
["sortInternal"]() {
|
|
3151
3071
|
this.scene.children.sort((a, b) => a.position.z - b.position.z);
|
|
3152
3072
|
for (let i = 0; i < this.scene.children.length; i++) {
|
|
3153
3073
|
const child = this.scene.children[i];
|
|
@@ -3172,11 +3092,11 @@ class UILayer extends i {
|
|
|
3172
3092
|
this.needsRecalculation = false;
|
|
3173
3093
|
this.solver?.updateVariables();
|
|
3174
3094
|
for (const element of this.elements.keys()) {
|
|
3175
|
-
element[
|
|
3095
|
+
element["needsRecalculationInternal"] = true;
|
|
3176
3096
|
}
|
|
3177
3097
|
}
|
|
3178
3098
|
for (const element of this.elements.keys()) {
|
|
3179
|
-
element[
|
|
3099
|
+
element["renderInternal"](renderer, deltaTime);
|
|
3180
3100
|
}
|
|
3181
3101
|
renderer.setRenderTarget(originalRenderTarget);
|
|
3182
3102
|
renderer.setClearColor(originalClearColor);
|
|
@@ -3193,7 +3113,7 @@ class UILayer extends i {
|
|
|
3193
3113
|
.filter((e) => e.mode === UIMode.INTERACTIVE)
|
|
3194
3114
|
.sort((a, b) => a.zIndex - b.zIndex);
|
|
3195
3115
|
for (const element of elements) {
|
|
3196
|
-
if (element[
|
|
3116
|
+
if (element["clickInternal"](x, y)) {
|
|
3197
3117
|
break;
|
|
3198
3118
|
}
|
|
3199
3119
|
}
|
|
@@ -3228,10 +3148,10 @@ class UILayer extends i {
|
|
|
3228
3148
|
this.solver?.removeConstraint(this.constraintH);
|
|
3229
3149
|
this.constraintH = undefined;
|
|
3230
3150
|
}
|
|
3231
|
-
this.constraintX = new Constraint(new Expression(this[
|
|
3232
|
-
this.constraintY = new Constraint(new Expression(this[
|
|
3233
|
-
this.constraintW = new Constraint(new Expression(this[
|
|
3234
|
-
this.constraintH = new Constraint(new Expression(this[
|
|
3151
|
+
this.constraintX = new Constraint(new Expression(this["xInternal"]), Operator.Eq, 0, Strength.required);
|
|
3152
|
+
this.constraintY = new Constraint(new Expression(this["yInternal"]), Operator.Eq, 0, Strength.required);
|
|
3153
|
+
this.constraintW = new Constraint(new Expression(this["widthInternal"]), Operator.Eq, width, Strength.required);
|
|
3154
|
+
this.constraintH = new Constraint(new Expression(this["heightInternal"]), Operator.Eq, height, Strength.required);
|
|
3235
3155
|
this.solver?.addConstraint(this.constraintX);
|
|
3236
3156
|
this.solver?.addConstraint(this.constraintY);
|
|
3237
3157
|
this.solver?.addConstraint(this.constraintW);
|
|
@@ -3244,10 +3164,10 @@ class UILayer extends i {
|
|
|
3244
3164
|
if (lastOrientation !== this.orientationPrivate) {
|
|
3245
3165
|
this.solver = undefined;
|
|
3246
3166
|
for (const constraint of this.constraints.keys()) {
|
|
3247
|
-
constraint[
|
|
3167
|
+
constraint["enableConstraintInternal"](this.orientationPrivate);
|
|
3248
3168
|
}
|
|
3249
3169
|
for (const constraint of this.constraints.keys()) {
|
|
3250
|
-
constraint[
|
|
3170
|
+
constraint["disableConstraintInternal"](this.orientationPrivate);
|
|
3251
3171
|
}
|
|
3252
3172
|
this.solver = new Solver();
|
|
3253
3173
|
const descriptions = [
|
|
@@ -3347,25 +3267,25 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3347
3267
|
*
|
|
3348
3268
|
* @param elementOne - The first element or layer
|
|
3349
3269
|
* @param elementTwo - The second element
|
|
3350
|
-
* @param
|
|
3270
|
+
* @param options - Configuration options
|
|
3351
3271
|
*/
|
|
3352
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3272
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3353
3273
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3354
3274
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement || _private_elementOne instanceof UIAnchor
|
|
3355
3275
|
? [_private_elementOne, _private_elementTwo]
|
|
3356
3276
|
: [_private_elementTwo]));
|
|
3357
3277
|
this._private_elementOne = _private_elementOne;
|
|
3358
3278
|
this._private_elementTwo = _private_elementTwo;
|
|
3359
|
-
this.
|
|
3360
|
-
anchorOne:
|
|
3361
|
-
anchorTwo:
|
|
3362
|
-
distance:
|
|
3363
|
-
power: resolvePower(
|
|
3364
|
-
rule: resolveRule(
|
|
3365
|
-
orientation: resolveOrientation(
|
|
3279
|
+
this._private_options = {
|
|
3280
|
+
anchorOne: options.anchorOne ?? DEFAULT_ANCHOR$3,
|
|
3281
|
+
anchorTwo: options.anchorTwo ?? DEFAULT_ANCHOR$3,
|
|
3282
|
+
distance: options.distance ?? 0,
|
|
3283
|
+
power: resolvePower(options.power),
|
|
3284
|
+
rule: resolveRule(options.rule),
|
|
3285
|
+
orientation: resolveOrientation(options.orientation),
|
|
3366
3286
|
};
|
|
3367
|
-
if (this.
|
|
3368
|
-
this.
|
|
3287
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3288
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3369
3289
|
this.buildConstraints();
|
|
3370
3290
|
}
|
|
3371
3291
|
}
|
|
@@ -3382,9 +3302,9 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3382
3302
|
* @param orientation - The new screen orientation
|
|
3383
3303
|
* @internal
|
|
3384
3304
|
*/
|
|
3385
|
-
[
|
|
3386
|
-
if (this.
|
|
3387
|
-
orientation !== this.
|
|
3305
|
+
["disableConstraintInternal"](orientation) {
|
|
3306
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3307
|
+
orientation !== this._private_options.orientation) {
|
|
3388
3308
|
this.destroyConstraints();
|
|
3389
3309
|
}
|
|
3390
3310
|
}
|
|
@@ -3394,9 +3314,9 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3394
3314
|
* @param orientation - The new screen orientation
|
|
3395
3315
|
* @internal
|
|
3396
3316
|
*/
|
|
3397
|
-
[
|
|
3398
|
-
if (this.
|
|
3399
|
-
orientation === this.
|
|
3317
|
+
["enableConstraintInternal"](orientation) {
|
|
3318
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3319
|
+
orientation === this._private_options.orientation) {
|
|
3400
3320
|
this.buildConstraints();
|
|
3401
3321
|
}
|
|
3402
3322
|
}
|
|
@@ -3409,13 +3329,13 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3409
3329
|
*/
|
|
3410
3330
|
buildConstraints() {
|
|
3411
3331
|
const expressionOne = this._private_elementOne instanceof UIElement || this._private_elementOne instanceof UILayer
|
|
3412
|
-
? new Expression(this._private_elementOne[
|
|
3413
|
-
: new Expression(this._private_elementOne[
|
|
3332
|
+
? new Expression(this._private_elementOne["xInternal"]).plus(new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.anchorOne))
|
|
3333
|
+
: new Expression(this._private_elementOne["xInternal"]);
|
|
3414
3334
|
const expressionTwo = this._private_elementTwo instanceof UIElement
|
|
3415
|
-
? new Expression(this._private_elementTwo[
|
|
3416
|
-
: new Expression(this._private_elementTwo[
|
|
3417
|
-
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this.
|
|
3418
|
-
this.layer[
|
|
3335
|
+
? new Expression(this._private_elementTwo["xInternal"]).plus(new Expression(this._private_elementTwo["widthInternal"]).multiply(this._private_options.anchorTwo))
|
|
3336
|
+
: new Expression(this._private_elementTwo["xInternal"]);
|
|
3337
|
+
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this._private_options.rule), this._private_options.distance, convertPowerToStrength(this._private_options.power));
|
|
3338
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3419
3339
|
}
|
|
3420
3340
|
/**
|
|
3421
3341
|
* Removes the horizontal distance constraint from the constraint solver.
|
|
@@ -3423,7 +3343,7 @@ class UIHorizontalDistanceConstraint extends UIConstraint {
|
|
|
3423
3343
|
*/
|
|
3424
3344
|
destroyConstraints() {
|
|
3425
3345
|
if (this._private_constraint) {
|
|
3426
|
-
this.layer[
|
|
3346
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3427
3347
|
this._private_constraint = undefined;
|
|
3428
3348
|
}
|
|
3429
3349
|
}
|
|
@@ -3441,23 +3361,23 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3441
3361
|
*
|
|
3442
3362
|
* @param elementOne - The reference element or layer
|
|
3443
3363
|
* @param elementTwo - The element to constrain proportionally
|
|
3444
|
-
* @param
|
|
3364
|
+
* @param options - Configuration options
|
|
3445
3365
|
*/
|
|
3446
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3366
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3447
3367
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3448
3368
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
3449
3369
|
? [_private_elementOne, _private_elementTwo]
|
|
3450
3370
|
: [_private_elementTwo]));
|
|
3451
3371
|
this._private_elementOne = _private_elementOne;
|
|
3452
3372
|
this._private_elementTwo = _private_elementTwo;
|
|
3453
|
-
this.
|
|
3454
|
-
proportion:
|
|
3455
|
-
power: resolvePower(
|
|
3456
|
-
rule: resolveRule(
|
|
3457
|
-
orientation: resolveOrientation(
|
|
3373
|
+
this._private_options = {
|
|
3374
|
+
proportion: options.proportion ?? 1,
|
|
3375
|
+
power: resolvePower(options.power),
|
|
3376
|
+
rule: resolveRule(options.rule),
|
|
3377
|
+
orientation: resolveOrientation(options.orientation),
|
|
3458
3378
|
};
|
|
3459
|
-
if (this.
|
|
3460
|
-
this.
|
|
3379
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3380
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3461
3381
|
this.buildConstraints();
|
|
3462
3382
|
}
|
|
3463
3383
|
}
|
|
@@ -3474,9 +3394,9 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3474
3394
|
* @param orientation - The new screen orientation
|
|
3475
3395
|
* @internal
|
|
3476
3396
|
*/
|
|
3477
|
-
[
|
|
3478
|
-
if (this.
|
|
3479
|
-
orientation !== this.
|
|
3397
|
+
["disableConstraintInternal"](orientation) {
|
|
3398
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3399
|
+
orientation !== this._private_options.orientation) {
|
|
3480
3400
|
this.destroyConstraints();
|
|
3481
3401
|
}
|
|
3482
3402
|
}
|
|
@@ -3486,9 +3406,9 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3486
3406
|
* @param orientation - The new screen orientation
|
|
3487
3407
|
* @internal
|
|
3488
3408
|
*/
|
|
3489
|
-
[
|
|
3490
|
-
if (this.
|
|
3491
|
-
orientation === this.
|
|
3409
|
+
["enableConstraintInternal"](orientation) {
|
|
3410
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3411
|
+
orientation === this._private_options.orientation) {
|
|
3492
3412
|
this.buildConstraints();
|
|
3493
3413
|
}
|
|
3494
3414
|
}
|
|
@@ -3500,10 +3420,10 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3500
3420
|
*
|
|
3501
3421
|
*/
|
|
3502
3422
|
buildConstraints() {
|
|
3503
|
-
const expressionOne = new Expression(this._private_elementOne[
|
|
3504
|
-
const expressionTwo = new Expression(this._private_elementTwo[
|
|
3505
|
-
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this.
|
|
3506
|
-
this.layer[
|
|
3423
|
+
const expressionOne = new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.proportion);
|
|
3424
|
+
const expressionTwo = new Expression(this._private_elementTwo["widthInternal"]);
|
|
3425
|
+
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this._private_options.rule), 0, convertPowerToStrength(this._private_options.power));
|
|
3426
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3507
3427
|
}
|
|
3508
3428
|
/**
|
|
3509
3429
|
* Removes the horizontal proportion constraint from the constraint solver.
|
|
@@ -3511,7 +3431,7 @@ class UIHorizontalProportionConstraint extends UIConstraint {
|
|
|
3511
3431
|
*/
|
|
3512
3432
|
destroyConstraints() {
|
|
3513
3433
|
if (this._private_constraint) {
|
|
3514
|
-
this.layer[
|
|
3434
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3515
3435
|
this._private_constraint = undefined;
|
|
3516
3436
|
}
|
|
3517
3437
|
}
|
|
@@ -3533,25 +3453,25 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3533
3453
|
*
|
|
3534
3454
|
* @param elementOne - The first element or layer
|
|
3535
3455
|
* @param elementTwo - The second element
|
|
3536
|
-
* @param
|
|
3456
|
+
* @param options - Configuration options
|
|
3537
3457
|
*/
|
|
3538
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3458
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3539
3459
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3540
3460
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement || _private_elementOne instanceof UIAnchor
|
|
3541
3461
|
? [_private_elementOne, _private_elementTwo]
|
|
3542
3462
|
: [_private_elementTwo]));
|
|
3543
3463
|
this._private_elementOne = _private_elementOne;
|
|
3544
3464
|
this._private_elementTwo = _private_elementTwo;
|
|
3545
|
-
this.
|
|
3546
|
-
anchorOne:
|
|
3547
|
-
anchorTwo:
|
|
3548
|
-
distance:
|
|
3549
|
-
power: resolvePower(
|
|
3550
|
-
rule: resolveRule(
|
|
3551
|
-
orientation: resolveOrientation(
|
|
3465
|
+
this._private_options = {
|
|
3466
|
+
anchorOne: options.anchorOne ?? DEFAULT_ANCHOR$2,
|
|
3467
|
+
anchorTwo: options.anchorTwo ?? DEFAULT_ANCHOR$2,
|
|
3468
|
+
distance: options.distance ?? 0,
|
|
3469
|
+
power: resolvePower(options.power),
|
|
3470
|
+
rule: resolveRule(options.rule),
|
|
3471
|
+
orientation: resolveOrientation(options.orientation),
|
|
3552
3472
|
};
|
|
3553
|
-
if (this.
|
|
3554
|
-
this.
|
|
3473
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3474
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3555
3475
|
this.buildConstraints();
|
|
3556
3476
|
}
|
|
3557
3477
|
}
|
|
@@ -3568,9 +3488,9 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3568
3488
|
* @param orientation - The new screen orientation
|
|
3569
3489
|
* @internal
|
|
3570
3490
|
*/
|
|
3571
|
-
[
|
|
3572
|
-
if (this.
|
|
3573
|
-
orientation !== this.
|
|
3491
|
+
["disableConstraintInternal"](orientation) {
|
|
3492
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3493
|
+
orientation !== this._private_options.orientation) {
|
|
3574
3494
|
this.destroyConstraints();
|
|
3575
3495
|
}
|
|
3576
3496
|
}
|
|
@@ -3580,9 +3500,9 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3580
3500
|
* @param orientation - The new screen orientation
|
|
3581
3501
|
* @internal
|
|
3582
3502
|
*/
|
|
3583
|
-
[
|
|
3584
|
-
if (this.
|
|
3585
|
-
orientation === this.
|
|
3503
|
+
["enableConstraintInternal"](orientation) {
|
|
3504
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3505
|
+
orientation === this._private_options.orientation) {
|
|
3586
3506
|
this.buildConstraints();
|
|
3587
3507
|
}
|
|
3588
3508
|
}
|
|
@@ -3595,13 +3515,13 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3595
3515
|
*/
|
|
3596
3516
|
buildConstraints() {
|
|
3597
3517
|
const expressionOne = this._private_elementOne instanceof UIElement || this._private_elementOne instanceof UILayer
|
|
3598
|
-
? new Expression(this._private_elementOne[
|
|
3599
|
-
: new Expression(this._private_elementOne[
|
|
3518
|
+
? new Expression(this._private_elementOne["yInternal"]).plus(new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.anchorOne))
|
|
3519
|
+
: new Expression(this._private_elementOne["yInternal"]);
|
|
3600
3520
|
const expressionTwo = this._private_elementTwo instanceof UIElement
|
|
3601
|
-
? new Expression(this._private_elementTwo[
|
|
3602
|
-
: new Expression(this._private_elementTwo[
|
|
3603
|
-
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this.
|
|
3604
|
-
this.layer[
|
|
3521
|
+
? new Expression(this._private_elementTwo["yInternal"]).plus(new Expression(this._private_elementTwo["heightInternal"]).multiply(this._private_options.anchorTwo))
|
|
3522
|
+
: new Expression(this._private_elementTwo["yInternal"]);
|
|
3523
|
+
this._private_constraint = new Constraint(expressionTwo.minus(expressionOne), convertRuleToOperator(this._private_options.rule), this._private_options.distance, convertPowerToStrength(this._private_options.power));
|
|
3524
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3605
3525
|
}
|
|
3606
3526
|
/**
|
|
3607
3527
|
* Removes the vertical distance constraint from the constraint solver.
|
|
@@ -3609,7 +3529,7 @@ class UIVerticalDistanceConstraint extends UIConstraint {
|
|
|
3609
3529
|
*/
|
|
3610
3530
|
destroyConstraints() {
|
|
3611
3531
|
if (this._private_constraint) {
|
|
3612
|
-
this.layer[
|
|
3532
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3613
3533
|
this._private_constraint = undefined;
|
|
3614
3534
|
}
|
|
3615
3535
|
}
|
|
@@ -3627,23 +3547,23 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3627
3547
|
*
|
|
3628
3548
|
* @param elementOne - The reference element or layer
|
|
3629
3549
|
* @param elementTwo - The element to constrain proportionally
|
|
3630
|
-
* @param
|
|
3550
|
+
* @param options - Configuration options
|
|
3631
3551
|
*/
|
|
3632
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3552
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
3633
3553
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
3634
3554
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
3635
3555
|
? [_private_elementOne, _private_elementTwo]
|
|
3636
3556
|
: [_private_elementTwo]));
|
|
3637
3557
|
this._private_elementOne = _private_elementOne;
|
|
3638
3558
|
this._private_elementTwo = _private_elementTwo;
|
|
3639
|
-
this.
|
|
3640
|
-
proportion:
|
|
3641
|
-
power: resolvePower(
|
|
3642
|
-
rule: resolveRule(
|
|
3643
|
-
orientation: resolveOrientation(
|
|
3559
|
+
this._private_options = {
|
|
3560
|
+
proportion: options.proportion ?? 1,
|
|
3561
|
+
power: resolvePower(options.power),
|
|
3562
|
+
rule: resolveRule(options.rule),
|
|
3563
|
+
orientation: resolveOrientation(options.orientation),
|
|
3644
3564
|
};
|
|
3645
|
-
if (this.
|
|
3646
|
-
this.
|
|
3565
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3566
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3647
3567
|
this.buildConstraints();
|
|
3648
3568
|
}
|
|
3649
3569
|
}
|
|
@@ -3660,9 +3580,9 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3660
3580
|
* @param orientation - The new screen orientation
|
|
3661
3581
|
* @internal
|
|
3662
3582
|
*/
|
|
3663
|
-
[
|
|
3664
|
-
if (this.
|
|
3665
|
-
orientation !== this.
|
|
3583
|
+
["disableConstraintInternal"](orientation) {
|
|
3584
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3585
|
+
orientation !== this._private_options.orientation) {
|
|
3666
3586
|
this.destroyConstraints();
|
|
3667
3587
|
}
|
|
3668
3588
|
}
|
|
@@ -3672,9 +3592,9 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3672
3592
|
* @param orientation - The new screen orientation
|
|
3673
3593
|
* @internal
|
|
3674
3594
|
*/
|
|
3675
|
-
[
|
|
3676
|
-
if (this.
|
|
3677
|
-
orientation === this.
|
|
3595
|
+
["enableConstraintInternal"](orientation) {
|
|
3596
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3597
|
+
orientation === this._private_options.orientation) {
|
|
3678
3598
|
this.buildConstraints();
|
|
3679
3599
|
}
|
|
3680
3600
|
}
|
|
@@ -3686,10 +3606,10 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3686
3606
|
*
|
|
3687
3607
|
*/
|
|
3688
3608
|
buildConstraints() {
|
|
3689
|
-
const expressionOne = new Expression(this._private_elementOne[
|
|
3690
|
-
const expressionTwo = new Expression(this._private_elementTwo[
|
|
3691
|
-
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this.
|
|
3692
|
-
this.layer[
|
|
3609
|
+
const expressionOne = new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.proportion);
|
|
3610
|
+
const expressionTwo = new Expression(this._private_elementTwo["heightInternal"]);
|
|
3611
|
+
this._private_constraint = new Constraint(expressionOne.minus(expressionTwo), convertRuleToOperator(this._private_options.rule), 0, convertPowerToStrength(this._private_options.power));
|
|
3612
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3693
3613
|
}
|
|
3694
3614
|
/**
|
|
3695
3615
|
* Removes the vertical proportion constraint from the constraint solver.
|
|
@@ -3697,7 +3617,7 @@ class UIVerticalProportionConstraint extends UIConstraint {
|
|
|
3697
3617
|
*/
|
|
3698
3618
|
destroyConstraints() {
|
|
3699
3619
|
if (this._private_constraint) {
|
|
3700
|
-
this.layer[
|
|
3620
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3701
3621
|
this._private_constraint = undefined;
|
|
3702
3622
|
}
|
|
3703
3623
|
}
|
|
@@ -3716,14 +3636,14 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3716
3636
|
* @param element - The UI element to constrain
|
|
3717
3637
|
* @param options - Configuration options
|
|
3718
3638
|
*/
|
|
3719
|
-
constructor(_private_element, options) {
|
|
3639
|
+
constructor(_private_element, options = {}) {
|
|
3720
3640
|
super(_private_element.layer, new Set([_private_element]));
|
|
3721
3641
|
this._private_element = _private_element;
|
|
3722
3642
|
this._private_options = {
|
|
3723
|
-
width: options
|
|
3724
|
-
power: resolvePower(options
|
|
3725
|
-
rule: resolveRule(options
|
|
3726
|
-
orientation: resolveOrientation(options
|
|
3643
|
+
width: options.width ?? _private_element.width,
|
|
3644
|
+
power: resolvePower(options.power),
|
|
3645
|
+
rule: resolveRule(options.rule),
|
|
3646
|
+
orientation: resolveOrientation(options.orientation),
|
|
3727
3647
|
};
|
|
3728
3648
|
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3729
3649
|
this._private_options.orientation === this.layer.orientation) {
|
|
@@ -3743,9 +3663,9 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3743
3663
|
* @param orientation - The new screen orientation
|
|
3744
3664
|
* @internal
|
|
3745
3665
|
*/
|
|
3746
|
-
[
|
|
3666
|
+
["disableConstraintInternal"](newOrientation) {
|
|
3747
3667
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3748
|
-
|
|
3668
|
+
newOrientation !== this._private_options.orientation) {
|
|
3749
3669
|
this.destroyConstraints();
|
|
3750
3670
|
}
|
|
3751
3671
|
}
|
|
@@ -3755,9 +3675,9 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3755
3675
|
* @param orientation - The new screen orientation
|
|
3756
3676
|
* @internal
|
|
3757
3677
|
*/
|
|
3758
|
-
[
|
|
3678
|
+
["enableConstraintInternal"](newOrientation) {
|
|
3759
3679
|
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3760
|
-
|
|
3680
|
+
newOrientation === this._private_options.orientation) {
|
|
3761
3681
|
this.buildConstraints();
|
|
3762
3682
|
}
|
|
3763
3683
|
}
|
|
@@ -3769,8 +3689,8 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3769
3689
|
*
|
|
3770
3690
|
*/
|
|
3771
3691
|
buildConstraints() {
|
|
3772
|
-
this._private_constraint = new Constraint(new Expression(this._private_element[
|
|
3773
|
-
this.layer[
|
|
3692
|
+
this._private_constraint = new Constraint(new Expression(this._private_element["widthInternal"]), convertRuleToOperator(this._private_options.rule), this._private_options.width, convertPowerToStrength(this._private_options.power));
|
|
3693
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
3774
3694
|
}
|
|
3775
3695
|
/**
|
|
3776
3696
|
* Removes the width constraint from the constraint solver.
|
|
@@ -3778,7 +3698,7 @@ class UIWidthConstraint extends UIConstraint {
|
|
|
3778
3698
|
*/
|
|
3779
3699
|
destroyConstraints() {
|
|
3780
3700
|
if (this._private_constraint) {
|
|
3781
|
-
this.layer[
|
|
3701
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
3782
3702
|
this._private_constraint = undefined;
|
|
3783
3703
|
}
|
|
3784
3704
|
}
|
|
@@ -3788,52 +3708,52 @@ class UIConstraint2DBuilder {
|
|
|
3788
3708
|
static size(element, options = {}) {
|
|
3789
3709
|
return {
|
|
3790
3710
|
x: new UIWidthConstraint(element, {
|
|
3791
|
-
width: options.size?.
|
|
3792
|
-
power: options.power?.
|
|
3793
|
-
rule: options.rule?.
|
|
3794
|
-
orientation: options.orientation?.
|
|
3711
|
+
width: options.size?.h,
|
|
3712
|
+
power: options.power?.h,
|
|
3713
|
+
rule: options.rule?.h,
|
|
3714
|
+
orientation: options.orientation?.h,
|
|
3795
3715
|
}),
|
|
3796
3716
|
y: new UIHeightConstraint(element, {
|
|
3797
|
-
height: options.size?.
|
|
3798
|
-
power: options.power?.
|
|
3799
|
-
rule: options.rule?.
|
|
3800
|
-
orientation: options.orientation?.
|
|
3717
|
+
height: options.size?.v,
|
|
3718
|
+
power: options.power?.v,
|
|
3719
|
+
rule: options.rule?.v,
|
|
3720
|
+
orientation: options.orientation?.v,
|
|
3801
3721
|
}),
|
|
3802
3722
|
};
|
|
3803
3723
|
}
|
|
3804
3724
|
static distance(elementOne, elementTwo, options = {}) {
|
|
3805
3725
|
return {
|
|
3806
3726
|
x: new UIHorizontalDistanceConstraint(elementOne, elementTwo, {
|
|
3807
|
-
anchorOne: options.anchorOne?.
|
|
3808
|
-
anchorTwo: options.anchorTwo?.
|
|
3809
|
-
distance: options.distance?.
|
|
3810
|
-
power: options.power?.
|
|
3811
|
-
rule: options.rule?.
|
|
3812
|
-
orientation: options.orientation?.
|
|
3727
|
+
anchorOne: options.anchorOne?.h,
|
|
3728
|
+
anchorTwo: options.anchorTwo?.h,
|
|
3729
|
+
distance: options.distance?.h,
|
|
3730
|
+
power: options.power?.h,
|
|
3731
|
+
rule: options.rule?.h,
|
|
3732
|
+
orientation: options.orientation?.h,
|
|
3813
3733
|
}),
|
|
3814
3734
|
y: new UIVerticalDistanceConstraint(elementOne, elementTwo, {
|
|
3815
|
-
anchorOne: options.anchorOne?.
|
|
3816
|
-
anchorTwo: options.anchorTwo?.
|
|
3817
|
-
distance: options.distance?.
|
|
3818
|
-
power: options.power?.
|
|
3819
|
-
rule: options.rule?.
|
|
3820
|
-
orientation: options.orientation?.
|
|
3735
|
+
anchorOne: options.anchorOne?.v,
|
|
3736
|
+
anchorTwo: options.anchorTwo?.v,
|
|
3737
|
+
distance: options.distance?.v,
|
|
3738
|
+
power: options.power?.v,
|
|
3739
|
+
rule: options.rule?.v,
|
|
3740
|
+
orientation: options.orientation?.v,
|
|
3821
3741
|
}),
|
|
3822
3742
|
};
|
|
3823
3743
|
}
|
|
3824
3744
|
static proportion(elementOne, elementTwo, options = {}) {
|
|
3825
3745
|
return {
|
|
3826
3746
|
x: new UIHorizontalProportionConstraint(elementOne, elementTwo, {
|
|
3827
|
-
proportion: options.proportion?.
|
|
3828
|
-
power: options.power?.
|
|
3829
|
-
rule: options.rule?.
|
|
3830
|
-
orientation: options.orientation?.
|
|
3747
|
+
proportion: options.proportion?.h,
|
|
3748
|
+
power: options.power?.h,
|
|
3749
|
+
rule: options.rule?.h,
|
|
3750
|
+
orientation: options.orientation?.h,
|
|
3831
3751
|
}),
|
|
3832
3752
|
y: new UIVerticalProportionConstraint(elementOne, elementTwo, {
|
|
3833
|
-
proportion: options.proportion?.
|
|
3834
|
-
power: options.power?.
|
|
3835
|
-
rule: options.rule?.
|
|
3836
|
-
orientation: options.orientation?.
|
|
3753
|
+
proportion: options.proportion?.v,
|
|
3754
|
+
power: options.power?.v,
|
|
3755
|
+
rule: options.rule?.v,
|
|
3756
|
+
orientation: options.orientation?.v,
|
|
3837
3757
|
}),
|
|
3838
3758
|
};
|
|
3839
3759
|
}
|
|
@@ -3948,19 +3868,19 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
3948
3868
|
* Creates a new aspect ratio constraint.
|
|
3949
3869
|
*
|
|
3950
3870
|
* @param element - The UI element to constrain
|
|
3951
|
-
* @param
|
|
3871
|
+
* @param options - Configuration options
|
|
3952
3872
|
*/
|
|
3953
|
-
constructor(_private_element,
|
|
3873
|
+
constructor(_private_element, options = {}) {
|
|
3954
3874
|
super(_private_element.layer, new Set([_private_element]));
|
|
3955
3875
|
this._private_element = _private_element;
|
|
3956
|
-
this.
|
|
3957
|
-
aspect:
|
|
3958
|
-
power: resolvePower(
|
|
3959
|
-
rule: resolveRule(
|
|
3960
|
-
orientation: resolveOrientation(
|
|
3876
|
+
this._private_options = {
|
|
3877
|
+
aspect: options.aspect ?? this._private_element.width / this._private_element.height,
|
|
3878
|
+
power: resolvePower(options.power),
|
|
3879
|
+
rule: resolveRule(options.rule),
|
|
3880
|
+
orientation: resolveOrientation(options.orientation),
|
|
3961
3881
|
};
|
|
3962
|
-
if (this.
|
|
3963
|
-
this.
|
|
3882
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3883
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
3964
3884
|
this.buildConstraints();
|
|
3965
3885
|
}
|
|
3966
3886
|
}
|
|
@@ -3977,9 +3897,9 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
3977
3897
|
* @param newOrientation - The new screen orientation
|
|
3978
3898
|
* @internal
|
|
3979
3899
|
*/
|
|
3980
|
-
[
|
|
3981
|
-
if (this.
|
|
3982
|
-
newOrientation !== this.
|
|
3900
|
+
["disableConstraintInternal"](newOrientation) {
|
|
3901
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3902
|
+
newOrientation !== this._private_options.orientation) {
|
|
3983
3903
|
this.destroyConstraints();
|
|
3984
3904
|
}
|
|
3985
3905
|
}
|
|
@@ -3989,9 +3909,9 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
3989
3909
|
* @param newOrientation - The new screen orientation
|
|
3990
3910
|
* @internal
|
|
3991
3911
|
*/
|
|
3992
|
-
[
|
|
3993
|
-
if (this.
|
|
3994
|
-
newOrientation === this.
|
|
3912
|
+
["enableConstraintInternal"](newOrientation) {
|
|
3913
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3914
|
+
newOrientation === this._private_options.orientation) {
|
|
3995
3915
|
this.buildConstraints();
|
|
3996
3916
|
}
|
|
3997
3917
|
}
|
|
@@ -4003,9 +3923,9 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
4003
3923
|
*
|
|
4004
3924
|
*/
|
|
4005
3925
|
buildConstraints() {
|
|
4006
|
-
const expression = new Expression(this._private_element[
|
|
4007
|
-
this._private_constraint = new Constraint(expression, convertRuleToOperator(this.
|
|
4008
|
-
this.layer[
|
|
3926
|
+
const expression = new Expression(this._private_element["widthInternal"]).plus(new Expression(this._private_element["heightInternal"]).multiply(-this._private_options.aspect));
|
|
3927
|
+
this._private_constraint = new Constraint(expression, convertRuleToOperator(this._private_options.rule), 0, convertPowerToStrength(this._private_options.power));
|
|
3928
|
+
this.layer["addConstraintInternal"](this, this._private_constraint);
|
|
4009
3929
|
}
|
|
4010
3930
|
/**
|
|
4011
3931
|
* Removes the aspect ratio constraint from the constraint solver.
|
|
@@ -4013,7 +3933,7 @@ class UIAspectConstraint extends UIConstraint {
|
|
|
4013
3933
|
*/
|
|
4014
3934
|
destroyConstraints() {
|
|
4015
3935
|
if (this._private_constraint) {
|
|
4016
|
-
this.layer[
|
|
3936
|
+
this.layer["removeConstraintInternal"](this, this._private_constraint);
|
|
4017
3937
|
this._private_constraint = undefined;
|
|
4018
3938
|
}
|
|
4019
3939
|
}
|
|
@@ -4039,23 +3959,23 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4039
3959
|
*
|
|
4040
3960
|
* @param elementOne - The element or layer to be covered (the reference)
|
|
4041
3961
|
* @param elementTwo - The element that will cover the reference
|
|
4042
|
-
* @param
|
|
3962
|
+
* @param options - Configuration options
|
|
4043
3963
|
*/
|
|
4044
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
3964
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
4045
3965
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
4046
3966
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
4047
3967
|
? [_private_elementOne, _private_elementTwo]
|
|
4048
3968
|
: [_private_elementTwo]));
|
|
4049
3969
|
this._private_elementOne = _private_elementOne;
|
|
4050
3970
|
this._private_elementTwo = _private_elementTwo;
|
|
4051
|
-
this.
|
|
4052
|
-
isStrict:
|
|
4053
|
-
horizontalAnchor:
|
|
4054
|
-
verticalAnchor:
|
|
4055
|
-
orientation: resolveOrientation(
|
|
3971
|
+
this._private_options = {
|
|
3972
|
+
isStrict: options.isStrict ?? true,
|
|
3973
|
+
horizontalAnchor: options.horizontalAnchor ?? DEFAULT_ANCHOR$1,
|
|
3974
|
+
verticalAnchor: options.verticalAnchor ?? DEFAULT_ANCHOR$1,
|
|
3975
|
+
orientation: resolveOrientation(options.orientation),
|
|
4056
3976
|
};
|
|
4057
|
-
if (this.
|
|
4058
|
-
this.
|
|
3977
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
3978
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
4059
3979
|
this.buildConstraints();
|
|
4060
3980
|
}
|
|
4061
3981
|
}
|
|
@@ -4072,9 +3992,9 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4072
3992
|
* @param orientation - The new screen orientation
|
|
4073
3993
|
* @internal
|
|
4074
3994
|
*/
|
|
4075
|
-
[
|
|
4076
|
-
if (this.
|
|
4077
|
-
orientation !== this.
|
|
3995
|
+
["disableConstraintInternal"](orientation) {
|
|
3996
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
3997
|
+
orientation !== this._private_options.orientation) {
|
|
4078
3998
|
this.destroyConstraints();
|
|
4079
3999
|
}
|
|
4080
4000
|
}
|
|
@@ -4084,9 +4004,9 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4084
4004
|
* @param orientation - The new screen orientation
|
|
4085
4005
|
* @internal
|
|
4086
4006
|
*/
|
|
4087
|
-
[
|
|
4088
|
-
if (this.
|
|
4089
|
-
orientation === this.
|
|
4007
|
+
["enableConstraintInternal"](orientation) {
|
|
4008
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
4009
|
+
orientation === this._private_options.orientation) {
|
|
4090
4010
|
this.buildConstraints();
|
|
4091
4011
|
}
|
|
4092
4012
|
}
|
|
@@ -4102,17 +4022,17 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4102
4022
|
*
|
|
4103
4023
|
*/
|
|
4104
4024
|
buildConstraints() {
|
|
4105
|
-
this._private_constraintX = new Constraint(new Expression(this._private_elementOne[
|
|
4106
|
-
this._private_constraintY = new Constraint(new Expression(this._private_elementOne[
|
|
4107
|
-
this._private_constraintW = new Constraint(new Expression(this._private_elementOne[
|
|
4108
|
-
this._private_constraintH = new Constraint(new Expression(this._private_elementOne[
|
|
4109
|
-
this.layer[
|
|
4110
|
-
this.layer[
|
|
4111
|
-
this.layer[
|
|
4112
|
-
this.layer[
|
|
4113
|
-
if (!this.
|
|
4114
|
-
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne[
|
|
4115
|
-
this.layer[
|
|
4025
|
+
this._private_constraintX = new Constraint(new Expression(this._private_elementOne["xInternal"]).plus(new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.horizontalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["xInternal"]).plus(new Expression(this._private_elementTwo["widthInternal"]).multiply(this._private_options.horizontalAnchor)));
|
|
4026
|
+
this._private_constraintY = new Constraint(new Expression(this._private_elementOne["yInternal"]).plus(new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.verticalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["yInternal"]).plus(new Expression(this._private_elementTwo["heightInternal"]).multiply(this._private_options.verticalAnchor)));
|
|
4027
|
+
this._private_constraintW = new Constraint(new Expression(this._private_elementOne["widthInternal"]), Operator.Eq, new Expression(this._private_elementTwo["widthInternal"]));
|
|
4028
|
+
this._private_constraintH = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Eq, new Expression(this._private_elementTwo["heightInternal"]));
|
|
4029
|
+
this.layer["addConstraintInternal"](this, this._private_constraintX);
|
|
4030
|
+
this.layer["addConstraintInternal"](this, this._private_constraintY);
|
|
4031
|
+
this.layer["addConstraintInternal"](this, this._private_constraintW);
|
|
4032
|
+
this.layer["addConstraintInternal"](this, this._private_constraintH);
|
|
4033
|
+
if (!this._private_options.isStrict) {
|
|
4034
|
+
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Eq, new Expression(this._private_elementTwo["heightInternal"]));
|
|
4035
|
+
this.layer["addConstraintInternal"](this, this._private_constraintStrict);
|
|
4116
4036
|
}
|
|
4117
4037
|
}
|
|
4118
4038
|
/**
|
|
@@ -4121,23 +4041,23 @@ class UICoverConstraint extends UIConstraint {
|
|
|
4121
4041
|
*/
|
|
4122
4042
|
destroyConstraints() {
|
|
4123
4043
|
if (this._private_constraintX) {
|
|
4124
|
-
this.layer[
|
|
4044
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintX);
|
|
4125
4045
|
this._private_constraintX = undefined;
|
|
4126
4046
|
}
|
|
4127
4047
|
if (this._private_constraintY) {
|
|
4128
|
-
this.layer[
|
|
4048
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintY);
|
|
4129
4049
|
this._private_constraintY = undefined;
|
|
4130
4050
|
}
|
|
4131
4051
|
if (this._private_constraintW) {
|
|
4132
|
-
this.layer[
|
|
4052
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintW);
|
|
4133
4053
|
this._private_constraintW = undefined;
|
|
4134
4054
|
}
|
|
4135
4055
|
if (this._private_constraintH) {
|
|
4136
|
-
this.layer[
|
|
4056
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintH);
|
|
4137
4057
|
this._private_constraintH = undefined;
|
|
4138
4058
|
}
|
|
4139
4059
|
if (this._private_constraintStrict) {
|
|
4140
|
-
this.layer[
|
|
4060
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintStrict);
|
|
4141
4061
|
this._private_constraintStrict = undefined;
|
|
4142
4062
|
}
|
|
4143
4063
|
}
|
|
@@ -4163,23 +4083,23 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4163
4083
|
*
|
|
4164
4084
|
* @param elementOne - The element or layer that contains the fitting element (the container)
|
|
4165
4085
|
* @param elementTwo - The element that will fit within the container
|
|
4166
|
-
* @param
|
|
4086
|
+
* @param options - Configuration options
|
|
4167
4087
|
*/
|
|
4168
|
-
constructor(_private_elementOne, _private_elementTwo,
|
|
4088
|
+
constructor(_private_elementOne, _private_elementTwo, options = {}) {
|
|
4169
4089
|
super(_private_elementTwo.layer, new Set(_private_elementOne instanceof UIElement
|
|
4170
4090
|
? [_private_elementOne, _private_elementTwo]
|
|
4171
4091
|
: [_private_elementTwo]));
|
|
4172
4092
|
this._private_elementOne = _private_elementOne;
|
|
4173
4093
|
this._private_elementTwo = _private_elementTwo;
|
|
4174
4094
|
assertSameLayer(_private_elementOne, _private_elementTwo);
|
|
4175
|
-
this.
|
|
4176
|
-
isStrict:
|
|
4177
|
-
horizontalAnchor:
|
|
4178
|
-
verticalAnchor:
|
|
4179
|
-
orientation: resolveOrientation(
|
|
4095
|
+
this._private_options = {
|
|
4096
|
+
isStrict: options.isStrict ?? true,
|
|
4097
|
+
horizontalAnchor: options.horizontalAnchor ?? DEFAULT_ANCHOR,
|
|
4098
|
+
verticalAnchor: options.verticalAnchor ?? DEFAULT_ANCHOR,
|
|
4099
|
+
orientation: resolveOrientation(options.orientation),
|
|
4180
4100
|
};
|
|
4181
|
-
if (this.
|
|
4182
|
-
this.
|
|
4101
|
+
if (this._private_options.orientation === UIOrientation.ALWAYS ||
|
|
4102
|
+
this._private_options.orientation === this.layer.orientation) {
|
|
4183
4103
|
this.buildConstraints();
|
|
4184
4104
|
}
|
|
4185
4105
|
}
|
|
@@ -4196,9 +4116,9 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4196
4116
|
* @param orientation - The new screen orientation
|
|
4197
4117
|
* @internal
|
|
4198
4118
|
*/
|
|
4199
|
-
[
|
|
4200
|
-
if (this.
|
|
4201
|
-
orientation !== this.
|
|
4119
|
+
["disableConstraintInternal"](orientation) {
|
|
4120
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
4121
|
+
orientation !== this._private_options.orientation) {
|
|
4202
4122
|
this.destroyConstraints();
|
|
4203
4123
|
}
|
|
4204
4124
|
}
|
|
@@ -4208,9 +4128,9 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4208
4128
|
* @param orientation - The new screen orientation
|
|
4209
4129
|
* @internal
|
|
4210
4130
|
*/
|
|
4211
|
-
[
|
|
4212
|
-
if (this.
|
|
4213
|
-
orientation === this.
|
|
4131
|
+
["enableConstraintInternal"](orientation) {
|
|
4132
|
+
if (this._private_options.orientation !== UIOrientation.ALWAYS &&
|
|
4133
|
+
orientation === this._private_options.orientation) {
|
|
4214
4134
|
this.buildConstraints();
|
|
4215
4135
|
}
|
|
4216
4136
|
}
|
|
@@ -4226,17 +4146,17 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4226
4146
|
*
|
|
4227
4147
|
*/
|
|
4228
4148
|
buildConstraints() {
|
|
4229
|
-
this._private_constraintX = new Constraint(new Expression(this._private_elementOne[
|
|
4230
|
-
this._private_constraintY = new Constraint(new Expression(this._private_elementOne[
|
|
4231
|
-
this._private_constraintW = new Constraint(new Expression(this._private_elementOne[
|
|
4232
|
-
this._private_constraintH = new Constraint(new Expression(this._private_elementOne[
|
|
4233
|
-
this.layer[
|
|
4234
|
-
this.layer[
|
|
4235
|
-
this.layer[
|
|
4236
|
-
this.layer[
|
|
4237
|
-
if (this.
|
|
4238
|
-
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne[
|
|
4239
|
-
this.layer[
|
|
4149
|
+
this._private_constraintX = new Constraint(new Expression(this._private_elementOne["xInternal"]).plus(new Expression(this._private_elementOne["widthInternal"]).multiply(this._private_options.horizontalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["xInternal"]).plus(new Expression(this._private_elementTwo["widthInternal"]).multiply(this._private_options.horizontalAnchor)));
|
|
4150
|
+
this._private_constraintY = new Constraint(new Expression(this._private_elementOne["yInternal"]).plus(new Expression(this._private_elementOne["heightInternal"]).multiply(this._private_options.verticalAnchor)), Operator.Eq, new Expression(this._private_elementTwo["yInternal"]).plus(new Expression(this._private_elementTwo["heightInternal"]).multiply(this._private_options.verticalAnchor)));
|
|
4151
|
+
this._private_constraintW = new Constraint(new Expression(this._private_elementOne["widthInternal"]), Operator.Ge, new Expression(this._private_elementTwo["widthInternal"]));
|
|
4152
|
+
this._private_constraintH = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Ge, new Expression(this._private_elementTwo["heightInternal"]));
|
|
4153
|
+
this.layer["addConstraintInternal"](this, this._private_constraintX);
|
|
4154
|
+
this.layer["addConstraintInternal"](this, this._private_constraintY);
|
|
4155
|
+
this.layer["addConstraintInternal"](this, this._private_constraintW);
|
|
4156
|
+
this.layer["addConstraintInternal"](this, this._private_constraintH);
|
|
4157
|
+
if (this._private_options.isStrict) {
|
|
4158
|
+
this._private_constraintStrict = new Constraint(new Expression(this._private_elementOne["heightInternal"]), Operator.Eq, new Expression(this._private_elementTwo["heightInternal"]), Strength.strong);
|
|
4159
|
+
this.layer["addConstraintInternal"](this, this._private_constraintStrict);
|
|
4240
4160
|
}
|
|
4241
4161
|
}
|
|
4242
4162
|
/**
|
|
@@ -4245,23 +4165,23 @@ class UIFitConstraint extends UIConstraint {
|
|
|
4245
4165
|
*/
|
|
4246
4166
|
destroyConstraints() {
|
|
4247
4167
|
if (this._private_constraintX) {
|
|
4248
|
-
this.layer[
|
|
4168
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintX);
|
|
4249
4169
|
this._private_constraintX = undefined;
|
|
4250
4170
|
}
|
|
4251
4171
|
if (this._private_constraintY) {
|
|
4252
|
-
this.layer[
|
|
4172
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintY);
|
|
4253
4173
|
this._private_constraintY = undefined;
|
|
4254
4174
|
}
|
|
4255
4175
|
if (this._private_constraintW) {
|
|
4256
|
-
this.layer[
|
|
4176
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintW);
|
|
4257
4177
|
this._private_constraintW = undefined;
|
|
4258
4178
|
}
|
|
4259
4179
|
if (this._private_constraintH) {
|
|
4260
|
-
this.layer[
|
|
4180
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintH);
|
|
4261
4181
|
this._private_constraintH = undefined;
|
|
4262
4182
|
}
|
|
4263
4183
|
if (this._private_constraintStrict) {
|
|
4264
|
-
this.layer[
|
|
4184
|
+
this.layer["removeConstraintInternal"](this, this._private_constraintStrict);
|
|
4265
4185
|
this._private_constraintStrict = undefined;
|
|
4266
4186
|
}
|
|
4267
4187
|
}
|
|
@@ -4996,7 +4916,7 @@ function resolveTextStyle(currentStyle, baseStyle) {
|
|
|
4996
4916
|
};
|
|
4997
4917
|
}
|
|
4998
4918
|
function splitText(text) {
|
|
4999
|
-
return text.match(/\S+|\s|\n/g)
|
|
4919
|
+
return text.match(/\S+|\s|\n/g) ?? [];
|
|
5000
4920
|
}
|
|
5001
4921
|
function measureTextChunk(context, chunk, style) {
|
|
5002
4922
|
context.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize}px ${style.fontFamily}`;
|
|
@@ -5141,10 +5061,10 @@ class UIText extends UIElement {
|
|
|
5141
5061
|
*
|
|
5142
5062
|
* @param layer - The UI layer that contains this element
|
|
5143
5063
|
* @param spans - Text content to display, either as a string, text span, or array of text spans/strings
|
|
5144
|
-
* @param
|
|
5064
|
+
* @param options - Options to customize the text rendering
|
|
5145
5065
|
* @throws Error if canvas context creation fails
|
|
5146
5066
|
*/
|
|
5147
|
-
constructor(layer, spans,
|
|
5067
|
+
constructor(layer, spans, options = {}) {
|
|
5148
5068
|
const canvas = document.createElement("canvas");
|
|
5149
5069
|
const context = canvas.getContext("2d");
|
|
5150
5070
|
if (!context) {
|
|
@@ -5155,15 +5075,15 @@ class UIText extends UIElement {
|
|
|
5155
5075
|
for (const span of processedSpans) {
|
|
5156
5076
|
const isSpanString = typeof span === "string";
|
|
5157
5077
|
const spanText = isSpanString ? span : span.text;
|
|
5158
|
-
const style = resolveTextStyle(isSpanString ? undefined : span.style,
|
|
5078
|
+
const style = resolveTextStyle(isSpanString ? undefined : span.style, options.defaultStyle);
|
|
5159
5079
|
for (const text of splitText(spanText)) {
|
|
5160
5080
|
const metrics = measureTextChunk(context, text, style);
|
|
5161
5081
|
chunks.push({ text, style, metrics });
|
|
5162
5082
|
}
|
|
5163
5083
|
}
|
|
5164
|
-
const wrappedLines = wrapTextLines(
|
|
5084
|
+
const wrappedLines = wrapTextLines(options.maxWidth ?? DEFAULT_LINE_SIZE, chunks);
|
|
5165
5085
|
const textBlockSize = calculateTextBlockSize(wrappedLines);
|
|
5166
|
-
const padding = resolvePadding(
|
|
5086
|
+
const padding = resolvePadding(options.padding);
|
|
5167
5087
|
canvas.width = textBlockSize.width + padding.left + padding.right;
|
|
5168
5088
|
canvas.height = textBlockSize.height + padding.top + padding.bottom;
|
|
5169
5089
|
const texture = new CanvasTexture(canvas);
|
|
@@ -5308,5 +5228,5 @@ function isUITextSpan(obj) {
|
|
|
5308
5228
|
class UIPass {
|
|
5309
5229
|
}
|
|
5310
5230
|
|
|
5311
|
-
export { UIAnchor, UIAspectConstraint, UIBlending, UIConstraint, UIConstraint2DBuilder, UIConstraintContainerBuilder, UIConstraintContainerDirection, UIConstraintPower, UIConstraintRule, UIConstraintStackBuilder, UICoverConstraint, UIDummy, UIElement, UIElementEvent, UIFitConstraint, UIFullScreenLayer, UIFullScreenQuad, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UILayer, UILayerEvent, UIMode, UIOrientation, UIPass, UIProgress, UIScene, UISceneUpdateMode, UIText, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint,
|
|
5231
|
+
export { UIAnchor, UIAspectConstraint, UIBlending, UIConstraint, UIConstraint2DBuilder, UIConstraintContainerBuilder, UIConstraintContainerDirection, UIConstraintPower, UIConstraintRule, UIConstraintStackBuilder, UICoverConstraint, UIDummy, UIElement, UIElementEvent, UIFitConstraint, UIFullScreenLayer, UIFullScreenQuad, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UILayer, UILayerEvent, UIMode, UIOrientation, UIPass, UIProgress, UIScene, UISceneUpdateMode, UIText, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPowerToStrength, convertRuleToOperator, isUIConstraintPower, isUIConstraintRule, isUIOrientation, isUITextSpan, resolveOrientation, resolvePower, resolveRule };
|
|
5312
5232
|
//# sourceMappingURL=index.js.map
|