@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
package/dist/cli/cli.js
CHANGED
|
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
92
92
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
var version = "2.1.
|
|
95
|
+
var version = "2.1.11";
|
|
96
96
|
|
|
97
97
|
function getCodeMarker(sourceCodeInfo) {
|
|
98
98
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -824,7 +824,7 @@ function deepEqual(a, b, sourceCodeInfo) {
|
|
|
824
824
|
if (a === b)
|
|
825
825
|
return true;
|
|
826
826
|
if (typeof a === 'number' && typeof b === 'number')
|
|
827
|
-
return
|
|
827
|
+
return approxEqual(a, b);
|
|
828
828
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
829
829
|
if (a.length !== b.length)
|
|
830
830
|
return false;
|
|
@@ -843,7 +843,7 @@ function deepEqual(a, b, sourceCodeInfo) {
|
|
|
843
843
|
return false;
|
|
844
844
|
for (var i = 0; i < aKeys.length; i += 1) {
|
|
845
845
|
var key = asString(aKeys[i], sourceCodeInfo);
|
|
846
|
-
if (!deepEqual(
|
|
846
|
+
if (!deepEqual(a[key], b[key], sourceCodeInfo))
|
|
847
847
|
return false;
|
|
848
848
|
}
|
|
849
849
|
return true;
|
|
@@ -913,9 +913,8 @@ function approxEqual(a, b, epsilon) {
|
|
|
913
913
|
// Use relative error for larger values
|
|
914
914
|
return diff / (absA + absB) < epsilon;
|
|
915
915
|
}
|
|
916
|
-
function approxZero(value
|
|
917
|
-
|
|
918
|
-
return Math.abs(value) < epsilon;
|
|
916
|
+
function approxZero(value) {
|
|
917
|
+
return Math.abs(value) < EPSILON;
|
|
919
918
|
}
|
|
920
919
|
|
|
921
920
|
// isArray not needed, use Array.isArary
|
|
@@ -2308,6 +2307,28 @@ function assertVector(vector, sourceCodeInfo) {
|
|
|
2308
2307
|
throw new LitsError("Expected a vector, but got ".concat(vector), sourceCodeInfo);
|
|
2309
2308
|
}
|
|
2310
2309
|
}
|
|
2310
|
+
function is2dVector(vector) {
|
|
2311
|
+
if (!isVector(vector)) {
|
|
2312
|
+
return false;
|
|
2313
|
+
}
|
|
2314
|
+
return vector.length === 2;
|
|
2315
|
+
}
|
|
2316
|
+
function assert2dVector(vector, sourceCodeInfo) {
|
|
2317
|
+
if (!is2dVector(vector)) {
|
|
2318
|
+
throw new LitsError("Expected a 2d vector, but got ".concat(vector), sourceCodeInfo);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
function is3dVector(vector) {
|
|
2322
|
+
if (!isVector(vector)) {
|
|
2323
|
+
return false;
|
|
2324
|
+
}
|
|
2325
|
+
return vector.length === 3;
|
|
2326
|
+
}
|
|
2327
|
+
function assert3dVector(vector, sourceCodeInfo) {
|
|
2328
|
+
if (!is3dVector(vector)) {
|
|
2329
|
+
throw new LitsError("Expected a 3d vector, but got ".concat(vector), sourceCodeInfo);
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2311
2332
|
function assertNonEmptyVector(vector, sourceCodeInfo) {
|
|
2312
2333
|
assertVector(vector, sourceCodeInfo);
|
|
2313
2334
|
if (vector.length === 0) {
|
|
@@ -2654,30 +2675,6 @@ var mathNormalExpression = {
|
|
|
2654
2675
|
},
|
|
2655
2676
|
paramCount: {},
|
|
2656
2677
|
},
|
|
2657
|
-
'~': {
|
|
2658
|
-
evaluate: function (params, sourceCodeInfo) {
|
|
2659
|
-
var _a;
|
|
2660
|
-
var _b = __read(getNumberVectorOrMatrixOperation([params[0], params[1]], sourceCodeInfo), 2), operation = _b[0], operands = _b[1];
|
|
2661
|
-
var eplsilon = (_a = params[2]) !== null && _a !== void 0 ? _a : 1e-10;
|
|
2662
|
-
assertNumber(eplsilon, sourceCodeInfo, { positive: true, finite: true });
|
|
2663
|
-
if (operation === 'number') {
|
|
2664
|
-
var _c = __read(operands, 2), first = _c[0], second = _c[1];
|
|
2665
|
-
return approxEqual(first, second, eplsilon);
|
|
2666
|
-
}
|
|
2667
|
-
else if (operation === 'vector') {
|
|
2668
|
-
var firstVector = operands[0];
|
|
2669
|
-
var secondVector_1 = operands[1];
|
|
2670
|
-
return firstVector.every(function (val, i) { return approxEqual(val, secondVector_1[i], eplsilon); });
|
|
2671
|
-
}
|
|
2672
|
-
else {
|
|
2673
|
-
var firstMatrix = operands[0];
|
|
2674
|
-
var secondMatrix_1 = operands[1];
|
|
2675
|
-
return firstMatrix.every(function (row, i) { return row.every(function (val, j) { return approxEqual(val, secondMatrix_1[i][j], eplsilon); }); });
|
|
2676
|
-
}
|
|
2677
|
-
},
|
|
2678
|
-
paramCount: { min: 2, max: 3 },
|
|
2679
|
-
aliases: ['≈'],
|
|
2680
|
-
},
|
|
2681
2678
|
'quot': {
|
|
2682
2679
|
evaluate: function (params, sourceCodeInfo) {
|
|
2683
2680
|
var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
|
|
@@ -2686,13 +2683,13 @@ var mathNormalExpression = {
|
|
|
2686
2683
|
}
|
|
2687
2684
|
else if (operation === 'vector') {
|
|
2688
2685
|
var firstVector = operands[0];
|
|
2689
|
-
var
|
|
2690
|
-
return firstVector.map(function (val, i) { return Math.trunc(val /
|
|
2686
|
+
var secondVector_1 = operands[1];
|
|
2687
|
+
return firstVector.map(function (val, i) { return Math.trunc(val / secondVector_1[i]); });
|
|
2691
2688
|
}
|
|
2692
2689
|
else {
|
|
2693
2690
|
var firstMatrix = operands[0];
|
|
2694
|
-
var
|
|
2695
|
-
return firstMatrix.map(function (row, i) { return row.map(function (val, j) { return Math.trunc(val /
|
|
2691
|
+
var secondMatrix_1 = operands[1];
|
|
2692
|
+
return firstMatrix.map(function (row, i) { return row.map(function (val, j) { return Math.trunc(val / secondMatrix_1[i][j]); }); });
|
|
2696
2693
|
}
|
|
2697
2694
|
},
|
|
2698
2695
|
paramCount: 2,
|
|
@@ -2706,19 +2703,19 @@ var mathNormalExpression = {
|
|
|
2706
2703
|
}
|
|
2707
2704
|
else if (operation === 'vector') {
|
|
2708
2705
|
var firstVector = operands[0];
|
|
2709
|
-
var
|
|
2706
|
+
var secondVector_2 = operands[1];
|
|
2710
2707
|
return firstVector.map(function (dividend, i) {
|
|
2711
|
-
var divisor =
|
|
2708
|
+
var divisor = secondVector_2[i];
|
|
2712
2709
|
var quotient = Math.floor(dividend / divisor);
|
|
2713
2710
|
return dividend - divisor * quotient;
|
|
2714
2711
|
});
|
|
2715
2712
|
}
|
|
2716
2713
|
else {
|
|
2717
2714
|
var firstMatrix = operands[0];
|
|
2718
|
-
var
|
|
2715
|
+
var secondMatrix_2 = operands[1];
|
|
2719
2716
|
return firstMatrix.map(function (row, i) { return row.map(function (val, j) {
|
|
2720
|
-
var quotient = Math.floor(val /
|
|
2721
|
-
return val -
|
|
2717
|
+
var quotient = Math.floor(val / secondMatrix_2[i][j]);
|
|
2718
|
+
return val - secondMatrix_2[i][j] * quotient;
|
|
2722
2719
|
}); });
|
|
2723
2720
|
}
|
|
2724
2721
|
},
|
|
@@ -2732,13 +2729,13 @@ var mathNormalExpression = {
|
|
|
2732
2729
|
}
|
|
2733
2730
|
else if (operation === 'vector') {
|
|
2734
2731
|
var firstVector = operands[0];
|
|
2735
|
-
var
|
|
2736
|
-
return firstVector.map(function (dividend, i) { return dividend %
|
|
2732
|
+
var secondVector_3 = operands[1];
|
|
2733
|
+
return firstVector.map(function (dividend, i) { return dividend % secondVector_3[i]; });
|
|
2737
2734
|
}
|
|
2738
2735
|
else {
|
|
2739
2736
|
var firstMatrix = operands[0];
|
|
2740
|
-
var
|
|
2741
|
-
return firstMatrix.map(function (row, i) { return row.map(function (dividend, j) { return dividend %
|
|
2737
|
+
var secondMatrix_3 = operands[1];
|
|
2738
|
+
return firstMatrix.map(function (row, i) { return row.map(function (dividend, j) { return dividend % secondMatrix_3[i][j]; }); });
|
|
2742
2739
|
}
|
|
2743
2740
|
},
|
|
2744
2741
|
paramCount: 2,
|
|
@@ -2788,13 +2785,13 @@ var mathNormalExpression = {
|
|
|
2788
2785
|
}
|
|
2789
2786
|
else if (operation === 'vector') {
|
|
2790
2787
|
var firstVector = operands[0];
|
|
2791
|
-
var
|
|
2792
|
-
return firstVector.map(function (base, i) { return Math.pow(base,
|
|
2788
|
+
var secondVector_4 = operands[1];
|
|
2789
|
+
return firstVector.map(function (base, i) { return Math.pow(base, secondVector_4[i]); });
|
|
2793
2790
|
}
|
|
2794
2791
|
else {
|
|
2795
2792
|
var firstMatrix = operands[0];
|
|
2796
|
-
var
|
|
2797
|
-
return firstMatrix.map(function (row, i) { return row.map(function (base, j) { return Math.pow(base,
|
|
2793
|
+
var secondMatrix_4 = operands[1];
|
|
2794
|
+
return firstMatrix.map(function (row, i) { return row.map(function (base, j) { return Math.pow(base, secondMatrix_4[i][j]); }); });
|
|
2798
2795
|
}
|
|
2799
2796
|
},
|
|
2800
2797
|
paramCount: 2,
|
|
@@ -3206,6 +3203,40 @@ var mathNormalExpression = {
|
|
|
3206
3203
|
},
|
|
3207
3204
|
paramCount: 1,
|
|
3208
3205
|
},
|
|
3206
|
+
'to-rad': {
|
|
3207
|
+
evaluate: function (params, sourceCodeInfo) {
|
|
3208
|
+
var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
|
|
3209
|
+
if (operation === 'number') {
|
|
3210
|
+
return (operands[0] * Math.PI) / 180;
|
|
3211
|
+
}
|
|
3212
|
+
else if (operation === 'vector') {
|
|
3213
|
+
var vector = operands[0];
|
|
3214
|
+
return vector.map(function (val) { return (val * Math.PI) / 180; });
|
|
3215
|
+
}
|
|
3216
|
+
else {
|
|
3217
|
+
var matrix = operands[0];
|
|
3218
|
+
return matrix.map(function (row) { return row.map(function (val) { return (val * Math.PI) / 180; }); });
|
|
3219
|
+
}
|
|
3220
|
+
},
|
|
3221
|
+
paramCount: 1,
|
|
3222
|
+
},
|
|
3223
|
+
'to-deg': {
|
|
3224
|
+
evaluate: function (params, sourceCodeInfo) {
|
|
3225
|
+
var _a = __read(getNumberVectorOrMatrixOperation(params, sourceCodeInfo), 2), operation = _a[0], operands = _a[1];
|
|
3226
|
+
if (operation === 'number') {
|
|
3227
|
+
return (operands[0] * 180) / Math.PI;
|
|
3228
|
+
}
|
|
3229
|
+
else if (operation === 'vector') {
|
|
3230
|
+
var vector = operands[0];
|
|
3231
|
+
return vector.map(function (val) { return (val * 180) / Math.PI; });
|
|
3232
|
+
}
|
|
3233
|
+
else {
|
|
3234
|
+
var matrix = operands[0];
|
|
3235
|
+
return matrix.map(function (row) { return row.map(function (val) { return (val * 180) / Math.PI; }); });
|
|
3236
|
+
}
|
|
3237
|
+
},
|
|
3238
|
+
paramCount: 1,
|
|
3239
|
+
},
|
|
3209
3240
|
};
|
|
3210
3241
|
|
|
3211
3242
|
function isEqual(_a, sourceCodeInfo) {
|
|
@@ -3825,9 +3856,9 @@ var predicatesNormalExpression = {
|
|
|
3825
3856
|
},
|
|
3826
3857
|
'zero?': {
|
|
3827
3858
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3828
|
-
var _b = __read(_a, 1),
|
|
3829
|
-
assertNumber(
|
|
3830
|
-
return
|
|
3859
|
+
var _b = __read(_a, 1), value = _b[0];
|
|
3860
|
+
assertNumber(value, sourceCodeInfo, { finite: true });
|
|
3861
|
+
return Math.abs(value) < EPSILON;
|
|
3831
3862
|
},
|
|
3832
3863
|
paramCount: 1,
|
|
3833
3864
|
},
|
|
@@ -4688,6 +4719,24 @@ var gridNormalExpression = {
|
|
|
4688
4719
|
},
|
|
4689
4720
|
paramCount: 1,
|
|
4690
4721
|
},
|
|
4722
|
+
'grid:fill': {
|
|
4723
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
4724
|
+
var _b = __read(_a, 3), rows = _b[0], cols = _b[1], value = _b[2];
|
|
4725
|
+
assertNumber(rows, sourceCodeInfo, { integer: true, positive: true });
|
|
4726
|
+
assertNumber(cols, sourceCodeInfo, { integer: true, positive: true });
|
|
4727
|
+
assertAny(value, sourceCodeInfo);
|
|
4728
|
+
var result = [];
|
|
4729
|
+
for (var i = 0; i < rows; i += 1) {
|
|
4730
|
+
var row = [];
|
|
4731
|
+
for (var j = 0; j < cols; j += 1) {
|
|
4732
|
+
row.push(value);
|
|
4733
|
+
}
|
|
4734
|
+
result.push(row);
|
|
4735
|
+
}
|
|
4736
|
+
return result;
|
|
4737
|
+
},
|
|
4738
|
+
paramCount: 3,
|
|
4739
|
+
},
|
|
4691
4740
|
'grid:generate': {
|
|
4692
4741
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4693
4742
|
var _c = __read(_a, 3), rows = _c[0], cols = _c[1], generator = _c[2];
|
|
@@ -6632,7 +6681,141 @@ function extractOverlappingSegments(vectorA, vectorB, lag) {
|
|
|
6632
6681
|
return [segmentA, segmentB];
|
|
6633
6682
|
}
|
|
6634
6683
|
|
|
6684
|
+
function getUnit(value, sourceCodeInfo) {
|
|
6685
|
+
if (value.length === 0) {
|
|
6686
|
+
return value;
|
|
6687
|
+
}
|
|
6688
|
+
var length = Math.sqrt(value.reduce(function (acc, item) { return acc + Math.pow(item, 2); }, 0));
|
|
6689
|
+
if (approxZero(length)) {
|
|
6690
|
+
throw new LitsError('The vector must not be zero', sourceCodeInfo);
|
|
6691
|
+
}
|
|
6692
|
+
return value.map(function (item) { return item / length; });
|
|
6693
|
+
}
|
|
6694
|
+
|
|
6695
|
+
function dot(vector1, vector2) {
|
|
6696
|
+
return vector1.reduce(function (acc, item, index) { return acc + item * vector2[index]; }, 0);
|
|
6697
|
+
}
|
|
6698
|
+
|
|
6699
|
+
function subtract(vector1, vector2) {
|
|
6700
|
+
return vector1.map(function (item, index) { return item - vector2[index]; });
|
|
6701
|
+
}
|
|
6702
|
+
|
|
6703
|
+
function scale(vector, scalar) {
|
|
6704
|
+
return vector.map(function (item) { return item * scalar; });
|
|
6705
|
+
}
|
|
6706
|
+
|
|
6707
|
+
function length(vector) {
|
|
6708
|
+
return Math.sqrt(vector.reduce(function (acc, item) { return acc + Math.pow(item, 2); }, 0));
|
|
6709
|
+
}
|
|
6710
|
+
|
|
6635
6711
|
var linearAlgebraNormalExpression = {
|
|
6712
|
+
'lin:rotate2d': {
|
|
6713
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6714
|
+
var _b = __read(_a, 2), vector = _b[0], radians = _b[1];
|
|
6715
|
+
assert2dVector(vector, sourceCodeInfo);
|
|
6716
|
+
if (isZeroVector(vector)) {
|
|
6717
|
+
return vector;
|
|
6718
|
+
}
|
|
6719
|
+
assertNumber(radians, sourceCodeInfo, { finite: true });
|
|
6720
|
+
var cosTheta = Math.cos(radians);
|
|
6721
|
+
var sinTheta = Math.sin(radians);
|
|
6722
|
+
return [
|
|
6723
|
+
vector[0] * cosTheta - vector[1] * sinTheta,
|
|
6724
|
+
vector[0] * sinTheta + vector[1] * cosTheta,
|
|
6725
|
+
];
|
|
6726
|
+
},
|
|
6727
|
+
paramCount: 2,
|
|
6728
|
+
},
|
|
6729
|
+
'lin:rotate3d': {
|
|
6730
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6731
|
+
var _b = __read(_a, 3), vector = _b[0], axis = _b[1], radians = _b[2];
|
|
6732
|
+
assert3dVector(vector, sourceCodeInfo);
|
|
6733
|
+
if (isZeroVector(vector)) {
|
|
6734
|
+
return vector;
|
|
6735
|
+
}
|
|
6736
|
+
assertNumber(radians, sourceCodeInfo, { finite: true });
|
|
6737
|
+
assert3dVector(axis, sourceCodeInfo);
|
|
6738
|
+
if (isZeroVector(axis)) {
|
|
6739
|
+
throw new LitsError('Rotation axis must not be zero', sourceCodeInfo);
|
|
6740
|
+
}
|
|
6741
|
+
var cosTheta = Math.cos(radians);
|
|
6742
|
+
var sinTheta = Math.sin(radians);
|
|
6743
|
+
var _c = __read(getUnit(axis, sourceCodeInfo), 3), u = _c[0], v = _c[1], w = _c[2];
|
|
6744
|
+
var dotProduct = vector[0] * u + vector[1] * v + vector[2] * w;
|
|
6745
|
+
return [
|
|
6746
|
+
dotProduct * u * (1 - cosTheta) + vector[0] * cosTheta + (-w * vector[1] + v * vector[2]) * sinTheta,
|
|
6747
|
+
dotProduct * v * (1 - cosTheta) + vector[1] * cosTheta + (w * vector[0] - u * vector[2]) * sinTheta,
|
|
6748
|
+
dotProduct * w * (1 - cosTheta) + vector[2] * cosTheta + (-v * vector[0] + u * vector[1]) * sinTheta,
|
|
6749
|
+
];
|
|
6750
|
+
},
|
|
6751
|
+
paramCount: 3,
|
|
6752
|
+
},
|
|
6753
|
+
'lin:reflect': {
|
|
6754
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6755
|
+
var _b = __read(_a, 2), vector = _b[0], normal = _b[1];
|
|
6756
|
+
assertVector(vector, sourceCodeInfo);
|
|
6757
|
+
assertVector(normal, sourceCodeInfo);
|
|
6758
|
+
if (vector.length !== normal.length) {
|
|
6759
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6760
|
+
}
|
|
6761
|
+
if (isZeroVector(normal)) {
|
|
6762
|
+
throw new LitsError('Reflection normal must not be zero', sourceCodeInfo);
|
|
6763
|
+
}
|
|
6764
|
+
if (isZeroVector(vector)) {
|
|
6765
|
+
return vector;
|
|
6766
|
+
}
|
|
6767
|
+
var unitNormal = getUnit(normal, sourceCodeInfo);
|
|
6768
|
+
var doubleDot = 2 * dot(vector, unitNormal);
|
|
6769
|
+
return subtract(vector, scale(unitNormal, doubleDot));
|
|
6770
|
+
},
|
|
6771
|
+
paramCount: 2,
|
|
6772
|
+
},
|
|
6773
|
+
'lin:refract': {
|
|
6774
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6775
|
+
var _b = __read(_a, 3), vector = _b[0], normal = _b[1], eta = _b[2];
|
|
6776
|
+
assertVector(vector, sourceCodeInfo);
|
|
6777
|
+
assertVector(normal, sourceCodeInfo);
|
|
6778
|
+
assertNumber(eta, sourceCodeInfo, { finite: true, positive: true });
|
|
6779
|
+
if (vector.length !== normal.length) {
|
|
6780
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6781
|
+
}
|
|
6782
|
+
if (isZeroVector(normal)) {
|
|
6783
|
+
throw new LitsError('Refraction normal must not be zero', sourceCodeInfo);
|
|
6784
|
+
}
|
|
6785
|
+
if (isZeroVector(vector)) {
|
|
6786
|
+
return vector;
|
|
6787
|
+
}
|
|
6788
|
+
// Make sure vectors are normalized
|
|
6789
|
+
var normalizedV = getUnit(vector, sourceCodeInfo);
|
|
6790
|
+
var normalizedNormal = getUnit(normal, sourceCodeInfo);
|
|
6791
|
+
// Calculate dot product between incident vector and normal
|
|
6792
|
+
var dotProduct = dot(normalizedV, normalizedNormal);
|
|
6793
|
+
// Calculate discriminant
|
|
6794
|
+
var discriminant = 1 - eta * eta * (1 - dotProduct * dotProduct);
|
|
6795
|
+
// Check for total internal reflection
|
|
6796
|
+
if (discriminant < 0) {
|
|
6797
|
+
return vector; // Total internal reflection occurs
|
|
6798
|
+
}
|
|
6799
|
+
// Calculate the refracted vector
|
|
6800
|
+
var scaledIncident = scale(normalizedV, eta);
|
|
6801
|
+
var scaledNormal = scale(normalizedNormal, eta * dotProduct + Math.sqrt(discriminant));
|
|
6802
|
+
return subtract(scaledIncident, scaledNormal);
|
|
6803
|
+
},
|
|
6804
|
+
paramCount: 3,
|
|
6805
|
+
},
|
|
6806
|
+
'lin:lerp': {
|
|
6807
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6808
|
+
var _b = __read(_a, 3), vectorA = _b[0], vectorB = _b[1], t = _b[2];
|
|
6809
|
+
assertVector(vectorA, sourceCodeInfo);
|
|
6810
|
+
assertVector(vectorB, sourceCodeInfo);
|
|
6811
|
+
assertNumber(t, sourceCodeInfo, { finite: true });
|
|
6812
|
+
if (vectorA.length !== vectorB.length) {
|
|
6813
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6814
|
+
}
|
|
6815
|
+
return vectorA.map(function (val, i) { return val + (vectorB[i] - val) * t; });
|
|
6816
|
+
},
|
|
6817
|
+
paramCount: 3,
|
|
6818
|
+
},
|
|
6636
6819
|
'lin:dot': {
|
|
6637
6820
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6638
6821
|
var _b = __read(_a, 2), vectorA = _b[0], vectorB = _b[1];
|
|
@@ -6641,7 +6824,7 @@ var linearAlgebraNormalExpression = {
|
|
|
6641
6824
|
if (vectorA.length !== vectorB.length) {
|
|
6642
6825
|
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6643
6826
|
}
|
|
6644
|
-
return vectorA
|
|
6827
|
+
return dot(vectorA, vectorB);
|
|
6645
6828
|
},
|
|
6646
6829
|
paramCount: 2,
|
|
6647
6830
|
},
|
|
@@ -6722,16 +6905,10 @@ var linearAlgebraNormalExpression = {
|
|
|
6722
6905
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6723
6906
|
var _b = __read(_a, 1), vector = _b[0];
|
|
6724
6907
|
assertVector(vector, sourceCodeInfo);
|
|
6725
|
-
|
|
6726
|
-
return [];
|
|
6727
|
-
}
|
|
6728
|
-
var norm = Math.sqrt(vector.reduce(function (acc, val) { return acc + Math.pow(val, 2); }, 0));
|
|
6729
|
-
if (norm === 0) {
|
|
6730
|
-
return vector.map(function () { return 0; });
|
|
6731
|
-
}
|
|
6732
|
-
return vector.map(function (val) { return val / norm; });
|
|
6908
|
+
return getUnit(vector, sourceCodeInfo);
|
|
6733
6909
|
},
|
|
6734
6910
|
paramCount: 1,
|
|
6911
|
+
aliases: ['lin:unit', 'lin:normalize'],
|
|
6735
6912
|
},
|
|
6736
6913
|
'lin:normalize-log': {
|
|
6737
6914
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -6855,10 +7032,10 @@ var linearAlgebraNormalExpression = {
|
|
|
6855
7032
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6856
7033
|
var _b = __read(_a, 1), vector = _b[0];
|
|
6857
7034
|
assertNonEmptyVector(vector, sourceCodeInfo);
|
|
6858
|
-
return
|
|
7035
|
+
return length(vector);
|
|
6859
7036
|
},
|
|
6860
7037
|
paramCount: 1,
|
|
6861
|
-
aliases: ['lin:l2-norm', 'lin:
|
|
7038
|
+
aliases: ['lin:l2-norm', 'lin:length'],
|
|
6862
7039
|
},
|
|
6863
7040
|
'lin:manhattan-distance': {
|
|
6864
7041
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -7161,6 +7338,31 @@ var linearAlgebraNormalExpression = {
|
|
|
7161
7338
|
},
|
|
7162
7339
|
paramCount: 2,
|
|
7163
7340
|
},
|
|
7341
|
+
'lin:to-polar': {
|
|
7342
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
7343
|
+
var _b = __read(_a, 1), vector = _b[0];
|
|
7344
|
+
assert2dVector(vector, sourceCodeInfo);
|
|
7345
|
+
if (isZeroVector(vector)) {
|
|
7346
|
+
return [0, 0];
|
|
7347
|
+
}
|
|
7348
|
+
var r = Math.sqrt(Math.pow(vector[0], 2) + Math.pow(vector[1], 2));
|
|
7349
|
+
var theta = Math.atan2(vector[1], vector[0]);
|
|
7350
|
+
return [r, theta];
|
|
7351
|
+
},
|
|
7352
|
+
paramCount: 1,
|
|
7353
|
+
},
|
|
7354
|
+
'lin:from-polar': {
|
|
7355
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
7356
|
+
var _b = __read(_a, 1), polar = _b[0];
|
|
7357
|
+
assert2dVector(polar, sourceCodeInfo);
|
|
7358
|
+
var _c = __read(polar, 2), r = _c[0], theta = _c[1];
|
|
7359
|
+
if (r === 0) {
|
|
7360
|
+
return [0, 0];
|
|
7361
|
+
}
|
|
7362
|
+
return [r * Math.cos(theta), r * Math.sin(theta)];
|
|
7363
|
+
},
|
|
7364
|
+
paramCount: 1,
|
|
7365
|
+
},
|
|
7164
7366
|
};
|
|
7165
7367
|
|
|
7166
7368
|
/**
|
|
@@ -12328,6 +12530,7 @@ function evaluateReservedSymbol(node) {
|
|
|
12328
12530
|
return asNonUndefined(value, node[2]);
|
|
12329
12531
|
}
|
|
12330
12532
|
function evaluateNormalExpression(node, contextStack) {
|
|
12533
|
+
var _a, _b;
|
|
12331
12534
|
var sourceCodeInfo = node[2];
|
|
12332
12535
|
var paramNodes = node[1][1];
|
|
12333
12536
|
var params = [];
|
|
@@ -12353,14 +12556,14 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12353
12556
|
var nameSymbol = node[1][0];
|
|
12354
12557
|
if (placeholders.length > 0) {
|
|
12355
12558
|
var fn = evaluateNode(nameSymbol, contextStack);
|
|
12356
|
-
var partialFunction = {
|
|
12357
|
-
|
|
12358
|
-
|
|
12359
|
-
|
|
12360
|
-
params
|
|
12361
|
-
placeholders
|
|
12362
|
-
sourceCodeInfo
|
|
12363
|
-
|
|
12559
|
+
var partialFunction = (_a = {},
|
|
12560
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
12561
|
+
_a.function = asFunctionLike(fn, sourceCodeInfo),
|
|
12562
|
+
_a.functionType = 'Partial',
|
|
12563
|
+
_a.params = params,
|
|
12564
|
+
_a.placeholders = placeholders,
|
|
12565
|
+
_a.sourceCodeInfo = sourceCodeInfo,
|
|
12566
|
+
_a);
|
|
12364
12567
|
return partialFunction;
|
|
12365
12568
|
}
|
|
12366
12569
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -12380,14 +12583,14 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12380
12583
|
var fnNode = node[1][0];
|
|
12381
12584
|
var fn = asFunctionLike(evaluateNode(fnNode, contextStack), sourceCodeInfo);
|
|
12382
12585
|
if (placeholders.length > 0) {
|
|
12383
|
-
var partialFunction = {
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
|
|
12387
|
-
params
|
|
12388
|
-
placeholders
|
|
12389
|
-
sourceCodeInfo
|
|
12390
|
-
|
|
12586
|
+
var partialFunction = (_b = {},
|
|
12587
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
12588
|
+
_b.function = asFunctionLike(fn, sourceCodeInfo),
|
|
12589
|
+
_b.functionType = 'Partial',
|
|
12590
|
+
_b.params = params,
|
|
12591
|
+
_b.placeholders = placeholders,
|
|
12592
|
+
_b.sourceCodeInfo = sourceCodeInfo,
|
|
12593
|
+
_b);
|
|
12391
12594
|
return partialFunction;
|
|
12392
12595
|
}
|
|
12393
12596
|
return executeFunction(fn, params, contextStack, sourceCodeInfo);
|
|
@@ -12687,8 +12890,6 @@ var binaryOperators = [
|
|
|
12687
12890
|
'=', // equal
|
|
12688
12891
|
'!=', // not equal
|
|
12689
12892
|
'≠', // not equal
|
|
12690
|
-
'~', // approximate
|
|
12691
|
-
'≈', // approximate
|
|
12692
12893
|
'&', // bitwise AND
|
|
12693
12894
|
'xor', // bitwise XOR
|
|
12694
12895
|
'|', // bitwise OR
|
|
@@ -13331,8 +13532,6 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13331
13532
|
case '=': // equal
|
|
13332
13533
|
case '!=': // not equal
|
|
13333
13534
|
case '≠': // not equal
|
|
13334
|
-
case '~': // approximate
|
|
13335
|
-
case '≈': // approximate
|
|
13336
13535
|
return 5;
|
|
13337
13536
|
case '&': // bitwise AND
|
|
13338
13537
|
case 'xor': // bitwise XOR
|
|
@@ -13386,8 +13585,6 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13386
13585
|
case '&':
|
|
13387
13586
|
case 'xor':
|
|
13388
13587
|
case '|':
|
|
13389
|
-
case '~':
|
|
13390
|
-
case '≈':
|
|
13391
13588
|
case '|>':
|
|
13392
13589
|
return createNamedNormalExpressionNode(symbolNode, [left, right], sourceCodeInfo);
|
|
13393
13590
|
case '&&':
|
|
@@ -14930,7 +15127,6 @@ var api = {
|
|
|
14930
15127
|
'-',
|
|
14931
15128
|
'*',
|
|
14932
15129
|
'/',
|
|
14933
|
-
'~',
|
|
14934
15130
|
'mod',
|
|
14935
15131
|
'rem',
|
|
14936
15132
|
'quot',
|
|
@@ -14962,6 +15158,8 @@ var api = {
|
|
|
14962
15158
|
'asinh',
|
|
14963
15159
|
'acosh',
|
|
14964
15160
|
'atanh',
|
|
15161
|
+
'to-rad',
|
|
15162
|
+
'to-deg',
|
|
14965
15163
|
],
|
|
14966
15164
|
functional: [
|
|
14967
15165
|
'|>',
|
|
@@ -15104,6 +15302,7 @@ var api = {
|
|
|
15104
15302
|
'grid:row',
|
|
15105
15303
|
'grid:col',
|
|
15106
15304
|
'grid:shape',
|
|
15305
|
+
'grid:fill',
|
|
15107
15306
|
'grid:generate',
|
|
15108
15307
|
'grid:reshape',
|
|
15109
15308
|
'grid:transpose',
|
|
@@ -15195,6 +15394,11 @@ var api = {
|
|
|
15195
15394
|
'vec:smape'
|
|
15196
15395
|
], __read(getVectorReductionNames('mean')), false), __read(getVectorReductionNames('median')), false), __read(getVectorReductionNames('variance')), false), __read(getVectorReductionNames('sample-variance')), false), __read(getVectorReductionNames('sum')), false), __read(getVectorReductionNames('prod')), false), __read(getVectorReductionNames('min')), false), __read(getVectorReductionNames('max')), false), __read(getVectorReductionNames('stdev')), false), __read(getVectorReductionNames('sample-stdev')), false), __read(getVectorReductionNames('iqr')), false), __read(getVectorReductionNames('span')), false), __read(getVectorReductionNames('geometric-mean')), false), __read(getVectorReductionNames('harmonic-mean')), false), __read(getVectorReductionNames('skewness')), false), __read(getVectorReductionNames('sample-skewness')), false), __read(getVectorReductionNames('kurtosis')), false), __read(getVectorReductionNames('sample-kurtosis')), false), __read(getVectorReductionNames('excess-kurtosis')), false), __read(getVectorReductionNames('sample-excess-kurtosis')), false), __read(getVectorReductionNames('rms')), false), __read(getVectorReductionNames('mad')), false), __read(getVectorReductionNames('medad')), false), __read(getVectorReductionNames('gini-coefficient')), false), __read(getVectorReductionNames('entropy')), false), __read(getVectorReductionNames('skewness')), false),
|
|
15197
15396
|
linAlg: [
|
|
15397
|
+
'lin:reflect',
|
|
15398
|
+
'lin:refract',
|
|
15399
|
+
'lin:lerp',
|
|
15400
|
+
'lin:rotate2d',
|
|
15401
|
+
'lin:rotate3d',
|
|
15198
15402
|
'lin:dot',
|
|
15199
15403
|
'lin:cross',
|
|
15200
15404
|
'lin:normalize-minmax',
|
|
@@ -15228,6 +15432,8 @@ var api = {
|
|
|
15228
15432
|
'lin:cross-correlation',
|
|
15229
15433
|
'lin:rref',
|
|
15230
15434
|
'lin:solve',
|
|
15435
|
+
'lin:to-polar',
|
|
15436
|
+
'lin:from-polar',
|
|
15231
15437
|
],
|
|
15232
15438
|
numberTheory: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(getNumberTheorySequenceNames('abundant')), false), __read(getNumberTheorySequenceNames('bell')), false), __read(getNumberTheorySequenceNames('catalan')), false), __read(getNumberTheorySequenceNames('composite')), false), __read(getNumberTheorySequenceNames('factorial')), false), __read(getNumberTheorySequenceNames('fibonacci')), false), __read(getNumberTheorySequenceNames('geometric')), false), __read(getNumberTheorySequenceNames('golomb')), false), __read(getNumberTheorySequenceNames('happy')), false), __read(getNumberTheorySequenceNames('look-and-say')), false), __read(getNumberTheorySequenceNames('lucas')), false), __read(getNumberTheorySequenceNames('lucky')), false), __read(getNumberTheorySequenceNames('mersenne')), false), __read(getNumberTheorySequenceNames('padovan')), false), __read(getNumberTheorySequenceNames('partition')), false), __read(getNumberTheorySequenceNames('pell')), false), __read(getNumberTheorySequenceNames('perfect')), false), __read(getNumberTheorySequenceNames('perfect-cube')), false), __read(getNumberTheorySequenceNames('perfect-power')), false), __read(getNumberTheorySequenceNames('perfect-square')), false), __read(getNumberTheorySequenceNames('polygonal')), false), __read(getNumberTheorySequenceNames('prime')), false), __read(getNumberTheorySequenceNames('recaman')), false), __read(getNumberTheorySequenceNames('sylvester')), false), __read(getNumberTheorySequenceNames('thue-morse')), false), __read(getNumberTheorySequenceNames('tribonacci')), false), [
|
|
15233
15439
|
'nth:collatz-seq',
|
|
@@ -16916,29 +17122,6 @@ var mathReference = {
|
|
|
16916
17122
|
'[[1, 2, 3], [4, 5, 6]] / 2',
|
|
16917
17123
|
],
|
|
16918
17124
|
},
|
|
16919
|
-
'~': {
|
|
16920
|
-
title: '~',
|
|
16921
|
-
category: 'Math',
|
|
16922
|
-
linkName: '-tilde',
|
|
16923
|
-
returns: {
|
|
16924
|
-
type: ['number', 'vector', 'matrix'],
|
|
16925
|
-
},
|
|
16926
|
-
args: __assign({}, mixedOperatorArgs),
|
|
16927
|
-
variants: [
|
|
16928
|
-
{ argumentNames: ['a, b'] },
|
|
16929
|
-
],
|
|
16930
|
-
description: 'The `~` checks for approximately equal values, returning `true` if the absolute difference between the two numbers is less than or equal to a small threshold (default: `1e-10`). It works on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it checks each element for approximate equality.',
|
|
16931
|
-
examples: [
|
|
16932
|
-
'~(0.1, 0.1)',
|
|
16933
|
-
'~(0.1, 0.10000000000001)',
|
|
16934
|
-
'~(0.1, 0.2)',
|
|
16935
|
-
'~(0.1, 0.101, 0.1)',
|
|
16936
|
-
'~([1, 2, 3], [1.00000000000001, 2.00000000000001, 3.00000000000001])',
|
|
16937
|
-
'~([1, 2, 3], [1.1, 2.1, 3.1])',
|
|
16938
|
-
'~([[1, 2, 3], [1, 2, 3]], [[1.01, 2.01, 3.01], [1.01, 2.01, 3.01]], 0.1)',
|
|
16939
|
-
],
|
|
16940
|
-
aliases: ['≈'],
|
|
16941
|
-
},
|
|
16942
17125
|
'mod': {
|
|
16943
17126
|
title: 'mod',
|
|
16944
17127
|
category: 'Math',
|
|
@@ -17716,6 +17899,56 @@ var mathReference = {
|
|
|
17716
17899
|
'atanh([[0.1, 0.2], [0.3, 0.4]])',
|
|
17717
17900
|
],
|
|
17718
17901
|
},
|
|
17902
|
+
'to-rad': {
|
|
17903
|
+
title: 'to-rad',
|
|
17904
|
+
category: 'Math',
|
|
17905
|
+
linkName: 'to-rad',
|
|
17906
|
+
returns: {
|
|
17907
|
+
type: ['number', 'vector', 'matrix'],
|
|
17908
|
+
},
|
|
17909
|
+
args: {
|
|
17910
|
+
x: {
|
|
17911
|
+
type: ['number', 'vector', 'matrix'],
|
|
17912
|
+
},
|
|
17913
|
+
},
|
|
17914
|
+
variants: [
|
|
17915
|
+
{ argumentNames: ['x'] },
|
|
17916
|
+
],
|
|
17917
|
+
description: 'The `to-rad` function converts an angle from degrees to radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',
|
|
17918
|
+
examples: [
|
|
17919
|
+
'to-rad(0)',
|
|
17920
|
+
'to-rad(90)',
|
|
17921
|
+
'to-rad(180)',
|
|
17922
|
+
'to-rad(360)',
|
|
17923
|
+
'to-rad([0, 90, 180])',
|
|
17924
|
+
'to-rad([[0, 90], [180, 360]])',
|
|
17925
|
+
],
|
|
17926
|
+
},
|
|
17927
|
+
'to-deg': {
|
|
17928
|
+
title: 'to-deg',
|
|
17929
|
+
category: 'Math',
|
|
17930
|
+
linkName: 'to-deg',
|
|
17931
|
+
returns: {
|
|
17932
|
+
type: ['number', 'vector', 'matrix'],
|
|
17933
|
+
},
|
|
17934
|
+
args: {
|
|
17935
|
+
x: {
|
|
17936
|
+
type: ['number', 'vector', 'matrix'],
|
|
17937
|
+
},
|
|
17938
|
+
},
|
|
17939
|
+
variants: [
|
|
17940
|
+
{ argumentNames: ['x'] },
|
|
17941
|
+
],
|
|
17942
|
+
description: 'The `to-deg` function converts an angle from radians to degrees, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',
|
|
17943
|
+
examples: [
|
|
17944
|
+
'to-deg(0)',
|
|
17945
|
+
'to-deg(PI)',
|
|
17946
|
+
'to-deg(PI / 2)',
|
|
17947
|
+
'to-deg(3 * PI / 2)',
|
|
17948
|
+
'to-deg([0, PI, PI / 2])',
|
|
17949
|
+
'to-deg([[0, PI], [PI / 2, 3 * PI / 2]])',
|
|
17950
|
+
],
|
|
17951
|
+
},
|
|
17719
17952
|
};
|
|
17720
17953
|
|
|
17721
17954
|
var miscReference = {
|
|
@@ -19044,6 +19277,36 @@ var gridReference = {
|
|
|
19044
19277
|
"grid:shape(".concat(exampleGrid3, ")"),
|
|
19045
19278
|
],
|
|
19046
19279
|
},
|
|
19280
|
+
'grid:fill': {
|
|
19281
|
+
title: 'grid:fill',
|
|
19282
|
+
category: 'Grid',
|
|
19283
|
+
linkName: 'grid-colon-fill',
|
|
19284
|
+
returns: {
|
|
19285
|
+
type: 'grid',
|
|
19286
|
+
},
|
|
19287
|
+
args: {
|
|
19288
|
+
rows: {
|
|
19289
|
+
type: 'integer',
|
|
19290
|
+
description: 'The number of rows in the grid.',
|
|
19291
|
+
},
|
|
19292
|
+
cols: {
|
|
19293
|
+
type: 'integer',
|
|
19294
|
+
description: 'The number of columns in the grid.',
|
|
19295
|
+
},
|
|
19296
|
+
value: {
|
|
19297
|
+
type: 'any',
|
|
19298
|
+
description: 'The value to fill the grid with.',
|
|
19299
|
+
},
|
|
19300
|
+
},
|
|
19301
|
+
variants: [
|
|
19302
|
+
{ argumentNames: ['rows', 'cols', 'value'] },
|
|
19303
|
+
],
|
|
19304
|
+
description: 'Creates a grid of the specified size, filled with the specified value.',
|
|
19305
|
+
examples: [
|
|
19306
|
+
'grid:fill(2, 3, 0)',
|
|
19307
|
+
'grid:fill(2, 3, "x")',
|
|
19308
|
+
],
|
|
19309
|
+
},
|
|
19047
19310
|
'grid:generate': {
|
|
19048
19311
|
title: 'grid:generate',
|
|
19049
19312
|
category: 'Grid',
|
|
@@ -23266,6 +23529,150 @@ var vectorReference = __assign(__assign(__assign(__assign(__assign(__assign(__as
|
|
|
23266
23529
|
} });
|
|
23267
23530
|
|
|
23268
23531
|
var linAlgReference = {
|
|
23532
|
+
'lin:reflect': {
|
|
23533
|
+
title: 'lin:reflect',
|
|
23534
|
+
category: 'Linear Algebra',
|
|
23535
|
+
description: 'Reflects a vector across a given axis.',
|
|
23536
|
+
linkName: 'lin-colon-reflect',
|
|
23537
|
+
returns: {
|
|
23538
|
+
type: 'vector',
|
|
23539
|
+
},
|
|
23540
|
+
args: {
|
|
23541
|
+
a: {
|
|
23542
|
+
type: 'vector',
|
|
23543
|
+
description: 'Vector to reflect.',
|
|
23544
|
+
},
|
|
23545
|
+
b: {
|
|
23546
|
+
type: 'vector',
|
|
23547
|
+
description: 'Axis of reflection.',
|
|
23548
|
+
},
|
|
23549
|
+
},
|
|
23550
|
+
variants: [
|
|
23551
|
+
{ argumentNames: ['a', 'b'] },
|
|
23552
|
+
],
|
|
23553
|
+
examples: [
|
|
23554
|
+
'lin:reflect([1, 2], [0, 1])',
|
|
23555
|
+
'lin:reflect([1, 2, 3], [0, 0, 1])',
|
|
23556
|
+
],
|
|
23557
|
+
},
|
|
23558
|
+
'lin:refract': {
|
|
23559
|
+
title: 'lin:refract',
|
|
23560
|
+
category: 'Linear Algebra',
|
|
23561
|
+
description: 'Refracts a vector across a given axis.',
|
|
23562
|
+
linkName: 'lin-colon-refract',
|
|
23563
|
+
returns: {
|
|
23564
|
+
type: 'vector',
|
|
23565
|
+
},
|
|
23566
|
+
args: {
|
|
23567
|
+
vector: {
|
|
23568
|
+
type: 'vector',
|
|
23569
|
+
description: 'Vector to refract.',
|
|
23570
|
+
},
|
|
23571
|
+
axis: {
|
|
23572
|
+
type: 'vector',
|
|
23573
|
+
description: 'Axis of refraction.',
|
|
23574
|
+
},
|
|
23575
|
+
eta: {
|
|
23576
|
+
type: 'number',
|
|
23577
|
+
description: 'Refraction index.',
|
|
23578
|
+
},
|
|
23579
|
+
},
|
|
23580
|
+
variants: [
|
|
23581
|
+
{ argumentNames: ['vector', 'axis', 'eta'] },
|
|
23582
|
+
],
|
|
23583
|
+
examples: [
|
|
23584
|
+
'lin:refract([1, 2], [0, 1], 1.5)',
|
|
23585
|
+
'lin:refract([1, 2, 3], [0, 0, 1], 1.5)',
|
|
23586
|
+
],
|
|
23587
|
+
},
|
|
23588
|
+
'lin:lerp': {
|
|
23589
|
+
title: 'lin:lerp',
|
|
23590
|
+
category: 'Linear Algebra',
|
|
23591
|
+
description: 'Performs linear interpolation between two vectors.',
|
|
23592
|
+
linkName: 'lin-colon-lerp',
|
|
23593
|
+
returns: {
|
|
23594
|
+
type: 'vector',
|
|
23595
|
+
},
|
|
23596
|
+
args: {
|
|
23597
|
+
a: {
|
|
23598
|
+
type: 'vector',
|
|
23599
|
+
description: 'Start vector.',
|
|
23600
|
+
},
|
|
23601
|
+
b: {
|
|
23602
|
+
type: 'vector',
|
|
23603
|
+
description: 'End vector.',
|
|
23604
|
+
},
|
|
23605
|
+
t: {
|
|
23606
|
+
type: 'number',
|
|
23607
|
+
description: 'Interpolation factor (0 to 1).',
|
|
23608
|
+
},
|
|
23609
|
+
},
|
|
23610
|
+
variants: [
|
|
23611
|
+
{ argumentNames: ['a', 'b', 't'] },
|
|
23612
|
+
],
|
|
23613
|
+
examples: [
|
|
23614
|
+
'lin:lerp([1, 2], [3, 4], 0.5)',
|
|
23615
|
+
'lin:lerp([1, 2], [3, 4], 2)',
|
|
23616
|
+
'lin:lerp([1, 2], [3, 4], -1)',
|
|
23617
|
+
'lin:lerp([1, 2, 3], [4, 5, 6], 0.25)',
|
|
23618
|
+
],
|
|
23619
|
+
},
|
|
23620
|
+
'lin:rotate2d': {
|
|
23621
|
+
title: 'lin:rotate2d',
|
|
23622
|
+
category: 'Linear Algebra',
|
|
23623
|
+
description: 'Rotates a 2D vector by a given angle in radians.',
|
|
23624
|
+
linkName: 'lin-colon-rotate2d',
|
|
23625
|
+
returns: {
|
|
23626
|
+
type: 'vector',
|
|
23627
|
+
},
|
|
23628
|
+
args: {
|
|
23629
|
+
a: {
|
|
23630
|
+
type: 'vector',
|
|
23631
|
+
description: 'Vector to rotate.',
|
|
23632
|
+
},
|
|
23633
|
+
b: {
|
|
23634
|
+
type: 'number',
|
|
23635
|
+
description: 'Angle in b.',
|
|
23636
|
+
},
|
|
23637
|
+
},
|
|
23638
|
+
variants: [
|
|
23639
|
+
{ argumentNames: ['a', 'b'] },
|
|
23640
|
+
],
|
|
23641
|
+
examples: [
|
|
23642
|
+
'lin:rotate2d([1, 0], PI / 2)',
|
|
23643
|
+
'lin:rotate2d([0, 1], PI)',
|
|
23644
|
+
],
|
|
23645
|
+
},
|
|
23646
|
+
'lin:rotate3d': {
|
|
23647
|
+
title: 'lin:rotate3d',
|
|
23648
|
+
category: 'Linear Algebra',
|
|
23649
|
+
description: 'Rotates a 3D vector around a given axis by a given angle in radians.',
|
|
23650
|
+
linkName: 'lin-colon-rotate3d',
|
|
23651
|
+
returns: {
|
|
23652
|
+
type: 'vector',
|
|
23653
|
+
},
|
|
23654
|
+
args: {
|
|
23655
|
+
v: {
|
|
23656
|
+
type: 'vector',
|
|
23657
|
+
description: 'Vector to rotate.',
|
|
23658
|
+
},
|
|
23659
|
+
axis: {
|
|
23660
|
+
type: 'vector',
|
|
23661
|
+
description: 'Axis of rotation.',
|
|
23662
|
+
},
|
|
23663
|
+
radians: {
|
|
23664
|
+
type: 'number',
|
|
23665
|
+
description: 'Angle in radians.',
|
|
23666
|
+
},
|
|
23667
|
+
},
|
|
23668
|
+
variants: [
|
|
23669
|
+
{ argumentNames: ['v', 'axis', 'radians'] },
|
|
23670
|
+
],
|
|
23671
|
+
examples: [
|
|
23672
|
+
'lin:rotate3d([1, 0, 0], [0, 1, 0], PI / 2)',
|
|
23673
|
+
'lin:rotate3d([0, 1, 0], [1, 0, 0], PI)',
|
|
23674
|
+
],
|
|
23675
|
+
},
|
|
23269
23676
|
'lin:dot': {
|
|
23270
23677
|
title: 'lin:dot',
|
|
23271
23678
|
category: 'Linear Algebra',
|
|
@@ -23440,11 +23847,16 @@ var linAlgReference = {
|
|
|
23440
23847
|
],
|
|
23441
23848
|
examples: [
|
|
23442
23849
|
'lin:normalize-l2([1, 2, 3])',
|
|
23850
|
+
'lin:unit([1, 2, 3])',
|
|
23443
23851
|
'lin:normalize-l2([1, 2, -3])',
|
|
23444
23852
|
'lin:normalize-l2([1, 2, 3, 4])',
|
|
23445
23853
|
'lin:normalize-l2([1, 2, -3, 4])',
|
|
23446
23854
|
'lin:normalize-l2([1, 2, 3, 40, 50])',
|
|
23447
23855
|
],
|
|
23856
|
+
aliases: [
|
|
23857
|
+
'lin:unit',
|
|
23858
|
+
'lin:normalize',
|
|
23859
|
+
],
|
|
23448
23860
|
},
|
|
23449
23861
|
'lin:normalize-log': {
|
|
23450
23862
|
title: 'lin:normalize-log',
|
|
@@ -23622,7 +24034,7 @@ var linAlgReference = {
|
|
|
23622
24034
|
],
|
|
23623
24035
|
aliases: [
|
|
23624
24036
|
'lin:l2-norm',
|
|
23625
|
-
'lin:
|
|
24037
|
+
'lin:length',
|
|
23626
24038
|
],
|
|
23627
24039
|
},
|
|
23628
24040
|
'lin:manhattan-distance': {
|
|
@@ -23990,6 +24402,51 @@ var linAlgReference = {
|
|
|
23990
24402
|
'lin:solve([[2, 3], [1, -1]], [8, 2])',
|
|
23991
24403
|
],
|
|
23992
24404
|
},
|
|
24405
|
+
'lin:to-polar': {
|
|
24406
|
+
title: 'lin:to-polar',
|
|
24407
|
+
category: 'Linear Algebra',
|
|
24408
|
+
description: 'Converts a 2D vector to polar coordinates.',
|
|
24409
|
+
linkName: 'lin-colon-to-polar',
|
|
24410
|
+
returns: {
|
|
24411
|
+
type: 'vector',
|
|
24412
|
+
},
|
|
24413
|
+
args: {
|
|
24414
|
+
vector: {
|
|
24415
|
+
type: 'vector',
|
|
24416
|
+
description: '2D Vector to convert.',
|
|
24417
|
+
},
|
|
24418
|
+
},
|
|
24419
|
+
variants: [
|
|
24420
|
+
{ argumentNames: ['vector'] },
|
|
24421
|
+
],
|
|
24422
|
+
examples: [
|
|
24423
|
+
'lin:to-polar([1, 2])',
|
|
24424
|
+
'lin:to-polar([3, 4])',
|
|
24425
|
+
],
|
|
24426
|
+
},
|
|
24427
|
+
'lin:from-polar': {
|
|
24428
|
+
title: 'lin:from-polar',
|
|
24429
|
+
category: 'Linear Algebra',
|
|
24430
|
+
description: 'Converts polar coordinates to a 2D vector.',
|
|
24431
|
+
linkName: 'lin-colon-from-polar',
|
|
24432
|
+
returns: {
|
|
24433
|
+
type: 'vector',
|
|
24434
|
+
},
|
|
24435
|
+
args: {
|
|
24436
|
+
polar: {
|
|
24437
|
+
type: 'vector',
|
|
24438
|
+
description: 'Polar coordinates to convert.',
|
|
24439
|
+
},
|
|
24440
|
+
},
|
|
24441
|
+
variants: [
|
|
24442
|
+
{ argumentNames: ['polar'] },
|
|
24443
|
+
],
|
|
24444
|
+
examples: [
|
|
24445
|
+
'lin:from-polar([1, PI / 4])',
|
|
24446
|
+
'lin:from-polar([1, 0])',
|
|
24447
|
+
'lin:from-polar([1, -PI / 2])',
|
|
24448
|
+
],
|
|
24449
|
+
},
|
|
23993
24450
|
};
|
|
23994
24451
|
|
|
23995
24452
|
var predicateReference = {
|