@mojir/lits 2.1.8 → 2.1.10
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 +380 -30
- package/dist/cli/reference/api.d.ts +3 -3
- package/dist/cli/reference/index.d.ts +6 -0
- 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/scale.d.ts +1 -0
- package/dist/cli/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/subtract.d.ts +1 -0
- package/dist/cli/src/typeGuards/annotatedArrays.d.ts +4 -0
- package/dist/cli/src/utils/index.d.ts +1 -1
- package/dist/index.esm.js +379 -29
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +379 -29
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +379 -29
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +3 -3
- package/dist/reference/index.d.ts +6 -0
- 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/scale.d.ts +1 -0
- package/dist/src/builtin/normalExpressions/categories/namespaces/linearAlgebra/helpers/subtract.d.ts +1 -0
- package/dist/src/typeGuards/annotatedArrays.d.ts +4 -0
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/testFramework.esm.js +193 -28
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +193 -28
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/testFramework.js
CHANGED
|
@@ -804,7 +804,7 @@ function deepEqual(a, b, sourceCodeInfo) {
|
|
|
804
804
|
if (a === b)
|
|
805
805
|
return true;
|
|
806
806
|
if (typeof a === 'number' && typeof b === 'number')
|
|
807
|
-
return Math.abs(a - b) <
|
|
807
|
+
return Math.abs(a - b) < 1e-10;
|
|
808
808
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
809
809
|
if (a.length !== b.length)
|
|
810
810
|
return false;
|
|
@@ -823,7 +823,7 @@ function deepEqual(a, b, sourceCodeInfo) {
|
|
|
823
823
|
return false;
|
|
824
824
|
for (var i = 0; i < aKeys.length; i += 1) {
|
|
825
825
|
var key = asString(aKeys[i], sourceCodeInfo);
|
|
826
|
-
if (!deepEqual(
|
|
826
|
+
if (!deepEqual(a[key], b[key], sourceCodeInfo))
|
|
827
827
|
return false;
|
|
828
828
|
}
|
|
829
829
|
return true;
|
|
@@ -2288,6 +2288,28 @@ function assertVector(vector, sourceCodeInfo) {
|
|
|
2288
2288
|
throw new LitsError("Expected a vector, but got ".concat(vector), sourceCodeInfo);
|
|
2289
2289
|
}
|
|
2290
2290
|
}
|
|
2291
|
+
function is2dVector(vector) {
|
|
2292
|
+
if (!isVector(vector)) {
|
|
2293
|
+
return false;
|
|
2294
|
+
}
|
|
2295
|
+
return vector.length === 2;
|
|
2296
|
+
}
|
|
2297
|
+
function assert2dVector(vector, sourceCodeInfo) {
|
|
2298
|
+
if (!is2dVector(vector)) {
|
|
2299
|
+
throw new LitsError("Expected a 2d vector, but got ".concat(vector), sourceCodeInfo);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
function is3dVector(vector) {
|
|
2303
|
+
if (!isVector(vector)) {
|
|
2304
|
+
return false;
|
|
2305
|
+
}
|
|
2306
|
+
return vector.length === 3;
|
|
2307
|
+
}
|
|
2308
|
+
function assert3dVector(vector, sourceCodeInfo) {
|
|
2309
|
+
if (!is3dVector(vector)) {
|
|
2310
|
+
throw new LitsError("Expected a 3d vector, but got ".concat(vector), sourceCodeInfo);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2291
2313
|
function assertNonEmptyVector(vector, sourceCodeInfo) {
|
|
2292
2314
|
assertVector(vector, sourceCodeInfo);
|
|
2293
2315
|
if (vector.length === 0) {
|
|
@@ -4668,6 +4690,24 @@ var gridNormalExpression = {
|
|
|
4668
4690
|
},
|
|
4669
4691
|
paramCount: 1,
|
|
4670
4692
|
},
|
|
4693
|
+
'grid:fill': {
|
|
4694
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
4695
|
+
var _b = __read(_a, 3), rows = _b[0], cols = _b[1], value = _b[2];
|
|
4696
|
+
assertNumber(rows, sourceCodeInfo, { integer: true, positive: true });
|
|
4697
|
+
assertNumber(cols, sourceCodeInfo, { integer: true, positive: true });
|
|
4698
|
+
assertAny(value, sourceCodeInfo);
|
|
4699
|
+
var result = [];
|
|
4700
|
+
for (var i = 0; i < rows; i += 1) {
|
|
4701
|
+
var row = [];
|
|
4702
|
+
for (var j = 0; j < cols; j += 1) {
|
|
4703
|
+
row.push(value);
|
|
4704
|
+
}
|
|
4705
|
+
result.push(row);
|
|
4706
|
+
}
|
|
4707
|
+
return result;
|
|
4708
|
+
},
|
|
4709
|
+
paramCount: 3,
|
|
4710
|
+
},
|
|
4671
4711
|
'grid:generate': {
|
|
4672
4712
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4673
4713
|
var _c = __read(_a, 3), rows = _c[0], cols = _c[1], generator = _c[2];
|
|
@@ -6612,7 +6652,137 @@ function extractOverlappingSegments(vectorA, vectorB, lag) {
|
|
|
6612
6652
|
return [segmentA, segmentB];
|
|
6613
6653
|
}
|
|
6614
6654
|
|
|
6655
|
+
function getUnit(value, sourceCodeInfo) {
|
|
6656
|
+
if (value.length === 0) {
|
|
6657
|
+
return value;
|
|
6658
|
+
}
|
|
6659
|
+
var length = Math.sqrt(value.reduce(function (acc, item) { return acc + Math.pow(item, 2); }, 0));
|
|
6660
|
+
if (approxZero(length)) {
|
|
6661
|
+
throw new LitsError('The vector must not be zero', sourceCodeInfo);
|
|
6662
|
+
}
|
|
6663
|
+
return value.map(function (item) { return item / length; });
|
|
6664
|
+
}
|
|
6665
|
+
|
|
6666
|
+
function dot(vector1, vector2) {
|
|
6667
|
+
return vector1.reduce(function (acc, item, index) { return acc + item * vector2[index]; }, 0);
|
|
6668
|
+
}
|
|
6669
|
+
|
|
6670
|
+
function subtract(vector1, vector2) {
|
|
6671
|
+
return vector1.map(function (item, index) { return item - vector2[index]; });
|
|
6672
|
+
}
|
|
6673
|
+
|
|
6674
|
+
function scale(vector, scalar) {
|
|
6675
|
+
return vector.map(function (item) { return item * scalar; });
|
|
6676
|
+
}
|
|
6677
|
+
|
|
6615
6678
|
var linearAlgebraNormalExpression = {
|
|
6679
|
+
'lin:rotate2d': {
|
|
6680
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6681
|
+
var _b = __read(_a, 2), vector = _b[0], radians = _b[1];
|
|
6682
|
+
assert2dVector(vector, sourceCodeInfo);
|
|
6683
|
+
if (isZeroVector(vector)) {
|
|
6684
|
+
return vector;
|
|
6685
|
+
}
|
|
6686
|
+
assertNumber(radians, sourceCodeInfo, { finite: true });
|
|
6687
|
+
var cosTheta = Math.cos(radians);
|
|
6688
|
+
var sinTheta = Math.sin(radians);
|
|
6689
|
+
return [
|
|
6690
|
+
vector[0] * cosTheta - vector[1] * sinTheta,
|
|
6691
|
+
vector[0] * sinTheta + vector[1] * cosTheta,
|
|
6692
|
+
];
|
|
6693
|
+
},
|
|
6694
|
+
paramCount: 2,
|
|
6695
|
+
},
|
|
6696
|
+
'lin:rotate3d': {
|
|
6697
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6698
|
+
var _b = __read(_a, 3), vector = _b[0], axis = _b[1], radians = _b[2];
|
|
6699
|
+
assert3dVector(vector, sourceCodeInfo);
|
|
6700
|
+
if (isZeroVector(vector)) {
|
|
6701
|
+
return vector;
|
|
6702
|
+
}
|
|
6703
|
+
assertNumber(radians, sourceCodeInfo, { finite: true });
|
|
6704
|
+
assert3dVector(axis, sourceCodeInfo);
|
|
6705
|
+
if (isZeroVector(axis)) {
|
|
6706
|
+
throw new LitsError('Rotation axis must not be zero', sourceCodeInfo);
|
|
6707
|
+
}
|
|
6708
|
+
var cosTheta = Math.cos(radians);
|
|
6709
|
+
var sinTheta = Math.sin(radians);
|
|
6710
|
+
var _c = __read(getUnit(axis, sourceCodeInfo), 3), u = _c[0], v = _c[1], w = _c[2];
|
|
6711
|
+
var dotProduct = vector[0] * u + vector[1] * v + vector[2] * w;
|
|
6712
|
+
return [
|
|
6713
|
+
dotProduct * u * (1 - cosTheta) + vector[0] * cosTheta + (-w * vector[1] + v * vector[2]) * sinTheta,
|
|
6714
|
+
dotProduct * v * (1 - cosTheta) + vector[1] * cosTheta + (w * vector[0] - u * vector[2]) * sinTheta,
|
|
6715
|
+
dotProduct * w * (1 - cosTheta) + vector[2] * cosTheta + (-v * vector[0] + u * vector[1]) * sinTheta,
|
|
6716
|
+
];
|
|
6717
|
+
},
|
|
6718
|
+
paramCount: 3,
|
|
6719
|
+
},
|
|
6720
|
+
'lin:reflect': {
|
|
6721
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6722
|
+
var _b = __read(_a, 2), vector = _b[0], normal = _b[1];
|
|
6723
|
+
assertVector(vector, sourceCodeInfo);
|
|
6724
|
+
assertVector(normal, sourceCodeInfo);
|
|
6725
|
+
if (vector.length !== normal.length) {
|
|
6726
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6727
|
+
}
|
|
6728
|
+
if (isZeroVector(normal)) {
|
|
6729
|
+
throw new LitsError('Reflection normal must not be zero', sourceCodeInfo);
|
|
6730
|
+
}
|
|
6731
|
+
if (isZeroVector(vector)) {
|
|
6732
|
+
return vector;
|
|
6733
|
+
}
|
|
6734
|
+
var unitNormal = getUnit(normal, sourceCodeInfo);
|
|
6735
|
+
var doubleDot = 2 * dot(vector, unitNormal);
|
|
6736
|
+
return subtract(vector, scale(unitNormal, doubleDot));
|
|
6737
|
+
},
|
|
6738
|
+
paramCount: 2,
|
|
6739
|
+
},
|
|
6740
|
+
'lin:refract': {
|
|
6741
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6742
|
+
var _b = __read(_a, 3), vector = _b[0], normal = _b[1], eta = _b[2];
|
|
6743
|
+
assertVector(vector, sourceCodeInfo);
|
|
6744
|
+
assertVector(normal, sourceCodeInfo);
|
|
6745
|
+
assertNumber(eta, sourceCodeInfo, { finite: true, positive: true });
|
|
6746
|
+
if (vector.length !== normal.length) {
|
|
6747
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6748
|
+
}
|
|
6749
|
+
if (isZeroVector(normal)) {
|
|
6750
|
+
throw new LitsError('Refraction normal must not be zero', sourceCodeInfo);
|
|
6751
|
+
}
|
|
6752
|
+
if (isZeroVector(vector)) {
|
|
6753
|
+
return vector;
|
|
6754
|
+
}
|
|
6755
|
+
// Make sure vectors are normalized
|
|
6756
|
+
var normalizedV = getUnit(vector, sourceCodeInfo);
|
|
6757
|
+
var normalizedNormal = getUnit(normal, sourceCodeInfo);
|
|
6758
|
+
// Calculate dot product between incident vector and normal
|
|
6759
|
+
var dotProduct = dot(normalizedV, normalizedNormal);
|
|
6760
|
+
// Calculate discriminant
|
|
6761
|
+
var discriminant = 1 - eta * eta * (1 - dotProduct * dotProduct);
|
|
6762
|
+
// Check for total internal reflection
|
|
6763
|
+
if (discriminant < 0) {
|
|
6764
|
+
return vector; // Total internal reflection occurs
|
|
6765
|
+
}
|
|
6766
|
+
// Calculate the refracted vector
|
|
6767
|
+
var scaledIncident = scale(normalizedV, eta);
|
|
6768
|
+
var scaledNormal = scale(normalizedNormal, eta * dotProduct + Math.sqrt(discriminant));
|
|
6769
|
+
return subtract(scaledIncident, scaledNormal);
|
|
6770
|
+
},
|
|
6771
|
+
paramCount: 3,
|
|
6772
|
+
},
|
|
6773
|
+
'lin:lerp': {
|
|
6774
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
6775
|
+
var _b = __read(_a, 3), vectorA = _b[0], vectorB = _b[1], t = _b[2];
|
|
6776
|
+
assertVector(vectorA, sourceCodeInfo);
|
|
6777
|
+
assertVector(vectorB, sourceCodeInfo);
|
|
6778
|
+
assertNumber(t, sourceCodeInfo, { finite: true });
|
|
6779
|
+
if (vectorA.length !== vectorB.length) {
|
|
6780
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6781
|
+
}
|
|
6782
|
+
return vectorA.map(function (val, i) { return val + (vectorB[i] - val) * t; });
|
|
6783
|
+
},
|
|
6784
|
+
paramCount: 3,
|
|
6785
|
+
},
|
|
6616
6786
|
'lin:dot': {
|
|
6617
6787
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6618
6788
|
var _b = __read(_a, 2), vectorA = _b[0], vectorB = _b[1];
|
|
@@ -6621,7 +6791,7 @@ var linearAlgebraNormalExpression = {
|
|
|
6621
6791
|
if (vectorA.length !== vectorB.length) {
|
|
6622
6792
|
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6623
6793
|
}
|
|
6624
|
-
return vectorA
|
|
6794
|
+
return dot(vectorA, vectorB);
|
|
6625
6795
|
},
|
|
6626
6796
|
paramCount: 2,
|
|
6627
6797
|
},
|
|
@@ -6702,16 +6872,10 @@ var linearAlgebraNormalExpression = {
|
|
|
6702
6872
|
evaluate: function (_a, sourceCodeInfo) {
|
|
6703
6873
|
var _b = __read(_a, 1), vector = _b[0];
|
|
6704
6874
|
assertVector(vector, sourceCodeInfo);
|
|
6705
|
-
|
|
6706
|
-
return [];
|
|
6707
|
-
}
|
|
6708
|
-
var norm = Math.sqrt(vector.reduce(function (acc, val) { return acc + Math.pow(val, 2); }, 0));
|
|
6709
|
-
if (norm === 0) {
|
|
6710
|
-
return vector.map(function () { return 0; });
|
|
6711
|
-
}
|
|
6712
|
-
return vector.map(function (val) { return val / norm; });
|
|
6875
|
+
return getUnit(vector, sourceCodeInfo);
|
|
6713
6876
|
},
|
|
6714
6877
|
paramCount: 1,
|
|
6878
|
+
aliases: ['lin:unit', 'lin:normalize'],
|
|
6715
6879
|
},
|
|
6716
6880
|
'lin:normalize-log': {
|
|
6717
6881
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -6838,7 +7002,7 @@ var linearAlgebraNormalExpression = {
|
|
|
6838
7002
|
return Math.sqrt(vector.reduce(function (acc, val) { return acc + val * val; }, 0));
|
|
6839
7003
|
},
|
|
6840
7004
|
paramCount: 1,
|
|
6841
|
-
aliases: ['lin:l2-norm', 'lin:
|
|
7005
|
+
aliases: ['lin:l2-norm', 'lin:length'],
|
|
6842
7006
|
},
|
|
6843
7007
|
'lin:manhattan-distance': {
|
|
6844
7008
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -12308,6 +12472,7 @@ function evaluateReservedSymbol(node) {
|
|
|
12308
12472
|
return asNonUndefined(value, node[2]);
|
|
12309
12473
|
}
|
|
12310
12474
|
function evaluateNormalExpression(node, contextStack) {
|
|
12475
|
+
var _a, _b;
|
|
12311
12476
|
var sourceCodeInfo = node[2];
|
|
12312
12477
|
var paramNodes = node[1][1];
|
|
12313
12478
|
var params = [];
|
|
@@ -12333,14 +12498,14 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12333
12498
|
var nameSymbol = node[1][0];
|
|
12334
12499
|
if (placeholders.length > 0) {
|
|
12335
12500
|
var fn = evaluateNode(nameSymbol, contextStack);
|
|
12336
|
-
var partialFunction = {
|
|
12337
|
-
|
|
12338
|
-
|
|
12339
|
-
|
|
12340
|
-
params
|
|
12341
|
-
placeholders
|
|
12342
|
-
sourceCodeInfo
|
|
12343
|
-
|
|
12501
|
+
var partialFunction = (_a = {},
|
|
12502
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
12503
|
+
_a.function = asFunctionLike(fn, sourceCodeInfo),
|
|
12504
|
+
_a.functionType = 'Partial',
|
|
12505
|
+
_a.params = params,
|
|
12506
|
+
_a.placeholders = placeholders,
|
|
12507
|
+
_a.sourceCodeInfo = sourceCodeInfo,
|
|
12508
|
+
_a);
|
|
12344
12509
|
return partialFunction;
|
|
12345
12510
|
}
|
|
12346
12511
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -12360,14 +12525,14 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12360
12525
|
var fnNode = node[1][0];
|
|
12361
12526
|
var fn = asFunctionLike(evaluateNode(fnNode, contextStack), sourceCodeInfo);
|
|
12362
12527
|
if (placeholders.length > 0) {
|
|
12363
|
-
var partialFunction = {
|
|
12364
|
-
|
|
12365
|
-
|
|
12366
|
-
|
|
12367
|
-
params
|
|
12368
|
-
placeholders
|
|
12369
|
-
sourceCodeInfo
|
|
12370
|
-
|
|
12528
|
+
var partialFunction = (_b = {},
|
|
12529
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
12530
|
+
_b.function = asFunctionLike(fn, sourceCodeInfo),
|
|
12531
|
+
_b.functionType = 'Partial',
|
|
12532
|
+
_b.params = params,
|
|
12533
|
+
_b.placeholders = placeholders,
|
|
12534
|
+
_b.sourceCodeInfo = sourceCodeInfo,
|
|
12535
|
+
_b);
|
|
12371
12536
|
return partialFunction;
|
|
12372
12537
|
}
|
|
12373
12538
|
return executeFunction(fn, params, contextStack, sourceCodeInfo);
|