@mojir/lits 2.1.8 → 2.1.11
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/dist/cli/cli.js +565 -108
- package/dist/cli/reference/api.d.ts +4 -4
- package/dist/cli/reference/index.d.ts +10 -1
- package/dist/cli/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/dot.d.ts +1 -0
- package/dist/cli/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/getUnit.d.ts +2 -0
- package/dist/cli/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/length.d.ts +1 -0
- package/dist/cli/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/scale.d.ts +1 -0
- package/dist/cli/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/subtract.d.ts +1 -0
- package/dist/cli/src/tokenizer/operators.d.ts +2 -2
- package/dist/cli/src/typeGuards/annotatedArrays.d.ts +4 -0
- package/dist/cli/src/utils/index.d.ts +3 -2
- package/dist/index.esm.js +564 -107
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +564 -107
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +564 -107
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +4 -4
- package/dist/reference/index.d.ts +10 -1
- package/dist/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/dot.d.ts +1 -0
- package/dist/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/getUnit.d.ts +2 -0
- package/dist/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/length.d.ts +1 -0
- package/dist/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/scale.d.ts +1 -0
- package/dist/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/subtract.d.ts +1 -0
- package/dist/src/tokenizer/operators.d.ts +2 -2
- package/dist/src/typeGuards/annotatedArrays.d.ts +4 -0
- package/dist/src/utils/index.d.ts +3 -2
- package/dist/testFramework.esm.js +279 -82
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +279 -82
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -802,7 +802,7 @@ function deepEqual(a, b, sourceCodeInfo) {
|
|
|
802
802
|
if (a === b)
|
|
803
803
|
return true;
|
|
804
804
|
if (typeof a === 'number' && typeof b === 'number')
|
|
805
|
-
return
|
|
805
|
+
return approxEqual(a, b);
|
|
806
806
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
807
807
|
if (a.length !== b.length)
|
|
808
808
|
return false;
|
|
@@ -821,7 +821,7 @@ function deepEqual(a, b, sourceCodeInfo) {
|
|
|
821
821
|
return false;
|
|
822
822
|
for (var i = 0; i < aKeys.length; i += 1) {
|
|
823
823
|
var key = asString(aKeys[i], sourceCodeInfo);
|
|
824
|
-
if (!deepEqual(
|
|
824
|
+
if (!deepEqual(a[key], b[key], sourceCodeInfo))
|
|
825
825
|
return false;
|
|
826
826
|
}
|
|
827
827
|
return true;
|
|
@@ -891,9 +891,8 @@ function approxEqual(a, b, epsilon) {
|
|
|
891
891
|
// Use relative error for larger values
|
|
892
892
|
return diff / (absA + absB) < epsilon;
|
|
893
893
|
}
|
|
894
|
-
function approxZero(value
|
|
895
|
-
|
|
896
|
-
return Math.abs(value) < epsilon;
|
|
894
|
+
function approxZero(value) {
|
|
895
|
+
return Math.abs(value) < EPSILON;
|
|
897
896
|
}
|
|
898
897
|
|
|
899
898
|
// isArray not needed, use Array.isArary
|
|
@@ -2286,6 +2285,28 @@ function assertVector(vector, sourceCodeInfo) {
|
|
|
2286
2285
|
throw new LitsError("Expected a vector, but got ".concat(vector), sourceCodeInfo);
|
|
2287
2286
|
}
|
|
2288
2287
|
}
|
|
2288
|
+
function is2dVector(vector) {
|
|
2289
|
+
if (!isVector(vector)) {
|
|
2290
|
+
return false;
|
|
2291
|
+
}
|
|
2292
|
+
return vector.length === 2;
|
|
2293
|
+
}
|
|
2294
|
+
function assert2dVector(vector, sourceCodeInfo) {
|
|
2295
|
+
if (!is2dVector(vector)) {
|
|
2296
|
+
throw new LitsError("Expected a 2d vector, but got ".concat(vector), sourceCodeInfo);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
function is3dVector(vector) {
|
|
2300
|
+
if (!isVector(vector)) {
|
|
2301
|
+
return false;
|
|
2302
|
+
}
|
|
2303
|
+
return vector.length === 3;
|
|
2304
|
+
}
|
|
2305
|
+
function assert3dVector(vector, sourceCodeInfo) {
|
|
2306
|
+
if (!is3dVector(vector)) {
|
|
2307
|
+
throw new LitsError("Expected a 3d vector, but got ".concat(vector), sourceCodeInfo);
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2289
2310
|
function assertNonEmptyVector(vector, sourceCodeInfo) {
|
|
2290
2311
|
assertVector(vector, sourceCodeInfo);
|
|
2291
2312
|
if (vector.length === 0) {
|
|
@@ -2632,30 +2653,6 @@ var mathNormalExpression = {
|
|
|
2632
2653
|
},
|
|
2633
2654
|
paramCount: {},
|
|
2634
2655
|
},
|
|
2635
|
-
'~': {
|
|
2636
|
-
evaluate: function (params, sourceCodeInfo) {
|
|
2637
|
-
var _a;
|
|
2638
|
-
var _b = __read(getNumberVectorOrMatrixOperation([params[0], params[1]], sourceCodeInfo), 2), operation = _b[0], operands = _b[1];
|
|
2639
|
-
var eplsilon = (_a = params[2]) !== null && _a !== void 0 ? _a : 1e-10;
|
|
2640
|
-
assertNumber(eplsilon, sourceCodeInfo, { positive: true, finite: true });
|
|
2641
|
-
if (operation === 'number') {
|
|
2642
|
-
var _c = __read(operands, 2), first = _c[0], second = _c[1];
|
|
2643
|
-
return approxEqual(first, second, eplsilon);
|
|
2644
|
-
}
|
|
2645
|
-
else if (operation === 'vector') {
|
|
2646
|
-
var firstVector = operands[0];
|
|
2647
|
-
var secondVector_1 = operands[1];
|
|
2648
|
-
return firstVector.every(function (val, i) { return approxEqual(val, secondVector_1[i], eplsilon); });
|
|
2649
|
-
}
|
|
2650
|
-
else {
|
|
2651
|
-
var firstMatrix = operands[0];
|
|
2652
|
-
var secondMatrix_1 = operands[1];
|
|
2653
|
-
return firstMatrix.every(function (row, i) { return row.every(function (val, j) { return approxEqual(val, secondMatrix_1[i][j], eplsilon); }); });
|
|
2654
|
-
}
|
|
2655
|
-
},
|
|
2656
|
-
paramCount: { min: 2, max: 3 },
|
|
2657
|
-
aliases: ['≈'],
|
|
2658
|
-
},
|
|
2659
2656
|
'quot': {
|
|
2660
2657
|
evaluate: function (params, sourceCodeInfo) {
|
|
2661
2658
|
var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
|
|
@@ -2664,13 +2661,13 @@ var mathNormalExpression = {
|
|
|
2664
2661
|
}
|
|
2665
2662
|
else if (operation === 'vector') {
|
|
2666
2663
|
var firstVector = operands[0];
|
|
2667
|
-
var
|
|
2668
|
-
return firstVector.map(function (val, i) { return Math.trunc(val /
|
|
2664
|
+
var secondVector_1 = operands[1];
|
|
2665
|
+
return firstVector.map(function (val, i) { return Math.trunc(val / secondVector_1[i]); });
|
|
2669
2666
|
}
|
|
2670
2667
|
else {
|
|
2671
2668
|
var firstMatrix = operands[0];
|
|
2672
|
-
var
|
|
2673
|
-
return firstMatrix.map(function (row, i) { return row.map(function (val, j) { return Math.trunc(val /
|
|
2669
|
+
var secondMatrix_1 = operands[1];
|
|
2670
|
+
return firstMatrix.map(function (row, i) { return row.map(function (val, j) { return Math.trunc(val / secondMatrix_1[i][j]); }); });
|
|
2674
2671
|
}
|
|
2675
2672
|
},
|
|
2676
2673
|
paramCount: 2,
|
|
@@ -2684,19 +2681,19 @@ var mathNormalExpression = {
|
|
|
2684
2681
|
}
|
|
2685
2682
|
else if (operation === 'vector') {
|
|
2686
2683
|
var firstVector = operands[0];
|
|
2687
|
-
var
|
|
2684
|
+
var secondVector_2 = operands[1];
|
|
2688
2685
|
return firstVector.map(function (dividend, i) {
|
|
2689
|
-
var divisor =
|
|
2686
|
+
var divisor = secondVector_2[i];
|
|
2690
2687
|
var quotient = Math.floor(dividend / divisor);
|
|
2691
2688
|
return dividend - divisor * quotient;
|
|
2692
2689
|
});
|
|
2693
2690
|
}
|
|
2694
2691
|
else {
|
|
2695
2692
|
var firstMatrix = operands[0];
|
|
2696
|
-
var
|
|
2693
|
+
var secondMatrix_2 = operands[1];
|
|
2697
2694
|
return firstMatrix.map(function (row, i) { return row.map(function (val, j) {
|
|
2698
|
-
var quotient = Math.floor(val /
|
|
2699
|
-
return val -
|
|
2695
|
+
var quotient = Math.floor(val / secondMatrix_2[i][j]);
|
|
2696
|
+
return val - secondMatrix_2[i][j] * quotient;
|
|
2700
2697
|
}); });
|
|
2701
2698
|
}
|
|
2702
2699
|
},
|
|
@@ -2710,13 +2707,13 @@ var mathNormalExpression = {
|
|
|
2710
2707
|
}
|
|
2711
2708
|
else if (operation === 'vector') {
|
|
2712
2709
|
var firstVector = operands[0];
|
|
2713
|
-
var
|
|
2714
|
-
return firstVector.map(function (dividend, i) { return dividend %
|
|
2710
|
+
var secondVector_3 = operands[1];
|
|
2711
|
+
return firstVector.map(function (dividend, i) { return dividend % secondVector_3[i]; });
|
|
2715
2712
|
}
|
|
2716
2713
|
else {
|
|
2717
2714
|
var firstMatrix = operands[0];
|
|
2718
|
-
var
|
|
2719
|
-
return firstMatrix.map(function (row, i) { return row.map(function (dividend, j) { return dividend %
|
|
2715
|
+
var secondMatrix_3 = operands[1];
|
|
2716
|
+
return firstMatrix.map(function (row, i) { return row.map(function (dividend, j) { return dividend % secondMatrix_3[i][j]; }); });
|
|
2720
2717
|
}
|
|
2721
2718
|
},
|
|
2722
2719
|
paramCount: 2,
|
|
@@ -2766,13 +2763,13 @@ var mathNormalExpression = {
|
|
|
2766
2763
|
}
|
|
2767
2764
|
else if (operation === 'vector') {
|
|
2768
2765
|
var firstVector = operands[0];
|
|
2769
|
-
var
|
|
2770
|
-
return firstVector.map(function (base, i) { return Math.pow(base,
|
|
2766
|
+
var secondVector_4 = operands[1];
|
|
2767
|
+
return firstVector.map(function (base, i) { return Math.pow(base, secondVector_4[i]); });
|
|
2771
2768
|
}
|
|
2772
2769
|
else {
|
|
2773
2770
|
var firstMatrix = operands[0];
|
|
2774
|
-
var
|
|
2775
|
-
return firstMatrix.map(function (row, i) { return row.map(function (base, j) { return Math.pow(base,
|
|
2771
|
+
var secondMatrix_4 = operands[1];
|
|
2772
|
+
return firstMatrix.map(function (row, i) { return row.map(function (base, j) { return Math.pow(base, secondMatrix_4[i][j]); }); });
|
|
2776
2773
|
}
|
|
2777
2774
|
},
|
|
2778
2775
|
paramCount: 2,
|
|
@@ -3184,6 +3181,40 @@ var mathNormalExpression = {
|
|
|
3184
3181
|
},
|
|
3185
3182
|
paramCount: 1,
|
|
3186
3183
|
},
|
|
3184
|
+
'to-rad': {
|
|
3185
|
+
evaluate: function (params, sourceCodeInfo) {
|
|
3186
|
+
var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
|
|
3187
|
+
if (operation === 'number') {
|
|
3188
|
+
return (operands[0] * Math.PI) / 180;
|
|
3189
|
+
}
|
|
3190
|
+
else if (operation === 'vector') {
|
|
3191
|
+
var vector = operands[0];
|
|
3192
|
+
return vector.map(function (val) { return (val * Math.PI) / 180; });
|
|
3193
|
+
}
|
|
3194
|
+
else {
|
|
3195
|
+
var matrix = operands[0];
|
|
3196
|
+
return matrix.map(function (row) { return row.map(function (val) { return (val * Math.PI) / 180; }); });
|
|
3197
|
+
}
|
|
3198
|
+
},
|
|
3199
|
+
paramCount: 1,
|
|
3200
|
+
},
|
|
3201
|
+
'to-deg': {
|
|
3202
|
+
evaluate: function (params, sourceCodeInfo) {
|
|
3203
|
+
var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
|
|
3204
|
+
if (operation === 'number') {
|
|
3205
|
+
return (operands[0] * 180) / Math.PI;
|
|
3206
|
+
}
|
|
3207
|
+
else if (operation === 'vector') {
|
|
3208
|
+
var vector = operands[0];
|
|
3209
|
+
return vector.map(function (val) { return (val * 180) / Math.PI; });
|
|
3210
|
+
}
|
|
3211
|
+
else {
|
|
3212
|
+
var matrix = operands[0];
|
|
3213
|
+
return matrix.map(function (row) { return row.map(function (val) { return (val * 180) / Math.PI; }); });
|
|
3214
|
+
}
|
|
3215
|
+
},
|
|
3216
|
+
paramCount: 1,
|
|
3217
|
+
},
|
|
3187
3218
|
};
|
|
3188
3219
|
|
|
3189
3220
|
function isEqual(_a, sourceCodeInfo) {
|
|
@@ -3803,9 +3834,9 @@ var predicatesNormalExpression = {
|
|
|
3803
3834
|
},
|
|
3804
3835
|
'zero?': {
|
|
3805
3836
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3806
|
-
var _b = __read(_a, 1),
|
|
3807
|
-
assertNumber(
|
|
3808
|
-
return
|
|
3837
|
+
var _b = __read(_a, 1), value = _b[0];
|
|
3838
|
+
assertNumber(value, sourceCodeInfo, { finite: true });
|
|
3839
|
+
return Math.abs(value) < EPSILON;
|
|
3809
3840
|
},
|
|
3810
3841
|
paramCount: 1,
|
|
3811
3842
|
},
|
|
@@ -4666,6 +4697,24 @@ var gridNormalExpression = {
|
|
|
4666
4697
|
},
|
|
4667
4698
|
paramCount: 1,
|
|
4668
4699
|
},
|
|
4700
|
+
'grid:fill': {
|
|
4701
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
4702
|
+
var _b = __read(_a, 3), rows = _b[0], cols = _b[1], value = _b[2];
|
|
4703
|
+
assertNumber(rows, sourceCodeInfo, { integer: true, positive: true });
|
|
4704
|
+
assertNumber(cols, sourceCodeInfo, { integer: true, positive: true });
|
|
4705
|
+
assertAny(value, sourceCodeInfo);
|
|
4706
|
+
var result = [];
|
|
4707
|
+
for (var i = 0; i < rows; i += 1) {
|
|
4708
|
+
var row = [];
|
|
4709
|
+
for (var j = 0; j < cols; j += 1) {
|
|
4710
|
+
row.push(value);
|
|
4711
|
+
}
|
|
4712
|
+
result.push(row);
|
|
4713
|
+
}
|
|
4714
|
+
return result;
|
|
4715
|
+
},
|
|
4716
|
+
paramCount: 3,
|
|
4717
|
+
},
|
|
4669
4718
|
'grid:generate': {
|
|
4670
4719
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4671
4720
|
var _c = __read(_a, 3), rows = _c[0], cols = _c[1], generator = _c[2];
|
|
@@ -6610,7 +6659,141 @@ function extractOverlappingSegments(vectorA, vectorB, lag) {
|
|
|
6610
6659
|
return [segmentA, segmentB];
|
|
6611
6660
|
}
|
|
6612
6661
|
|
|
6662
|
+
function getUnit(value, sourceCodeInfo) {
|
|
6663
|
+
if (value.length === 0) {
|
|
6664
|
+
return value;
|
|
6665
|
+
}
|
|
6666
|
+
var length = Math.sqrt(value.reduce(function (acc, item) { return acc + Math.pow(item, 2); }, 0));
|
|
6667
|
+
if (approxZero(length)) {
|
|
6668
|
+
throw new LitsError('The vector must not be zero', sourceCodeInfo);
|
|
6669
|
+
}
|
|
6670
|
+
return value.map(function (item) { return item / length; });
|
|
6671
|
+
}
|
|
6672
|
+
|
|
6673
|
+
function dot(vector1, vector2) {
|
|
6674
|
+
return vector1.reduce(function (acc, item, index) { return acc + item * vector2[index]; }, 0);
|
|
6675
|
+
}
|
|
6676
|
+
|
|
6677
|
+
function subtract(vector1, vector2) {
|
|
6678
|
+
return vector1.map(function (item, index) { return item - vector2[index]; });
|
|
6679
|
+
}
|
|
6680
|
+
|
|
6681
|
+
function scale(vector, scalar) {
|
|
6682
|
+
return vector.map(function (item) { return item * scalar; });
|
|
6683
|
+
}
|
|
6684
|
+
|
|
6685
|
+
function length(vector) {
|
|
6686
|
+
return Math.sqrt(vector.reduce(function (acc, item) { return acc + Math.pow(item, 2); }, 0));
|
|
6687
|
+
}
|
|
6688
|
+
|
|
6613
6689
|
var linearAlgebraNormalExpression = {
|
|
6690
|
+
'lin:rotate2d': {
|
|
6691
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6692
|
+
var _b = __read(_a, 2), vector = _b[0], radians = _b[1];
|
|
6693
|
+
assert2dVector(vector, sourceCodeInfo);
|
|
6694
|
+
if (isZeroVector(vector)) {
|
|
6695
|
+
return vector;
|
|
6696
|
+
}
|
|
6697
|
+
assertNumber(radians, sourceCodeInfo, { finite: true });
|
|
6698
|
+
var cosTheta = Math.cos(radians);
|
|
6699
|
+
var sinTheta = Math.sin(radians);
|
|
6700
|
+
return [
|
|
6701
|
+
vector[0] * cosTheta - vector[1] * sinTheta,
|
|
6702
|
+
vector[0] * sinTheta + vector[1] * cosTheta,
|
|
6703
|
+
];
|
|
6704
|
+
},
|
|
6705
|
+
paramCount: 2,
|
|
6706
|
+
},
|
|
6707
|
+
'lin:rotate3d': {
|
|
6708
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6709
|
+
var _b = __read(_a, 3), vector = _b[0], axis = _b[1], radians = _b[2];
|
|
6710
|
+
assert3dVector(vector, sourceCodeInfo);
|
|
6711
|
+
if (isZeroVector(vector)) {
|
|
6712
|
+
return vector;
|
|
6713
|
+
}
|
|
6714
|
+
assertNumber(radians, sourceCodeInfo, { finite: true });
|
|
6715
|
+
assert3dVector(axis, sourceCodeInfo);
|
|
6716
|
+
if (isZeroVector(axis)) {
|
|
6717
|
+
throw new LitsError('Rotation axis must not be zero', sourceCodeInfo);
|
|
6718
|
+
}
|
|
6719
|
+
var cosTheta = Math.cos(radians);
|
|
6720
|
+
var sinTheta = Math.sin(radians);
|
|
6721
|
+
var _c = __read(getUnit(axis, sourceCodeInfo), 3), u = _c[0], v = _c[1], w = _c[2];
|
|
6722
|
+
var dotProduct = vector[0] * u + vector[1] * v + vector[2] * w;
|
|
6723
|
+
return [
|
|
6724
|
+
dotProduct * u * (1 - cosTheta) + vector[0] * cosTheta + (-w * vector[1] + v * vector[2]) * sinTheta,
|
|
6725
|
+
dotProduct * v * (1 - cosTheta) + vector[1] * cosTheta + (w * vector[0] - u * vector[2]) * sinTheta,
|
|
6726
|
+
dotProduct * w * (1 - cosTheta) + vector[2] * cosTheta + (-v * vector[0] + u * vector[1]) * sinTheta,
|
|
6727
|
+
];
|
|
6728
|
+
},
|
|
6729
|
+
paramCount: 3,
|
|
6730
|
+
},
|
|
6731
|
+
'lin:reflect': {
|
|
6732
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6733
|
+
var _b = __read(_a, 2), vector = _b[0], normal = _b[1];
|
|
6734
|
+
assertVector(vector, sourceCodeInfo);
|
|
6735
|
+
assertVector(normal, sourceCodeInfo);
|
|
6736
|
+
if (vector.length !== normal.length) {
|
|
6737
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6738
|
+
}
|
|
6739
|
+
if (isZeroVector(normal)) {
|
|
6740
|
+
throw new LitsError('Reflection normal must not be zero', sourceCodeInfo);
|
|
6741
|
+
}
|
|
6742
|
+
if (isZeroVector(vector)) {
|
|
6743
|
+
return vector;
|
|
6744
|
+
}
|
|
6745
|
+
var unitNormal = getUnit(normal, sourceCodeInfo);
|
|
6746
|
+
var doubleDot = 2 * dot(vector, unitNormal);
|
|
6747
|
+
return subtract(vector, scale(unitNormal, doubleDot));
|
|
6748
|
+
},
|
|
6749
|
+
paramCount: 2,
|
|
6750
|
+
},
|
|
6751
|
+
'lin:refract': {
|
|
6752
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6753
|
+
var _b = __read(_a, 3), vector = _b[0], normal = _b[1], eta = _b[2];
|
|
6754
|
+
assertVector(vector, sourceCodeInfo);
|
|
6755
|
+
assertVector(normal, sourceCodeInfo);
|
|
6756
|
+
assertNumber(eta, sourceCodeInfo, { finite: true, positive: true });
|
|
6757
|
+
if (vector.length !== normal.length) {
|
|
6758
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6759
|
+
}
|
|
6760
|
+
if (isZeroVector(normal)) {
|
|
6761
|
+
throw new LitsError('Refraction normal must not be zero', sourceCodeInfo);
|
|
6762
|
+
}
|
|
6763
|
+
if (isZeroVector(vector)) {
|
|
6764
|
+
return vector;
|
|
6765
|
+
}
|
|
6766
|
+
// Make sure vectors are normalized
|
|
6767
|
+
var normalizedV = getUnit(vector, sourceCodeInfo);
|
|
6768
|
+
var normalizedNormal = getUnit(normal, sourceCodeInfo);
|
|
6769
|
+
// Calculate dot product between incident vector and normal
|
|
6770
|
+
var dotProduct = dot(normalizedV, normalizedNormal);
|
|
6771
|
+
// Calculate discriminant
|
|
6772
|
+
var discriminant = 1 - eta * eta * (1 - dotProduct * dotProduct);
|
|
6773
|
+
// Check for total internal reflection
|
|
6774
|
+
if (discriminant < 0) {
|
|
6775
|
+
return vector; // Total internal reflection occurs
|
|
6776
|
+
}
|
|
6777
|
+
// Calculate the refracted vector
|
|
6778
|
+
var scaledIncident = scale(normalizedV, eta);
|
|
6779
|
+
var scaledNormal = scale(normalizedNormal, eta * dotProduct + Math.sqrt(discriminant));
|
|
6780
|
+
return subtract(scaledIncident, scaledNormal);
|
|
6781
|
+
},
|
|
6782
|
+
paramCount: 3,
|
|
6783
|
+
},
|
|
6784
|
+
'lin:lerp': {
|
|
6785
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6786
|
+
var _b = __read(_a, 3), vectorA = _b[0], vectorB = _b[1], t = _b[2];
|
|
6787
|
+
assertVector(vectorA, sourceCodeInfo);
|
|
6788
|
+
assertVector(vectorB, sourceCodeInfo);
|
|
6789
|
+
assertNumber(t, sourceCodeInfo, { finite: true });
|
|
6790
|
+
if (vectorA.length !== vectorB.length) {
|
|
6791
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6792
|
+
}
|
|
6793
|
+
return vectorA.map(function (val, i) { return val + (vectorB[i] - val) * t; });
|
|
6794
|
+
},
|
|
6795
|
+
paramCount: 3,
|
|
6796
|
+
},
|
|
6614
6797
|
'lin:dot': {
|
|
6615
6798
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6616
6799
|
var _b = __read(_a, 2), vectorA = _b[0], vectorB = _b[1];
|
|
@@ -6619,7 +6802,7 @@ var linearAlgebraNormalExpression = {
|
|
|
6619
6802
|
if (vectorA.length !== vectorB.length) {
|
|
6620
6803
|
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6621
6804
|
}
|
|
6622
|
-
return vectorA
|
|
6805
|
+
return dot(vectorA, vectorB);
|
|
6623
6806
|
},
|
|
6624
6807
|
paramCount: 2,
|
|
6625
6808
|
},
|
|
@@ -6700,16 +6883,10 @@ var linearAlgebraNormalExpression = {
|
|
|
6700
6883
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6701
6884
|
var _b = __read(_a, 1), vector = _b[0];
|
|
6702
6885
|
assertVector(vector, sourceCodeInfo);
|
|
6703
|
-
|
|
6704
|
-
return [];
|
|
6705
|
-
}
|
|
6706
|
-
var norm = Math.sqrt(vector.reduce(function (acc, val) { return acc + Math.pow(val, 2); }, 0));
|
|
6707
|
-
if (norm === 0) {
|
|
6708
|
-
return vector.map(function () { return 0; });
|
|
6709
|
-
}
|
|
6710
|
-
return vector.map(function (val) { return val / norm; });
|
|
6886
|
+
return getUnit(vector, sourceCodeInfo);
|
|
6711
6887
|
},
|
|
6712
6888
|
paramCount: 1,
|
|
6889
|
+
aliases: ['lin:unit', 'lin:normalize'],
|
|
6713
6890
|
},
|
|
6714
6891
|
'lin:normalize-log': {
|
|
6715
6892
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -6833,10 +7010,10 @@ var linearAlgebraNormalExpression = {
|
|
|
6833
7010
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6834
7011
|
var _b = __read(_a, 1), vector = _b[0];
|
|
6835
7012
|
assertNonEmptyVector(vector, sourceCodeInfo);
|
|
6836
|
-
return
|
|
7013
|
+
return length(vector);
|
|
6837
7014
|
},
|
|
6838
7015
|
paramCount: 1,
|
|
6839
|
-
aliases: ['lin:l2-norm', 'lin:
|
|
7016
|
+
aliases: ['lin:l2-norm', 'lin:length'],
|
|
6840
7017
|
},
|
|
6841
7018
|
'lin:manhattan-distance': {
|
|
6842
7019
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -7139,6 +7316,31 @@ var linearAlgebraNormalExpression = {
|
|
|
7139
7316
|
},
|
|
7140
7317
|
paramCount: 2,
|
|
7141
7318
|
},
|
|
7319
|
+
'lin:to-polar': {
|
|
7320
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
7321
|
+
var _b = __read(_a, 1), vector = _b[0];
|
|
7322
|
+
assert2dVector(vector, sourceCodeInfo);
|
|
7323
|
+
if (isZeroVector(vector)) {
|
|
7324
|
+
return [0, 0];
|
|
7325
|
+
}
|
|
7326
|
+
var r = Math.sqrt(Math.pow(vector[0], 2) + Math.pow(vector[1], 2));
|
|
7327
|
+
var theta = Math.atan2(vector[1], vector[0]);
|
|
7328
|
+
return [r, theta];
|
|
7329
|
+
},
|
|
7330
|
+
paramCount: 1,
|
|
7331
|
+
},
|
|
7332
|
+
'lin:from-polar': {
|
|
7333
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
7334
|
+
var _b = __read(_a, 1), polar = _b[0];
|
|
7335
|
+
assert2dVector(polar, sourceCodeInfo);
|
|
7336
|
+
var _c = __read(polar, 2), r = _c[0], theta = _c[1];
|
|
7337
|
+
if (r === 0) {
|
|
7338
|
+
return [0, 0];
|
|
7339
|
+
}
|
|
7340
|
+
return [r * Math.cos(theta), r * Math.sin(theta)];
|
|
7341
|
+
},
|
|
7342
|
+
paramCount: 1,
|
|
7343
|
+
},
|
|
7142
7344
|
};
|
|
7143
7345
|
|
|
7144
7346
|
/**
|
|
@@ -12306,6 +12508,7 @@ function evaluateReservedSymbol(node) {
|
|
|
12306
12508
|
return asNonUndefined(value, node[2]);
|
|
12307
12509
|
}
|
|
12308
12510
|
function evaluateNormalExpression(node, contextStack) {
|
|
12511
|
+
var _a, _b;
|
|
12309
12512
|
var sourceCodeInfo = node[2];
|
|
12310
12513
|
var paramNodes = node[1][1];
|
|
12311
12514
|
var params = [];
|
|
@@ -12331,14 +12534,14 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12331
12534
|
var nameSymbol = node[1][0];
|
|
12332
12535
|
if (placeholders.length > 0) {
|
|
12333
12536
|
var fn = evaluateNode(nameSymbol, contextStack);
|
|
12334
|
-
var partialFunction = {
|
|
12335
|
-
|
|
12336
|
-
|
|
12337
|
-
|
|
12338
|
-
params
|
|
12339
|
-
placeholders
|
|
12340
|
-
sourceCodeInfo
|
|
12341
|
-
|
|
12537
|
+
var partialFunction = (_a = {},
|
|
12538
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
12539
|
+
_a.function = asFunctionLike(fn, sourceCodeInfo),
|
|
12540
|
+
_a.functionType = 'Partial',
|
|
12541
|
+
_a.params = params,
|
|
12542
|
+
_a.placeholders = placeholders,
|
|
12543
|
+
_a.sourceCodeInfo = sourceCodeInfo,
|
|
12544
|
+
_a);
|
|
12342
12545
|
return partialFunction;
|
|
12343
12546
|
}
|
|
12344
12547
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -12358,14 +12561,14 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12358
12561
|
var fnNode = node[1][0];
|
|
12359
12562
|
var fn = asFunctionLike(evaluateNode(fnNode, contextStack), sourceCodeInfo);
|
|
12360
12563
|
if (placeholders.length > 0) {
|
|
12361
|
-
var partialFunction = {
|
|
12362
|
-
|
|
12363
|
-
|
|
12364
|
-
|
|
12365
|
-
params
|
|
12366
|
-
placeholders
|
|
12367
|
-
sourceCodeInfo
|
|
12368
|
-
|
|
12564
|
+
var partialFunction = (_b = {},
|
|
12565
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
12566
|
+
_b.function = asFunctionLike(fn, sourceCodeInfo),
|
|
12567
|
+
_b.functionType = 'Partial',
|
|
12568
|
+
_b.params = params,
|
|
12569
|
+
_b.placeholders = placeholders,
|
|
12570
|
+
_b.sourceCodeInfo = sourceCodeInfo,
|
|
12571
|
+
_b);
|
|
12369
12572
|
return partialFunction;
|
|
12370
12573
|
}
|
|
12371
12574
|
return executeFunction(fn, params, contextStack, sourceCodeInfo);
|
|
@@ -12665,8 +12868,6 @@ var binaryOperators = [
|
|
|
12665
12868
|
'=', // equal
|
|
12666
12869
|
'!=', // not equal
|
|
12667
12870
|
'≠', // not equal
|
|
12668
|
-
'~', // approximate
|
|
12669
|
-
'≈', // approximate
|
|
12670
12871
|
'&', // bitwise AND
|
|
12671
12872
|
'xor', // bitwise XOR
|
|
12672
12873
|
'|', // bitwise OR
|
|
@@ -13309,8 +13510,6 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13309
13510
|
case '=': // equal
|
|
13310
13511
|
case '!=': // not equal
|
|
13311
13512
|
case '≠': // not equal
|
|
13312
|
-
case '~': // approximate
|
|
13313
|
-
case '≈': // approximate
|
|
13314
13513
|
return 5;
|
|
13315
13514
|
case '&': // bitwise AND
|
|
13316
13515
|
case 'xor': // bitwise XOR
|
|
@@ -13364,8 +13563,6 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13364
13563
|
case '&':
|
|
13365
13564
|
case 'xor':
|
|
13366
13565
|
case '|':
|
|
13367
|
-
case '~':
|
|
13368
|
-
case '≈':
|
|
13369
13566
|
case '|>':
|
|
13370
13567
|
return createNamedNormalExpressionNode(symbolNode, [left, right], sourceCodeInfo);
|
|
13371
13568
|
case '&&':
|