mathjs 7.5.1 → 7.6.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/HISTORY.md +7 -0
- package/dist/math.js +123 -29
- package/dist/math.min.js +3 -3
- package/dist/math.min.map +1 -1
- package/docs/datatypes/units.md +21 -0
- package/docs/reference/functions/rotate.md +47 -0
- package/docs/reference/functions/rotationMatrix.md +1 -1
- package/docs/reference/functions.md +1 -0
- package/es/entry/dependenciesAny/dependenciesRotate.generated.js +14 -0
- package/es/entry/dependenciesAny.generated.js +1 -0
- package/es/entry/impureFunctionsAny.generated.js +24 -23
- package/es/entry/pureFunctionsAny.generated.js +10 -5
- package/es/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/es/expression/embeddedDocs/function/matrix/rotate.js +8 -0
- package/es/expression/node/FunctionNode.js +1 -1
- package/es/expression/node/Node.js +2 -2
- package/es/factoriesAny.js +1 -0
- package/es/function/matrix/rotate.js +78 -0
- package/es/function/matrix/rotationMatrix.js +5 -4
- package/es/function/special/erf.js +1 -0
- package/es/plain/number/constants.js +1 -1
- package/es/plain/number/probability.js +1 -0
- package/es/type/unit/Unit.js +17 -18
- package/es/version.js +1 -1
- package/examples/bignumbers.js +2 -0
- package/lib/entry/dependenciesAny/dependenciesRotate.generated.js +26 -0
- package/lib/entry/dependenciesAny.generated.js +8 -0
- package/lib/entry/impureFunctionsAny.generated.js +27 -26
- package/lib/entry/mainAny.js +5 -0
- package/lib/entry/mainNumber.js +5 -0
- package/lib/entry/pureFunctionsAny.generated.js +14 -8
- package/lib/expression/embeddedDocs/embeddedDocs.js +3 -0
- package/lib/expression/embeddedDocs/function/matrix/rotate.js +15 -0
- package/lib/expression/node/FunctionNode.js +1 -1
- package/lib/expression/node/Node.js +2 -2
- package/lib/factoriesAny.js +8 -0
- package/lib/function/matrix/rotate.js +88 -0
- package/lib/function/matrix/rotationMatrix.js +5 -4
- package/lib/function/special/erf.js +1 -0
- package/lib/header.js +2 -2
- package/lib/plain/bignumber/index.js +1 -0
- package/lib/plain/number/constants.js +2 -1
- package/lib/plain/number/index.js +9 -0
- package/lib/plain/number/probability.js +1 -0
- package/lib/type/unit/Unit.js +17 -18
- package/lib/version.js +1 -1
- package/package.json +9 -9
- package/src/core/function/import.js +2 -2
- package/src/entry/dependenciesAny/dependenciesRotate.generated.js +15 -0
- package/src/entry/dependenciesAny.generated.js +1 -0
- package/src/entry/impureFunctionsAny.generated.js +20 -18
- package/src/entry/pureFunctionsAny.generated.js +7 -5
- package/src/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/src/expression/embeddedDocs/function/matrix/rotate.js +19 -0
- package/src/expression/node/FunctionNode.js +1 -1
- package/src/expression/node/Node.js +2 -1
- package/src/factoriesAny.js +1 -0
- package/src/function/matrix/rotate.js +79 -0
- package/src/function/matrix/rotationMatrix.js +5 -4
- package/src/function/special/erf.js +2 -0
- package/src/plain/number/constants.js +1 -1
- package/src/plain/number/probability.js +2 -0
- package/src/type/unit/Unit.js +18 -21
- package/src/version.js +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.6.0",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|
@@ -35,10 +35,10 @@
|
|
35
35
|
"typed-function": "^2.0.0"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
38
|
-
"@babel/core": "7.
|
39
|
-
"@babel/plugin-transform-object-assign": "7.
|
40
|
-
"@babel/preset-env": "7.
|
41
|
-
"@babel/register": "7.
|
38
|
+
"@babel/core": "7.12.3",
|
39
|
+
"@babel/plugin-transform-object-assign": "7.12.1",
|
40
|
+
"@babel/preset-env": "7.12.1",
|
41
|
+
"@babel/register": "7.12.1",
|
42
42
|
"babel-loader": "8.1.0",
|
43
43
|
"benchmark": "2.1.4",
|
44
44
|
"codecov": "3.8.0",
|
@@ -53,14 +53,14 @@
|
|
53
53
|
"jsep": "0.3.5",
|
54
54
|
"karma": "5.2.3",
|
55
55
|
"karma-browserstack-launcher": "1.6.0",
|
56
|
-
"karma-firefox-launcher": "
|
56
|
+
"karma-firefox-launcher": "2.0.0",
|
57
57
|
"karma-mocha": "2.0.1",
|
58
58
|
"karma-mocha-reporter": "2.2.5",
|
59
59
|
"karma-webpack": "4.0.2",
|
60
60
|
"lodash": "4.17.20",
|
61
61
|
"math-expression-evaluator": "1.2.22",
|
62
62
|
"mkdirp": "1.0.4",
|
63
|
-
"mocha": "8.
|
63
|
+
"mocha": "8.2.0",
|
64
64
|
"ndarray": "1.0.19",
|
65
65
|
"ndarray-determinant": "1.0.0",
|
66
66
|
"ndarray-gemm": "1.0.0",
|
@@ -69,9 +69,9 @@
|
|
69
69
|
"numericjs": "1.2.6",
|
70
70
|
"nyc": "15.1.0",
|
71
71
|
"pad-right": "0.2.2",
|
72
|
-
"standard": "
|
72
|
+
"standard": "16.0.1",
|
73
73
|
"sylvester": "0.0.21",
|
74
|
-
"uglify-js": "3.11.
|
74
|
+
"uglify-js": "3.11.4",
|
75
75
|
"webpack": "4.44.2",
|
76
76
|
"zeros": "1.0.0"
|
77
77
|
},
|
@@ -82,8 +82,8 @@ export function importFactory (typed, load, math, importedFactories) {
|
|
82
82
|
} else if (isFactory(value) || name !== undefined) {
|
83
83
|
const flatName = isFactory(value)
|
84
84
|
? isTransformFunctionFactory(value)
|
85
|
-
|
86
|
-
|
85
|
+
? (value.fn + '.transform') // TODO: this is ugly
|
86
|
+
: value.fn
|
87
87
|
: name
|
88
88
|
|
89
89
|
// we allow importing the same function twice if it points to the same implementation
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
3
|
+
* DON'T MAKE CHANGES HERE
|
4
|
+
*/
|
5
|
+
import { multiplyDependencies } from './dependenciesMultiply.generated'
|
6
|
+
import { rotationMatrixDependencies } from './dependenciesRotationMatrix.generated'
|
7
|
+
import { typedDependencies } from './dependenciesTyped.generated'
|
8
|
+
import { createRotate } from '../../factoriesAny.js'
|
9
|
+
|
10
|
+
export const rotateDependencies = {
|
11
|
+
multiplyDependencies,
|
12
|
+
rotationMatrixDependencies,
|
13
|
+
typedDependencies,
|
14
|
+
createRotate
|
15
|
+
}
|
@@ -82,6 +82,7 @@ export { onesDependencies } from './dependenciesAny/dependenciesOnes.generated'
|
|
82
82
|
export { rangeDependencies } from './dependenciesAny/dependenciesRange.generated'
|
83
83
|
export { reshapeDependencies } from './dependenciesAny/dependenciesReshape.generated'
|
84
84
|
export { resizeDependencies } from './dependenciesAny/dependenciesResize.generated'
|
85
|
+
export { rotateDependencies } from './dependenciesAny/dependenciesRotate.generated'
|
85
86
|
export { rotationMatrixDependencies } from './dependenciesAny/dependenciesRotationMatrix.generated'
|
86
87
|
export { rowDependencies } from './dependenciesAny/dependenciesRow.generated'
|
87
88
|
export { sizeDependencies } from './dependenciesAny/dependenciesSize.generated'
|
@@ -26,13 +26,13 @@ import {
|
|
26
26
|
createParse,
|
27
27
|
createEvaluate,
|
28
28
|
createHelpClass,
|
29
|
+
createParserClass,
|
30
|
+
createHelp,
|
31
|
+
createCompile,
|
29
32
|
createSimplify,
|
30
33
|
createRationalize,
|
31
|
-
createCompile,
|
32
|
-
createHelp,
|
33
|
-
createParserClass,
|
34
|
-
createDerivative,
|
35
34
|
createParser,
|
35
|
+
createDerivative,
|
36
36
|
createApplyTransform,
|
37
37
|
createFilterTransform,
|
38
38
|
createMapTransform,
|
@@ -325,13 +325,14 @@ import {
|
|
325
325
|
molarVolume,
|
326
326
|
planckTime,
|
327
327
|
thomsonCrossSection,
|
328
|
-
|
328
|
+
rotate,
|
329
329
|
mad,
|
330
330
|
coulomb,
|
331
331
|
magneticFluxQuantum,
|
332
332
|
rydberg,
|
333
|
-
|
334
|
-
gasConstant
|
333
|
+
unit,
|
334
|
+
gasConstant,
|
335
|
+
planckConstant
|
335
336
|
} from './pureFunctionsAny.generated'
|
336
337
|
|
337
338
|
const math = {} // NOT pure!
|
@@ -360,13 +361,13 @@ export const FunctionNode = createFunctionNode({ Node, SymbolNode, math })
|
|
360
361
|
export const parse = createParse({ AccessorNode, ArrayNode, AssignmentNode, BlockNode, ConditionalNode, ConstantNode, FunctionAssignmentNode, FunctionNode, IndexNode, ObjectNode, OperatorNode, ParenthesisNode, RangeNode, RelationalNode, SymbolNode, config, numeric, typed })
|
361
362
|
export const evaluate = createEvaluate({ parse, typed })
|
362
363
|
export const Help = createHelpClass({ parse })
|
364
|
+
export const Parser = createParserClass({ parse })
|
365
|
+
export const help = createHelp({ Help, mathWithTransform, typed })
|
366
|
+
export const compile = createCompile({ parse, typed })
|
363
367
|
export const simplify = createSimplify({ bignumber, fraction, ConstantNode, FunctionNode, OperatorNode, ParenthesisNode, SymbolNode, add, config, divide, equal, isZero, mathWithTransform, multiply, parse, pow, subtract, typed })
|
364
368
|
export const rationalize = createRationalize({ bignumber, fraction, ConstantNode, FunctionNode, OperatorNode, ParenthesisNode, SymbolNode, add, config, divide, equal, isZero, mathWithTransform, multiply, parse, pow, simplify, subtract, typed })
|
365
|
-
export const compile = createCompile({ parse, typed })
|
366
|
-
export const help = createHelp({ Help, mathWithTransform, typed })
|
367
|
-
export const Parser = createParserClass({ parse })
|
368
|
-
export const derivative = createDerivative({ ConstantNode, FunctionNode, OperatorNode, ParenthesisNode, SymbolNode, config, equal, isZero, numeric, parse, simplify, typed })
|
369
369
|
export const parser = createParser({ Parser, typed })
|
370
|
+
export const derivative = createDerivative({ ConstantNode, FunctionNode, OperatorNode, ParenthesisNode, SymbolNode, config, equal, isZero, numeric, parse, simplify, typed })
|
370
371
|
|
371
372
|
Object.assign(math, {
|
372
373
|
reviver,
|
@@ -633,21 +634,22 @@ Object.assign(math, {
|
|
633
634
|
molarVolume,
|
634
635
|
planckTime,
|
635
636
|
thomsonCrossSection,
|
636
|
-
|
637
|
+
rotate,
|
638
|
+
parse,
|
639
|
+
evaluate,
|
637
640
|
mad,
|
638
641
|
coulomb,
|
639
642
|
magneticFluxQuantum,
|
640
643
|
rydberg,
|
641
|
-
|
642
|
-
|
644
|
+
unit,
|
645
|
+
help,
|
646
|
+
gasConstant,
|
647
|
+
compile,
|
643
648
|
simplify,
|
644
649
|
rationalize,
|
650
|
+
parser,
|
645
651
|
planckConstant,
|
646
|
-
compile,
|
647
|
-
help,
|
648
|
-
gasConstant,
|
649
652
|
derivative,
|
650
|
-
parser,
|
651
653
|
config
|
652
654
|
})
|
653
655
|
|
@@ -277,13 +277,14 @@ import {
|
|
277
277
|
createMolarVolume,
|
278
278
|
createPlanckTime,
|
279
279
|
createThomsonCrossSection,
|
280
|
-
|
280
|
+
createRotate,
|
281
281
|
createMad,
|
282
282
|
createCoulomb,
|
283
283
|
createMagneticFluxQuantum,
|
284
284
|
createRydberg,
|
285
|
-
|
286
|
-
createGasConstant
|
285
|
+
createUnitFunction,
|
286
|
+
createGasConstant,
|
287
|
+
createPlanckConstant
|
287
288
|
} from '../factoriesAny'
|
288
289
|
|
289
290
|
export const ResultSet = /* #__PURE__ */ createResultSet({})
|
@@ -559,10 +560,11 @@ export const inverseConductanceQuantum = /* #__PURE__ */ createInverseConductanc
|
|
559
560
|
export const molarVolume = /* #__PURE__ */ createMolarVolume({ BigNumber, Unit, config })
|
560
561
|
export const planckTime = /* #__PURE__ */ createPlanckTime({ BigNumber, Unit, config })
|
561
562
|
export const thomsonCrossSection = /* #__PURE__ */ createThomsonCrossSection({ BigNumber, Unit, config })
|
562
|
-
export const
|
563
|
+
export const rotate = /* #__PURE__ */ createRotate({ multiply, rotationMatrix, typed })
|
563
564
|
export const mad = /* #__PURE__ */ createMad({ abs, map, median, subtract, typed })
|
564
565
|
export const coulomb = /* #__PURE__ */ createCoulomb({ BigNumber, Unit, config })
|
565
566
|
export const magneticFluxQuantum = /* #__PURE__ */ createMagneticFluxQuantum({ BigNumber, Unit, config })
|
566
567
|
export const rydberg = /* #__PURE__ */ createRydberg({ BigNumber, Unit, config })
|
567
|
-
export const
|
568
|
+
export const unit = /* #__PURE__ */ createUnitFunction({ Unit, typed })
|
568
569
|
export const gasConstant = /* #__PURE__ */ createGasConstant({ BigNumber, Unit, config })
|
570
|
+
export const planckConstant = /* #__PURE__ */ createPlanckConstant({ BigNumber, Unit, config })
|
@@ -215,6 +215,7 @@ import { numericDocs } from './function/utils/numeric'
|
|
215
215
|
import { columnDocs } from './function/matrix/column'
|
216
216
|
import { rowDocs } from './function/matrix/row'
|
217
217
|
import { rotationMatrixDocs } from './function/matrix/rotationMatrix'
|
218
|
+
import { rotateDocs } from './function/matrix/rotate'
|
218
219
|
|
219
220
|
export const embeddedDocs = {
|
220
221
|
|
@@ -427,6 +428,7 @@ export const embeddedDocs = {
|
|
427
428
|
range: rangeDocs,
|
428
429
|
resize: resizeDocs,
|
429
430
|
reshape: reshapeDocs,
|
431
|
+
rotate: rotateDocs,
|
430
432
|
rotationMatrix: rotationMatrixDocs,
|
431
433
|
row: rowDocs,
|
432
434
|
size: sizeDocs,
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export const rotateDocs = {
|
2
|
+
name: 'rotate',
|
3
|
+
category: 'Matrix',
|
4
|
+
syntax: [
|
5
|
+
'rotate(w, theta)',
|
6
|
+
'rotate(w, theta, v)'
|
7
|
+
],
|
8
|
+
description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' +
|
9
|
+
'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.',
|
10
|
+
examples: [
|
11
|
+
'rotate([1, 0], math.pi / 2)',
|
12
|
+
'rotate(matrix([1, 0]), unit("35deg"))',
|
13
|
+
'rotate([1, 0, 0], unit("90deg"), [0, 0, 1])',
|
14
|
+
'rotate(matrix([1, 0, 0]), unit("90deg"), matrix([0, 0, 1]))'
|
15
|
+
],
|
16
|
+
seealso: [
|
17
|
+
'matrix', 'rotationMatrix'
|
18
|
+
]
|
19
|
+
}
|
@@ -287,7 +287,7 @@ export const createFunctionNode = /* #__PURE__ */ factory(name, dependencies, ({
|
|
287
287
|
|
288
288
|
// Match everything of the form ${identifier} or ${identifier[2]} or $$
|
289
289
|
// while submatching identifier and 2 (in the second case)
|
290
|
-
const regex =
|
290
|
+
const regex = /\$(?:\{([a-z_][a-z_0-9]*)(?:\[([0-9]+)\])?\}|\$)/gi
|
291
291
|
|
292
292
|
let inputPos = 0 // position in the input string
|
293
293
|
let match
|
@@ -115,7 +115,8 @@ export const createNode = /* #__PURE__ */ factory(name, dependencies, ({ mathWit
|
|
115
115
|
*/
|
116
116
|
Node.prototype.traverse = function (callback) {
|
117
117
|
// execute callback for itself
|
118
|
-
|
118
|
+
// eslint-disable-next-line
|
119
|
+
callback(this, null, null)
|
119
120
|
|
120
121
|
// recursively traverse over all childs of a node
|
121
122
|
function _traverse (node, callback) {
|
package/src/factoriesAny.js
CHANGED
@@ -78,6 +78,7 @@ export { createOnes } from './function/matrix/ones'
|
|
78
78
|
export { createRange } from './function/matrix/range'
|
79
79
|
export { createReshape } from './function/matrix/reshape'
|
80
80
|
export { createResize } from './function/matrix/resize'
|
81
|
+
export { createRotate } from './function/matrix/rotate'
|
81
82
|
export { createRotationMatrix } from './function/matrix/rotationMatrix'
|
82
83
|
export { createRow } from './function/matrix/row'
|
83
84
|
export { createSize } from './function/matrix/size'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { factory } from '../../utils/factory'
|
2
|
+
import { arraySize } from '../../utils/array'
|
3
|
+
|
4
|
+
const name = 'rotate'
|
5
|
+
const dependencies = [
|
6
|
+
'typed',
|
7
|
+
'multiply',
|
8
|
+
'rotationMatrix'
|
9
|
+
]
|
10
|
+
|
11
|
+
export const createRotate = /* #__PURE__ */ factory(name, dependencies, (
|
12
|
+
{
|
13
|
+
typed, multiply, rotationMatrix
|
14
|
+
}) => {
|
15
|
+
/**
|
16
|
+
* Rotate a vector of size 1x2 counter-clockwise by a given angle
|
17
|
+
* Rotate a vector of size 1x3 counter-clockwise by a given angle around the given axis
|
18
|
+
*
|
19
|
+
* Syntax:
|
20
|
+
*
|
21
|
+
* math.rotate(w, theta)
|
22
|
+
* math.rotate(w, theta, v)
|
23
|
+
*
|
24
|
+
* Examples:
|
25
|
+
*
|
26
|
+
* math.rotate([11, 12], math.pi / 2) // returns matrix([-12, 11])
|
27
|
+
* math.rotate(matrix([11, 12]), math.pi / 2) // returns matrix([-12, 11])
|
28
|
+
*
|
29
|
+
* math.rotate([1, 0, 0], unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
30
|
+
* math.rotate(matrix([1, 0, 0]), unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
31
|
+
*
|
32
|
+
* math.rotate([1, 0], math.complex(1 + i)) // returns matrix([cos(1 + i) - sin(1 + i), sin(1 + i) + cos(1 + i)])
|
33
|
+
*
|
34
|
+
* See also:
|
35
|
+
*
|
36
|
+
* matrix, rotationMatrix
|
37
|
+
*
|
38
|
+
* @param {Array | Matrix} w Vector to rotate
|
39
|
+
* @param {number | BigNumber | Complex | Unit} theta Rotation angle
|
40
|
+
* @param {Array | Matrix} [v] Rotation axis
|
41
|
+
* @return {Array | Matrix} Multiplication of the rotation matrix and w
|
42
|
+
*/
|
43
|
+
return typed(name, {
|
44
|
+
'Array , number | BigNumber | Complex | Unit': function (w, theta) {
|
45
|
+
_validateSize(w, 2)
|
46
|
+
const matrixRes = multiply(rotationMatrix(theta), w)
|
47
|
+
return matrixRes.toArray()
|
48
|
+
},
|
49
|
+
|
50
|
+
'Matrix , number | BigNumber | Complex | Unit': function (w, theta) {
|
51
|
+
_validateSize(w, 2)
|
52
|
+
return multiply(rotationMatrix(theta), w)
|
53
|
+
},
|
54
|
+
|
55
|
+
'Array, number | BigNumber | Complex | Unit, Array | Matrix': function (w, theta, v) {
|
56
|
+
_validateSize(w, 3)
|
57
|
+
const matrixRes = multiply(rotationMatrix(theta, v), w)
|
58
|
+
return matrixRes
|
59
|
+
},
|
60
|
+
|
61
|
+
'Matrix, number | BigNumber | Complex | Unit, Array | Matrix': function (w, theta, v) {
|
62
|
+
_validateSize(w, 3)
|
63
|
+
return multiply(rotationMatrix(theta, v), w)
|
64
|
+
}
|
65
|
+
})
|
66
|
+
|
67
|
+
function _validateSize (v, expectedSize) {
|
68
|
+
const actualSize = Array.isArray(v) ? arraySize(v) : v.size()
|
69
|
+
if (actualSize.length > 2) {
|
70
|
+
throw new RangeError(`Vector must be of dimensions 1x${expectedSize}`)
|
71
|
+
}
|
72
|
+
if (actualSize.length === 2 && actualSize[1] !== 1) {
|
73
|
+
throw new RangeError(`Vector must be of dimensions 1x${expectedSize}`)
|
74
|
+
}
|
75
|
+
if (actualSize[0] !== expectedSize) {
|
76
|
+
throw new RangeError(`Vector must be of dimensions 1x${expectedSize}`)
|
77
|
+
}
|
78
|
+
}
|
79
|
+
})
|
@@ -37,7 +37,7 @@ export const createRotationMatrix = /* #__PURE__ */ factory(name, dependencies,
|
|
37
37
|
* Examples:
|
38
38
|
*
|
39
39
|
* math.rotationMatrix(math.pi / 2) // returns [[0, -1], [1, 0]]
|
40
|
-
* math.rotationMatrix(math.bignumber(
|
40
|
+
* math.rotationMatrix(math.bignumber(1)) // returns [[bignumber(cos(1)), bignumber(-sin(1))], [bignumber(sin(1)), bignumber(cos(1))]]
|
41
41
|
* math.rotationMatrix(math.complex(1 + i)) // returns [[cos(1 + i), -sin(1 + i)], [sin(1 + i), cos(1 + i)]]
|
42
42
|
* math.rotationMatrix(math.unit('1rad')) // returns [[cos(1), -sin(1)], [sin(1), cos(1)]]
|
43
43
|
*
|
@@ -76,12 +76,13 @@ export const createRotationMatrix = /* #__PURE__ */ factory(name, dependencies,
|
|
76
76
|
'number | BigNumber | Complex | Unit, Array': function (theta, v) {
|
77
77
|
const matrixV = matrix(v)
|
78
78
|
_validateVector(matrixV)
|
79
|
-
return _rotationMatrix3x3(theta, matrixV,
|
79
|
+
return _rotationMatrix3x3(theta, matrixV, undefined)
|
80
80
|
},
|
81
81
|
|
82
82
|
'number | BigNumber | Complex | Unit, Matrix': function (theta, v) {
|
83
83
|
_validateVector(v)
|
84
|
-
|
84
|
+
const storageType = v.storage() || (config.matrix === 'Matrix' ? 'dense' : undefined)
|
85
|
+
return _rotationMatrix3x3(theta, v, storageType)
|
85
86
|
},
|
86
87
|
|
87
88
|
'number | BigNumber | Complex | Unit, Array, string': function (theta, v, format) {
|
@@ -152,7 +153,7 @@ export const createRotationMatrix = /* #__PURE__ */ factory(name, dependencies,
|
|
152
153
|
function _rotationMatrix3x3 (theta, v, format) {
|
153
154
|
const normV = norm(v)
|
154
155
|
if (normV === 0) {
|
155
|
-
|
156
|
+
throw new RangeError('Rotation around zero vector')
|
156
157
|
}
|
157
158
|
|
158
159
|
const Big = isBigNumber(theta) ? BigNumber : null
|
package/src/type/unit/Unit.js
CHANGED
@@ -216,20 +216,15 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
|
|
216
216
|
let unitName = ''
|
217
217
|
|
218
218
|
// Alphanumeric characters only; matches [a-zA-Z0-9]
|
219
|
-
|
220
|
-
while ((code >= 48 && code <= 57) ||
|
221
|
-
(code >= 65 && code <= 90) ||
|
222
|
-
(code >= 97 && code <= 122)) {
|
219
|
+
while (isDigit(c) || Unit.isValidAlpha(c)) {
|
223
220
|
unitName += c
|
224
221
|
next()
|
225
|
-
code = text.charCodeAt(index)
|
226
222
|
}
|
227
223
|
|
228
224
|
// Must begin with [a-zA-Z]
|
229
|
-
|
230
|
-
if ((
|
231
|
-
|
232
|
-
return unitName || null
|
225
|
+
const firstC = unitName.charAt(0)
|
226
|
+
if (Unit.isValidAlpha(firstC)) {
|
227
|
+
return unitName
|
233
228
|
} else {
|
234
229
|
return null
|
235
230
|
}
|
@@ -1103,7 +1098,8 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
|
|
1103
1098
|
// Simplfy the unit list, unless it is valueless or was created directly in the
|
1104
1099
|
// constructor or as the result of to or toSI
|
1105
1100
|
const simp = this.skipAutomaticSimplification || this.value === null
|
1106
|
-
? this.clone()
|
1101
|
+
? this.clone()
|
1102
|
+
: this.simplify()
|
1107
1103
|
|
1108
1104
|
// Apply some custom logic for handling VA and VAR. The goal is to express the value of the unit as a real value, if possible. Otherwise, use a real-valued unit instead of a complex-valued one.
|
1109
1105
|
let isImaginary = false
|
@@ -3030,21 +3026,22 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
|
|
3030
3026
|
}
|
3031
3027
|
}
|
3032
3028
|
|
3029
|
+
/**
|
3030
|
+
* Checks if a character is a valid latin letter (upper or lower case).
|
3031
|
+
* Note that this function can be overridden, for example to allow support of other alphabets.
|
3032
|
+
* @param {string} c Tested character
|
3033
|
+
*/
|
3034
|
+
Unit.isValidAlpha = function isValidAlpha (c) {
|
3035
|
+
return /^[a-zA-Z]$/.test(c)
|
3036
|
+
}
|
3037
|
+
|
3033
3038
|
function assertUnitNameIsValid (name) {
|
3034
3039
|
for (let i = 0; i < name.length; i++) {
|
3035
|
-
|
3036
|
-
|
3037
|
-
const isValidAlpha = function (p) {
|
3038
|
-
return /^[a-zA-Z]$/.test(p)
|
3039
|
-
}
|
3040
|
-
|
3041
|
-
const isDigit = function (c) {
|
3042
|
-
return (c >= '0' && c <= '9')
|
3043
|
-
}
|
3040
|
+
c = name.charAt(i)
|
3044
3041
|
|
3045
|
-
if (i === 0 && !isValidAlpha(c)) { throw new Error('Invalid unit name (must begin with alpha character): "' + name + '"') }
|
3042
|
+
if (i === 0 && !Unit.isValidAlpha(c)) { throw new Error('Invalid unit name (must begin with alpha character): "' + name + '"') }
|
3046
3043
|
|
3047
|
-
if (i > 0 && !(isValidAlpha(c) ||
|
3044
|
+
if (i > 0 && !(Unit.isValidAlpha(c) ||
|
3048
3045
|
isDigit(c))) { throw new Error('Invalid unit name (only alphanumeric characters are allowed): "' + name + '"') }
|
3049
3046
|
}
|
3050
3047
|
}
|
package/src/version.js
CHANGED