symcrys 0.10.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/cell.d.ts +19 -16
- package/dist/cell.d.ts.map +1 -1
- package/dist/cell.js +63 -35
- package/dist/cell.js.map +1 -1
- package/dist/checks.d.ts +29 -0
- package/dist/checks.d.ts.map +1 -0
- package/dist/checks.js +79 -0
- package/dist/checks.js.map +1 -0
- package/dist/closure.d.ts +43 -0
- package/dist/closure.d.ts.map +1 -0
- package/dist/closure.js +201 -0
- package/dist/closure.js.map +1 -0
- package/dist/coordinates.d.ts +143 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +198 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/crystalClasses.d.ts +170 -117
- package/dist/crystalClasses.d.ts.map +1 -1
- package/dist/crystalClasses.js +190 -121
- package/dist/crystalClasses.js.map +1 -1
- package/dist/freeze.d.ts +7 -0
- package/dist/freeze.d.ts.map +1 -0
- package/dist/freeze.js +15 -0
- package/dist/freeze.js.map +1 -0
- package/dist/index.d.ts +13 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/indices.d.ts +30 -20
- package/dist/indices.d.ts.map +1 -1
- package/dist/indices.js +101 -31
- package/dist/indices.js.map +1 -1
- package/dist/lattice.d.ts +15 -1
- package/dist/lattice.d.ts.map +1 -1
- package/dist/lattice.js +30 -1
- package/dist/lattice.js.map +1 -1
- package/dist/linalg.d.ts +2 -2
- package/dist/linalg.d.ts.map +1 -1
- package/dist/linalg.js +3 -3
- package/dist/linalg.js.map +1 -1
- package/dist/magnetic.d.ts +14 -10
- package/dist/magnetic.d.ts.map +1 -1
- package/dist/magnetic.js +10 -6
- package/dist/magnetic.js.map +1 -1
- package/dist/notation.d.ts +16 -0
- package/dist/notation.d.ts.map +1 -0
- package/dist/notation.js +66 -0
- package/dist/notation.js.map +1 -0
- package/dist/operations.d.ts +40 -26
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +48 -60
- package/dist/operations.js.map +1 -1
- package/dist/plane.d.ts +297 -80
- package/dist/plane.d.ts.map +1 -1
- package/dist/plane.js +289 -94
- package/dist/plane.js.map +1 -1
- package/dist/pointGroups/crystalForms.d.ts +6 -21
- package/dist/pointGroups/crystalForms.d.ts.map +1 -1
- package/dist/pointGroups/crystalForms.js +9 -16
- package/dist/pointGroups/crystalForms.js.map +1 -1
- package/dist/pointGroups/crystalFormsData.d.ts +4 -1
- package/dist/pointGroups/crystalFormsData.d.ts.map +1 -1
- package/dist/pointGroups/crystalFormsData.js +64 -1
- package/dist/pointGroups/crystalFormsData.js.map +1 -1
- package/dist/pointGroups/elements.d.ts +19 -17
- package/dist/pointGroups/elements.d.ts.map +1 -1
- package/dist/pointGroups/elements.js +65 -83
- package/dist/pointGroups/elements.js.map +1 -1
- package/dist/pointGroups/identify.d.ts +10 -18
- package/dist/pointGroups/identify.d.ts.map +1 -1
- package/dist/pointGroups/identify.js +27 -79
- package/dist/pointGroups/identify.js.map +1 -1
- package/dist/pointGroups/itaOrder.d.ts +15 -14
- package/dist/pointGroups/itaOrder.d.ts.map +1 -1
- package/dist/pointGroups/itaOrder.js +116 -94
- package/dist/pointGroups/itaOrder.js.map +1 -1
- package/dist/pointGroups/itcData.d.ts +96 -0
- package/dist/pointGroups/itcData.d.ts.map +1 -0
- package/dist/pointGroups/itcData.js +336 -0
- package/dist/pointGroups/itcData.js.map +1 -0
- package/dist/pointGroups/itcMagneticData.d.ts +55 -0
- package/dist/pointGroups/itcMagneticData.d.ts.map +1 -0
- package/dist/pointGroups/itcMagneticData.js +172 -0
- package/dist/pointGroups/itcMagneticData.js.map +1 -0
- package/dist/pointGroups/keys.d.ts +32 -0
- package/dist/pointGroups/keys.d.ts.map +1 -0
- package/dist/pointGroups/keys.js +120 -0
- package/dist/pointGroups/keys.js.map +1 -0
- package/dist/pointGroups/magneticSymbols.d.ts +6 -5
- package/dist/pointGroups/magneticSymbols.d.ts.map +1 -1
- package/dist/pointGroups/magneticSymbols.js +15 -12
- package/dist/pointGroups/magneticSymbols.js.map +1 -1
- package/dist/pointGroups/orbits.d.ts +23 -42
- package/dist/pointGroups/orbits.d.ts.map +1 -1
- package/dist/pointGroups/orbits.js +20 -62
- package/dist/pointGroups/orbits.js.map +1 -1
- package/dist/pointGroups/pointGroups.d.ts +145 -68
- package/dist/pointGroups/pointGroups.d.ts.map +1 -1
- package/dist/pointGroups/pointGroups.js +455 -243
- package/dist/pointGroups/pointGroups.js.map +1 -1
- package/dist/pointGroups/properties.d.ts +21 -22
- package/dist/pointGroups/properties.d.ts.map +1 -1
- package/dist/pointGroups/properties.js +40 -37
- package/dist/pointGroups/properties.js.map +1 -1
- package/dist/pointGroups/seitzData.d.ts +26 -0
- package/dist/pointGroups/seitzData.d.ts.map +1 -0
- package/dist/pointGroups/seitzData.js +130 -0
- package/dist/pointGroups/seitzData.js.map +1 -0
- package/dist/pointGroups/shubnikovData.d.ts +11 -0
- package/dist/pointGroups/shubnikovData.d.ts.map +1 -0
- package/dist/pointGroups/shubnikovData.js +101 -0
- package/dist/pointGroups/shubnikovData.js.map +1 -0
- package/dist/pointGroups/wyckoff.d.ts +70 -40
- package/dist/pointGroups/wyckoff.d.ts.map +1 -1
- package/dist/pointGroups/wyckoff.js +98 -91
- package/dist/pointGroups/wyckoff.js.map +1 -1
- package/dist/pointGroups/wyckoffData.d.ts +7 -4
- package/dist/pointGroups/wyckoffData.d.ts.map +1 -1
- package/dist/pointGroups/wyckoffData.js +789 -168
- package/dist/pointGroups/wyckoffData.js.map +1 -1
- package/dist/siteSymmetry.d.ts +8 -16
- package/dist/siteSymmetry.d.ts.map +1 -1
- package/dist/siteSymmetry.js +34 -24
- package/dist/siteSymmetry.js.map +1 -1
- package/dist/spaceGroups/affine.d.ts.map +1 -1
- package/dist/spaceGroups/affine.js +3 -2
- package/dist/spaceGroups/affine.js.map +1 -1
- package/dist/spaceGroups/cell.d.ts +43 -31
- package/dist/spaceGroups/cell.d.ts.map +1 -1
- package/dist/spaceGroups/cell.js +173 -85
- package/dist/spaceGroups/cell.js.map +1 -1
- package/dist/spaceGroups/describe.d.ts +13 -10
- package/dist/spaceGroups/describe.d.ts.map +1 -1
- package/dist/spaceGroups/describe.js +11 -10
- package/dist/spaceGroups/describe.js.map +1 -1
- package/dist/spaceGroups/planeGroupData.d.ts +3 -1
- package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
- package/dist/spaceGroups/planeGroupData.js +25 -8
- package/dist/spaceGroups/planeGroupData.js.map +1 -1
- package/dist/spaceGroups/planeGroups.d.ts.map +1 -1
- package/dist/spaceGroups/planeGroups.js +2 -1
- package/dist/spaceGroups/planeGroups.js.map +1 -1
- package/dist/spaceGroups/planeLattice.d.ts +78 -0
- package/dist/spaceGroups/planeLattice.d.ts.map +1 -0
- package/dist/spaceGroups/planeLattice.js +143 -0
- package/dist/spaceGroups/planeLattice.js.map +1 -0
- package/dist/spaceGroups/planePointGroups.d.ts +6 -2
- package/dist/spaceGroups/planePointGroups.d.ts.map +1 -1
- package/dist/spaceGroups/planePointGroups.js +14 -2
- package/dist/spaceGroups/planePointGroups.js.map +1 -1
- package/dist/spaceGroups/positions.d.ts +48 -19
- package/dist/spaceGroups/positions.d.ts.map +1 -1
- package/dist/spaceGroups/positions.js +166 -67
- package/dist/spaceGroups/positions.js.map +1 -1
- package/dist/spaceGroups/rational.d.ts +18 -0
- package/dist/spaceGroups/rational.d.ts.map +1 -1
- package/dist/spaceGroups/rational.js +58 -0
- package/dist/spaceGroups/rational.js.map +1 -1
- package/dist/tensors/propertyTable.d.ts +3 -1
- package/dist/tensors/propertyTable.d.ts.map +1 -1
- package/dist/tensors/propertyTable.js +17 -10
- package/dist/tensors/propertyTable.js.map +1 -1
- package/dist/tensors/rowEchelon.d.ts +3 -3
- package/dist/tensors/rowEchelon.d.ts.map +1 -1
- package/dist/tensors/rowEchelon.js +4 -4
- package/dist/tensors/rowEchelon.js.map +1 -1
- package/dist/tensors/tensorForm.d.ts +75 -34
- package/dist/tensors/tensorForm.d.ts.map +1 -1
- package/dist/tensors/tensorForm.js +171 -67
- package/dist/tensors/tensorForm.js.map +1 -1
- package/dist/tensors/tensorProperties.d.ts +10 -9
- package/dist/tensors/tensorProperties.d.ts.map +1 -1
- package/dist/tensors/tensorProperties.js +22 -12
- package/dist/tensors/tensorProperties.js.map +1 -1
- package/dist/tensors/voigt.d.ts +56 -0
- package/dist/tensors/voigt.d.ts.map +1 -0
- package/dist/tensors/voigt.js +188 -0
- package/dist/tensors/voigt.js.map +1 -0
- package/dist/tolerances.d.ts +56 -1
- package/dist/tolerances.d.ts.map +1 -1
- package/dist/tolerances.js +51 -1
- package/dist/tolerances.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/cell.ts +78 -51
- package/src/checks.ts +84 -0
- package/src/closure.ts +214 -0
- package/src/coordinates.ts +370 -0
- package/src/crystalClasses.ts +271 -157
- package/src/freeze.ts +14 -0
- package/src/index.ts +33 -12
- package/src/indices.ts +102 -42
- package/src/lattice.ts +41 -1
- package/src/linalg.ts +3 -3
- package/src/magnetic.ts +24 -11
- package/src/notation.ts +73 -0
- package/src/operations.ts +78 -71
- package/src/plane.ts +531 -151
- package/src/pointGroups/crystalForms.ts +11 -44
- package/src/pointGroups/crystalFormsData.ts +66 -1
- package/src/pointGroups/elements.ts +82 -92
- package/src/pointGroups/identify.ts +38 -97
- package/src/pointGroups/itaOrder.ts +117 -101
- package/src/pointGroups/itcData.ts +404 -0
- package/src/pointGroups/itcMagneticData.ts +206 -0
- package/src/pointGroups/keys.ts +144 -0
- package/src/pointGroups/magneticSymbols.ts +18 -17
- package/src/pointGroups/orbits.ts +41 -89
- package/src/pointGroups/pointGroups.ts +593 -298
- package/src/pointGroups/properties.ts +44 -40
- package/src/pointGroups/seitzData.ts +147 -0
- package/src/pointGroups/shubnikovData.ts +103 -0
- package/src/pointGroups/wyckoff.ts +137 -112
- package/src/pointGroups/wyckoffData.ts +793 -170
- package/src/siteSymmetry.ts +43 -40
- package/src/spaceGroups/affine.ts +3 -2
- package/src/spaceGroups/cell.ts +227 -116
- package/src/spaceGroups/describe.ts +23 -19
- package/src/spaceGroups/planeGroupData.ts +28 -9
- package/src/spaceGroups/planeGroups.ts +2 -1
- package/src/spaceGroups/planeLattice.ts +208 -0
- package/src/spaceGroups/planePointGroups.ts +23 -3
- package/src/spaceGroups/positions.ts +202 -78
- package/src/spaceGroups/rational.ts +59 -0
- package/src/tensors/propertyTable.ts +26 -14
- package/src/tensors/rowEchelon.ts +4 -3
- package/src/tensors/tensorForm.ts +258 -88
- package/src/tensors/tensorProperties.ts +34 -14
- package/src/tensors/voigt.ts +268 -0
- package/src/tolerances.ts +66 -1
- package/src/version.ts +1 -1
- package/dist/pointGroups/data.d.ts +0 -75
- package/dist/pointGroups/data.d.ts.map +0 -1
- package/dist/pointGroups/data.js +0 -212
- package/dist/pointGroups/data.js.map +0 -1
- package/dist/pointGroups/magneticData.d.ts +0 -66
- package/dist/pointGroups/magneticData.d.ts.map +0 -1
- package/dist/pointGroups/magneticData.js +0 -184
- package/dist/pointGroups/magneticData.js.map +0 -1
- package/dist/spaceGroups/snap.d.ts +0 -20
- package/dist/spaceGroups/snap.d.ts.map +0 -1
- package/dist/spaceGroups/snap.js +0 -103
- package/dist/spaceGroups/snap.js.map +0 -1
- package/src/pointGroups/data.ts +0 -305
- package/src/pointGroups/magneticData.ts +0 -328
- package/src/spaceGroups/snap.ts +0 -121
package/src/freeze.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Freezing of results: every result of the API is frozen, nested arrays and objects included
|
|
3
|
+
* (#137 C4), so that a caller who wants to change one copies it. Internal.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** `value`, frozen with everything it holds (plain arrays and objects). */
|
|
7
|
+
export function deepFreeze<T>(value: T): T {
|
|
8
|
+
if (value !== null && typeof value === 'object') {
|
|
9
|
+
// Also into a container that is frozen already: its children need not be.
|
|
10
|
+
for (const v of Object.values(value)) deepFreeze(v);
|
|
11
|
+
Object.freeze(value);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* SemVer (see CLAUDE.md); everything else is internal.
|
|
7
7
|
*/
|
|
8
8
|
export { VERSION } from './version.js';
|
|
9
|
+
export { EPSILON, type ToleranceOptions } from './tolerances.js';
|
|
9
10
|
|
|
10
11
|
export type { Mat3, Vec3 } from './linalg.js';
|
|
11
12
|
export {
|
|
@@ -14,10 +15,12 @@ export {
|
|
|
14
15
|
type CrystalFamily,
|
|
15
16
|
type CrystalSystem,
|
|
16
17
|
type FixedAngleFamily,
|
|
18
|
+
type LatticeSystem,
|
|
17
19
|
} from './lattice.js';
|
|
18
20
|
export {
|
|
19
21
|
angleBetweenDirections,
|
|
20
22
|
angleBetweenPlanes,
|
|
23
|
+
faceNormal,
|
|
21
24
|
isValidCell,
|
|
22
25
|
latticeFromParameters,
|
|
23
26
|
latticeParameters,
|
|
@@ -27,29 +30,43 @@ export {
|
|
|
27
30
|
type CellOperation,
|
|
28
31
|
type IsValidCellOptions,
|
|
29
32
|
type LatticeParameters,
|
|
30
|
-
type ResidualOperationsOptions,
|
|
31
33
|
} from './cell.js';
|
|
32
34
|
export {
|
|
33
|
-
changeOfAxes,
|
|
34
35
|
directionFromFourIndices,
|
|
35
36
|
directionToFourIndices,
|
|
36
37
|
planeFromFourIndices,
|
|
37
38
|
planeToFourIndices,
|
|
39
|
+
millerIndices,
|
|
38
40
|
reduceIndices,
|
|
39
41
|
zoneAxis,
|
|
40
|
-
type AxisChange,
|
|
41
42
|
type FourIndices,
|
|
43
|
+
type MillerValues,
|
|
42
44
|
} from './indices.js';
|
|
45
|
+
export {
|
|
46
|
+
changeOfCoordinates,
|
|
47
|
+
type AffineOperation,
|
|
48
|
+
type CoordinateChange,
|
|
49
|
+
type CoordinateQuantities,
|
|
50
|
+
type CoordinateTransformation,
|
|
51
|
+
type InverseTransformation,
|
|
52
|
+
type TransformedOperation,
|
|
53
|
+
} from './coordinates.js';
|
|
43
54
|
|
|
44
|
-
export type {
|
|
55
|
+
export type { PointGroupKey, Setting, AxesOptions, SettingOptions, SymbolOptions } from './pointGroups/pointGroups.js';
|
|
45
56
|
export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
|
|
46
57
|
export type { Axis, DirectionElements, OperationKind, SymmetryDirection } from './pointGroups/elements.js';
|
|
47
|
-
export type { SiteSymmetry
|
|
48
|
-
export type { Hkl,
|
|
58
|
+
export type { SiteSymmetry } from './siteSymmetry.js';
|
|
59
|
+
export type { Hkl, WyckoffPosition } from './pointGroups/wyckoff.js';
|
|
49
60
|
export type { CrystalForm, CrystalFormType } from './pointGroups/crystalForms.js';
|
|
50
|
-
export type {
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
export type {
|
|
62
|
+
DirectionIndices,
|
|
63
|
+
DirectionOrbitEntry,
|
|
64
|
+
FaceIndices,
|
|
65
|
+
FaceOrbitEntry,
|
|
66
|
+
OrbitPole,
|
|
67
|
+
} from './pointGroups/orbits.js';
|
|
68
|
+
export type { CartesianAxis } from './pointGroups/identify.js';
|
|
69
|
+
export type { IntrinsicSymmetry, TensorForm, TensorKind, TensorRank } from './tensors/tensorForm.js';
|
|
53
70
|
|
|
54
71
|
export {
|
|
55
72
|
CRYSTAL_FORM_TYPES,
|
|
@@ -66,9 +83,9 @@ export {
|
|
|
66
83
|
generators,
|
|
67
84
|
holohedry,
|
|
68
85
|
isCentrosymmetricOf,
|
|
69
|
-
|
|
86
|
+
isEnantiomorphicOf,
|
|
70
87
|
isPointGroupKey,
|
|
71
|
-
|
|
88
|
+
latticeSystems,
|
|
72
89
|
residualOperations,
|
|
73
90
|
operations,
|
|
74
91
|
orbit,
|
|
@@ -77,13 +94,16 @@ export {
|
|
|
77
94
|
pointGroupOf,
|
|
78
95
|
pointGroups,
|
|
79
96
|
rotateTensor,
|
|
97
|
+
toVoigt,
|
|
98
|
+
fromVoigt,
|
|
80
99
|
settings,
|
|
81
100
|
siteSymmetry,
|
|
101
|
+
siteSymmetryOf,
|
|
82
102
|
symbol,
|
|
83
103
|
symmetryDirections,
|
|
84
104
|
tensorForm,
|
|
85
105
|
tensorFormOf,
|
|
86
|
-
|
|
106
|
+
wyckoffPosition,
|
|
87
107
|
wyckoffPositions,
|
|
88
108
|
type CartesianOperationDescription,
|
|
89
109
|
type IdentifiedPointGroup,
|
|
@@ -95,3 +115,4 @@ export {
|
|
|
95
115
|
type TensorPropertyName,
|
|
96
116
|
type TensorSpec,
|
|
97
117
|
} from './crystalClasses.js';
|
|
118
|
+
export type { VoigtFactor, VoigtOptions } from './tensors/voigt.js';
|
package/src/indices.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Miller and Miller
|
|
3
|
-
*
|
|
2
|
+
* Miller and Bravais–Miller indices and the zone law (docs/conventions.md, "Cell, metric and
|
|
3
|
+
* indices"); the change of the coordinate system is in coordinates.ts. Plain integers and matrices in and out.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { shown } from './checks.js';
|
|
7
|
+
import { type Vec3 } from './linalg.js';
|
|
8
|
+
import { deepFreeze } from './freeze.js';
|
|
7
9
|
|
|
8
|
-
/** A direction [UVTW] or a plane (hkil) in four indices (Miller
|
|
10
|
+
/** A direction [UVTW] or a plane (hkil) in four indices (Bravais–Miller). */
|
|
9
11
|
export type FourIndices = readonly [number, number, number, number];
|
|
10
12
|
|
|
11
13
|
function gcd(a: number, b: number): number {
|
|
@@ -22,33 +24,31 @@ function integers(v: readonly number[], who: string, length?: number): void {
|
|
|
22
24
|
v.length === 0 ||
|
|
23
25
|
!v.every((x) => Number.isSafeInteger(x))
|
|
24
26
|
) {
|
|
25
|
-
throw new RangeError(
|
|
26
|
-
`${who}: ${length === undefined ? 'a list of' : length} integers expected, not ${JSON.stringify(v)}`,
|
|
27
|
-
);
|
|
27
|
+
throw new RangeError(`${who}: ${length === undefined ? 'a list of' : length} integers expected, not ${shown(v)}`);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** The indices divided by their greatest common divisor, signs kept. Throws a RangeError for non-integers and for all zeros. */
|
|
32
|
-
export function reduceIndices(indices: readonly number[]): number[] {
|
|
32
|
+
export function reduceIndices(indices: readonly number[]): readonly number[] {
|
|
33
33
|
integers(indices, 'reduceIndices');
|
|
34
34
|
const g = indices.reduce(gcd, 0);
|
|
35
35
|
if (g === 0) throw new RangeError('reduceIndices: all indices are zero');
|
|
36
|
-
return indices.map((x) => x / g + 0);
|
|
36
|
+
return deepFreeze(indices.map((x) => x / g + 0));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** The plane (hkl) of hexagonal axes as (hkil) with i = −(h + k). */
|
|
40
40
|
export function planeToFourIndices(hkl: Vec3): FourIndices {
|
|
41
41
|
integers(hkl, 'planeToFourIndices', 3);
|
|
42
42
|
if (hkl.every((x) => x === 0)) throw new RangeError('planeToFourIndices: zero vector');
|
|
43
|
-
return [hkl[0] + 0, hkl[1] + 0, -(hkl[0] + hkl[1]) + 0, hkl[2] + 0];
|
|
43
|
+
return deepFreeze([hkl[0] + 0, hkl[1] + 0, -(hkl[0] + hkl[1]) + 0, hkl[2] + 0]);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/** The plane (hkil) as (hkl); throws a RangeError unless i = −(h + k). */
|
|
47
47
|
export function planeFromFourIndices(hkil: FourIndices): Vec3 {
|
|
48
48
|
integers(hkil, 'planeFromFourIndices', 4);
|
|
49
49
|
if (hkil[2] !== -(hkil[0] + hkil[1]))
|
|
50
|
-
throw new RangeError(`planeFromFourIndices: i must be −(h + k) in ${
|
|
51
|
-
return [hkil[0] + 0, hkil[1] + 0, hkil[3] + 0];
|
|
50
|
+
throw new RangeError(`planeFromFourIndices: i must be −(h + k) in ${shown(hkil)}`);
|
|
51
|
+
return deepFreeze([hkil[0] + 0, hkil[1] + 0, hkil[3] + 0]);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -59,7 +59,7 @@ export function directionToFourIndices(uvw: Vec3): FourIndices {
|
|
|
59
59
|
integers(uvw, 'directionToFourIndices', 3);
|
|
60
60
|
const [u, v, w] = uvw;
|
|
61
61
|
if (u === 0 && v === 0 && w === 0) throw new RangeError('directionToFourIndices: zero vector');
|
|
62
|
-
return reduceIndices([2 * u - v, 2 * v - u, -(u + v), 3 * w]) as unknown as FourIndices;
|
|
62
|
+
return deepFreeze(reduceIndices([2 * u - v, 2 * v - u, -(u + v), 3 * w]) as unknown as FourIndices);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/** The direction [UVTW] as [uvw], reduced: u = U − T, v = V − T, w = W; throws a RangeError unless T = −(U + V). */
|
|
@@ -67,51 +67,111 @@ export function directionFromFourIndices(uvtw: FourIndices): Vec3 {
|
|
|
67
67
|
integers(uvtw, 'directionFromFourIndices', 4);
|
|
68
68
|
if (uvtw.every((x) => x === 0)) throw new RangeError('directionFromFourIndices: zero vector');
|
|
69
69
|
const [U, V, T, W] = uvtw;
|
|
70
|
-
if (T !== -(U + V)) throw new RangeError(`directionFromFourIndices: T must be −(U + V) in ${
|
|
71
|
-
return reduceIndices([U - T, V - T, W]) as unknown as Vec3;
|
|
70
|
+
if (T !== -(U + V)) throw new RangeError(`directionFromFourIndices: T must be −(U + V) in ${shown(uvtw)}`);
|
|
71
|
+
return deepFreeze(reduceIndices([U - T, V - T, W]) as unknown as Vec3);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* The zone axis [uvw] of two planes (hkl), which must not be zero vectors: the solution of the zone law hu + kv + lw = 0, the
|
|
76
|
-
* cross product h₁ × h₂ reduced (so its sign follows the order of the planes), or `
|
|
76
|
+
* cross product h₁ × h₂ reduced (so its sign follows the order of the planes), or `undefined` for parallel planes.
|
|
77
77
|
*/
|
|
78
|
-
export function zoneAxis(h1: Vec3, h2: Vec3): Vec3 |
|
|
78
|
+
export function zoneAxis(h1: Vec3, h2: Vec3): Vec3 | undefined {
|
|
79
79
|
integers(h1, 'zoneAxis', 3);
|
|
80
80
|
integers(h2, 'zoneAxis', 3);
|
|
81
81
|
if (h1.every((x) => x === 0) || h2.every((x) => x === 0)) throw new RangeError('zoneAxis: zero vector');
|
|
82
82
|
const c = [h1[1] * h2[2] - h1[2] * h2[1], h1[2] * h2[0] - h1[0] * h2[2], h1[0] * h2[1] - h1[1] * h2[0]];
|
|
83
83
|
if (!c.every((x) => Number.isSafeInteger(x)))
|
|
84
84
|
throw new RangeError('zoneAxis: the cross product exceeds the safe integers');
|
|
85
|
-
if (c.every((x) => x === 0)) return
|
|
86
|
-
return reduceIndices(c) as unknown as Vec3;
|
|
85
|
+
if (c.every((x) => x === 0)) return undefined;
|
|
86
|
+
return deepFreeze(reduceIndices(c) as unknown as Vec3);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
/** The
|
|
90
|
-
export interface
|
|
91
|
-
/**
|
|
92
|
-
readonly
|
|
93
|
-
/**
|
|
94
|
-
readonly
|
|
89
|
+
/** The values of h, k, l substituted into printed Miller indices. */
|
|
90
|
+
export interface MillerValues {
|
|
91
|
+
/** The value of h, an integer. */
|
|
92
|
+
readonly h?: number;
|
|
93
|
+
/** The value of k, an integer. */
|
|
94
|
+
readonly k?: number;
|
|
95
|
+
/** The value of l, an integer. */
|
|
96
|
+
readonly l?: number;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* both bases. Throws a RangeError unless det P > 0 (a right-handed basis), and for a P that is
|
|
102
|
-
* singular within rounding (the absolute value of det P at most 10⁻⁹ times the product of its
|
|
103
|
-
* column lengths).
|
|
100
|
+
* One printed index as a number: a term (`h`, `-2h`, `0`, `1`) or a sum of terms (`-h-k`, `2k-h`, as
|
|
101
|
+
* printed for rhombohedral axes); `i` is −(h + k). `fail` makes the error: a RangeError for a
|
|
102
|
+
* caller's string, a plain Error for the transcribed data.
|
|
104
103
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
) {
|
|
111
|
-
|
|
104
|
+
function printedIndex(component: string, values: MillerValues, fail: (message: string) => Error): number {
|
|
105
|
+
// A term is a signed number, or a signed letter with an optional factor; terms after the first
|
|
106
|
+
// begin with their sign, so that run-together terms (`hk`, `h2`) are unreadable.
|
|
107
|
+
if (!/^-?(\d+|\d*[hkil])([+-](\d+|\d*[hkil]))*$/.test(component)) throw fail(`Unreadable Miller index: ${component}`);
|
|
108
|
+
const terms = component.match(/[+-]?\d*[hkil]?/g)!.filter((t) => t !== '');
|
|
109
|
+
const value = (letter: 'h' | 'k' | 'l'): number => {
|
|
110
|
+
const v = values[letter];
|
|
111
|
+
if (v === undefined) throw fail(`The Miller index ${component} needs a value of ${letter}`);
|
|
112
|
+
return v;
|
|
113
|
+
};
|
|
114
|
+
const result = terms.reduce((sum, term) => {
|
|
115
|
+
const m = /^([+-]?)(\d*)([hkil]?)$/.exec(term)!;
|
|
116
|
+
const sign = m[1] === '-' ? -1 : 1;
|
|
117
|
+
const factor = m[2] === '' ? 1 : Number(m[2]);
|
|
118
|
+
if (!Number.isSafeInteger(factor)) throw fail(`The factor in ${component} is not a safe integer`);
|
|
119
|
+
if (m[3] === '') return sum + sign * factor;
|
|
120
|
+
if (m[3] === 'i') return sum + sign * factor * -(value('h') + value('k'));
|
|
121
|
+
return sum + sign * factor * value(m[3] as 'h' | 'k' | 'l');
|
|
122
|
+
}, 0);
|
|
123
|
+
if (!Number.isSafeInteger(result)) throw fail(`The Miller index ${component} is not a safe integer: ${result}`);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Printed Miller indices, three or four (Bravais–Miller, hexagonal axes) separated by commas, as
|
|
129
|
+
* three numbers (hkl) with the given values of h, k, l; four lose i, which must be −(h + k). Internal:
|
|
130
|
+
* `fail` makes the error.
|
|
131
|
+
*/
|
|
132
|
+
export function substituteMillerIndices(printed: string, values: MillerValues, fail: (message: string) => Error): Vec3 {
|
|
133
|
+
const components = printed.split(',').map((c) => c.trim());
|
|
134
|
+
// i is the third of four indices; ITA prints no i among three.
|
|
135
|
+
if (components.length === 3 && components.some((c) => c.includes('i'))) {
|
|
136
|
+
throw fail(`Unreadable Miller indices: ${printed} (i among three indices)`);
|
|
137
|
+
}
|
|
138
|
+
const parts = components.map((c) => printedIndex(c, values, fail) + 0);
|
|
139
|
+
if (parts.length === 3) return [parts[0], parts[1], parts[2]];
|
|
140
|
+
if (parts.length === 4 && parts[2] === -(parts[0] + parts[1])) return [parts[0], parts[1], parts[3]];
|
|
141
|
+
throw fail(`Unreadable Miller indices: ${printed}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The face (hkl) of printed Miller indices with the caller's values of h, k, l substituted (#137 G3):
|
|
146
|
+
* the printed `h,h,-2h,l` with h = 3 and l = 1 gives (3, 3, 1). The printed strings are those of
|
|
147
|
+
* `wyckoffPositions` and `crystalForms` (`millerIndices`), as ITA prints them: three indices, or four
|
|
148
|
+
* for hexagonal axes, of which i = −(h + k) is dropped, so that the face can be passed to `orbit`
|
|
149
|
+
* (`planeToFourIndices` gives the four). Each value is an integer; only the letters the string uses
|
|
150
|
+
* are needed. The face is not reduced, and whether the values keep it in its position (a general
|
|
151
|
+
* face (hkl) with h = k lies on a special one) is the caller's choice. Throws a RangeError for an
|
|
152
|
+
* unreadable string, a missing or non-integer value, an unknown key and the face (000).
|
|
153
|
+
*/
|
|
154
|
+
export function millerIndices(printed: string, values: MillerValues): Vec3 {
|
|
155
|
+
if (typeof printed !== 'string')
|
|
156
|
+
throw new RangeError(`millerIndices: printed Miller indices expected, not ${shown(printed)}`);
|
|
157
|
+
if (values === null || typeof values !== 'object' || Array.isArray(values)) {
|
|
158
|
+
throw new RangeError(`millerIndices: values { h, k, l } expected, not ${shown(values)}`);
|
|
159
|
+
}
|
|
160
|
+
for (const key of Object.keys(values)) {
|
|
161
|
+
if (!['h', 'k', 'l'].includes(key)) throw new RangeError(`millerIndices: unknown value ${shown(key)} (h, k or l)`);
|
|
162
|
+
}
|
|
163
|
+
// The own values only, each checked as it is read (an inherited or non-enumerable one included).
|
|
164
|
+
const own: { h?: number; k?: number; l?: number } = {};
|
|
165
|
+
for (const letter of ['h', 'k', 'l'] as const) {
|
|
166
|
+
if (!Object.hasOwn(values, letter)) continue;
|
|
167
|
+
const v: unknown = values[letter];
|
|
168
|
+
if (v === undefined) continue;
|
|
169
|
+
if (!Number.isSafeInteger(v)) throw new RangeError(`millerIndices: ${letter} must be an integer, not ${shown(v)}`);
|
|
170
|
+
own[letter] = v as number;
|
|
112
171
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
172
|
+
// Spaces around the commas are allowed; a space inside an index is unreadable.
|
|
173
|
+
const hkl = substituteMillerIndices(printed, own, (m) => new RangeError(`millerIndices: ${m}`));
|
|
174
|
+
if (hkl.every((x) => x === 0))
|
|
175
|
+
throw new RangeError(`millerIndices: ${printed} gives the face (000) with ${shown(values)}`);
|
|
176
|
+
return deepFreeze(hkl);
|
|
117
177
|
}
|
package/src/lattice.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* of symcrys (docs/conventions.md, "Cartesian frame").
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { shown } from './checks.js';
|
|
6
7
|
import type { Mat3 } from './linalg.js';
|
|
7
8
|
|
|
8
9
|
/** One of the seven crystal systems. */
|
|
@@ -12,11 +13,50 @@ export type CrystalSystem =
|
|
|
12
13
|
/** One of the six crystal families: the trigonal and the hexagonal system form the hexagonal family. */
|
|
13
14
|
export type CrystalFamily = 'triclinic' | 'monoclinic' | 'orthorhombic' | 'tetragonal' | 'hexagonal' | 'cubic';
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
const SYSTEMS: readonly string[] = [
|
|
17
|
+
'triclinic',
|
|
18
|
+
'monoclinic',
|
|
19
|
+
'orthorhombic',
|
|
20
|
+
'tetragonal',
|
|
21
|
+
'trigonal',
|
|
22
|
+
'hexagonal',
|
|
23
|
+
'cubic',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The crystal family of a crystal system: trigonal and hexagonal form the hexagonal family. Throws
|
|
28
|
+
* a RangeError for anything that is not one of the seven crystal systems.
|
|
29
|
+
*/
|
|
16
30
|
export function crystalFamily(system: CrystalSystem): CrystalFamily {
|
|
31
|
+
if (!SYSTEMS.includes(system)) throw new RangeError(`Unknown crystal system: ${shown(system)}`);
|
|
17
32
|
return system === 'trigonal' ? 'hexagonal' : system;
|
|
18
33
|
}
|
|
19
34
|
|
|
35
|
+
/**
|
|
36
|
+
* One of the seven lattice systems of ITA Table 1.3.4.1 (p. 39): the lattices whose point symmetry
|
|
37
|
+
* is the same holohedry. The hexagonal family has two, `'hexagonal'` (hP) and `'rhombohedral'` (hR).
|
|
38
|
+
*/
|
|
39
|
+
export type LatticeSystem =
|
|
40
|
+
'triclinic' | 'monoclinic' | 'orthorhombic' | 'tetragonal' | 'hexagonal' | 'rhombohedral' | 'cubic';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The lattice systems on which the point groups of a crystal system act (ITA § 1.3.4.4.2, p. 39):
|
|
44
|
+
* both of the hexagonal family for the trigonal system, which belongs to either depending on the
|
|
45
|
+
* basis, otherwise the one of the same name.
|
|
46
|
+
*/
|
|
47
|
+
export function latticeSystemsOfSystem(system: CrystalSystem): readonly LatticeSystem[] {
|
|
48
|
+
if (!SYSTEMS.includes(system)) throw new RangeError(`Unknown crystal system: ${shown(system)}`);
|
|
49
|
+
if (system === 'trigonal') return TRIGONAL;
|
|
50
|
+
return LATTICE_SYSTEM_OF[system];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const TRIGONAL: readonly LatticeSystem[] = Object.freeze(['hexagonal', 'rhombohedral']);
|
|
54
|
+
const LATTICE_SYSTEM_OF = Object.freeze(
|
|
55
|
+
Object.fromEntries(
|
|
56
|
+
['triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 'hexagonal', 'cubic'].map((s) => [s, Object.freeze([s])]),
|
|
57
|
+
),
|
|
58
|
+
) as Readonly<Record<Exclude<CrystalSystem, 'trigonal'>, readonly LatticeSystem[]>>;
|
|
59
|
+
|
|
20
60
|
/** The families whose cell angles are fixed, so that their lattice basis is fixed up to edge lengths. */
|
|
21
61
|
export type FixedAngleFamily = 'orthorhombic' | 'tetragonal' | 'hexagonal' | 'cubic';
|
|
22
62
|
|
package/src/linalg.ts
CHANGED
|
@@ -105,11 +105,11 @@ export function rotationY(angleDeg: number): Mat3 {
|
|
|
105
105
|
*/
|
|
106
106
|
const SNAP_VALUES = [0, 1, -1, 0.5, -0.5, Math.SQRT1_2, -Math.SQRT1_2, Math.sqrt(3) / 2, -Math.sqrt(3) / 2];
|
|
107
107
|
|
|
108
|
-
/** Replaces each entry within SNAP_EPSILON of an exact value by that value (this also turns −0 into 0). */
|
|
109
|
-
export function snap(a: Mat3): Mat3 {
|
|
108
|
+
/** Replaces each entry within `epsilon` (default SNAP_EPSILON) of an exact value by that value (this also turns −0 into 0). */
|
|
109
|
+
export function snap(a: Mat3, epsilon = SNAP_EPSILON): Mat3 {
|
|
110
110
|
return build((i, j) => {
|
|
111
111
|
const v = a[i][j];
|
|
112
|
-
for (const s of SNAP_VALUES) if (Math.abs(v - s) <
|
|
112
|
+
for (const s of SNAP_VALUES) if (Math.abs(v - s) < epsilon) return s;
|
|
113
113
|
return v;
|
|
114
114
|
});
|
|
115
115
|
}
|
package/src/magnetic.ts
CHANGED
|
@@ -10,19 +10,22 @@
|
|
|
10
10
|
* allows no time-odd property (docs/conventions.md, "Two entry points").
|
|
11
11
|
*/
|
|
12
12
|
export { VERSION } from './version.js';
|
|
13
|
+
export { EPSILON, type ToleranceOptions } from './tolerances.js';
|
|
13
14
|
|
|
14
15
|
export type { Mat3, Vec3 } from './linalg.js';
|
|
15
|
-
export type { Operation } from './operations.js';
|
|
16
|
+
export type { CartesianOperation, Operation } from './operations.js';
|
|
16
17
|
export {
|
|
17
18
|
crystalFamily,
|
|
18
19
|
latticeBasis,
|
|
19
20
|
type CrystalFamily,
|
|
20
21
|
type CrystalSystem,
|
|
21
22
|
type FixedAngleFamily,
|
|
23
|
+
type LatticeSystem,
|
|
22
24
|
} from './lattice.js';
|
|
23
25
|
export {
|
|
24
26
|
angleBetweenDirections,
|
|
25
27
|
angleBetweenPlanes,
|
|
28
|
+
faceNormal,
|
|
26
29
|
isValidCell,
|
|
27
30
|
latticeFromParameters,
|
|
28
31
|
latticeParameters,
|
|
@@ -32,19 +35,27 @@ export {
|
|
|
32
35
|
type CellOperation,
|
|
33
36
|
type IsValidCellOptions,
|
|
34
37
|
type LatticeParameters,
|
|
35
|
-
type ResidualOperationsOptions,
|
|
36
38
|
} from './cell.js';
|
|
37
39
|
export {
|
|
38
|
-
changeOfAxes,
|
|
39
40
|
directionFromFourIndices,
|
|
40
41
|
directionToFourIndices,
|
|
41
42
|
planeFromFourIndices,
|
|
42
43
|
planeToFourIndices,
|
|
44
|
+
millerIndices,
|
|
43
45
|
reduceIndices,
|
|
44
46
|
zoneAxis,
|
|
45
|
-
type AxisChange,
|
|
46
47
|
type FourIndices,
|
|
48
|
+
type MillerValues,
|
|
47
49
|
} from './indices.js';
|
|
50
|
+
export {
|
|
51
|
+
changeOfCoordinates,
|
|
52
|
+
type AffineOperation,
|
|
53
|
+
type CoordinateChange,
|
|
54
|
+
type CoordinateQuantities,
|
|
55
|
+
type CoordinateTransformation,
|
|
56
|
+
type InverseTransformation,
|
|
57
|
+
type TransformedOperation,
|
|
58
|
+
} from './coordinates.js';
|
|
48
59
|
|
|
49
60
|
import type {
|
|
50
61
|
PointGroupKey as ClassKey,
|
|
@@ -70,18 +81,19 @@ export {
|
|
|
70
81
|
findMagneticPointGroup as findPointGroup,
|
|
71
82
|
generators,
|
|
72
83
|
isMagneticPointGroupKey as isPointGroupKey,
|
|
84
|
+
latticeSystems,
|
|
73
85
|
magneticPointGroups as pointGroups,
|
|
74
86
|
operations,
|
|
75
87
|
pointGroup,
|
|
76
88
|
settings,
|
|
77
89
|
symbol,
|
|
78
|
-
type Convention,
|
|
79
90
|
type PointGroupType,
|
|
80
91
|
type Setting,
|
|
92
|
+
type AxesOptions,
|
|
81
93
|
type SettingOptions,
|
|
82
94
|
type SymbolOptions,
|
|
83
95
|
} from './pointGroups/pointGroups.js';
|
|
84
|
-
export { holohedry, isCentrosymmetricOf,
|
|
96
|
+
export { holohedry, isCentrosymmetricOf, isEnantiomorphicOf } from './pointGroups/properties.js';
|
|
85
97
|
export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
|
|
86
98
|
export {
|
|
87
99
|
describeOperations,
|
|
@@ -93,22 +105,22 @@ export {
|
|
|
93
105
|
type SymmetryDirection,
|
|
94
106
|
} from './pointGroups/elements.js';
|
|
95
107
|
export { residualMagneticOperations as residualOperations, type MagneticCellOperation } from './cell.js';
|
|
96
|
-
export {
|
|
108
|
+
export { siteSymmetryOf, type SiteSymmetry } from './siteSymmetry.js';
|
|
109
|
+
export { siteSymmetry } from './pointGroups/wyckoff.js';
|
|
97
110
|
export {
|
|
98
111
|
describeOperationsOf,
|
|
99
112
|
pointGroupOf,
|
|
100
113
|
type CartesianAxis,
|
|
101
114
|
type CartesianOperationDescription,
|
|
102
115
|
type IdentifiedPointGroup,
|
|
103
|
-
type PointGroupOfOptions,
|
|
104
116
|
} from './pointGroups/identify.js';
|
|
105
117
|
export {
|
|
106
|
-
latticeOperations,
|
|
107
118
|
orbit,
|
|
108
119
|
orbitOf,
|
|
120
|
+
type DirectionIndices,
|
|
109
121
|
type DirectionOrbitEntry,
|
|
122
|
+
type FaceIndices,
|
|
110
123
|
type FaceOrbitEntry,
|
|
111
|
-
type OrbitOptions,
|
|
112
124
|
type OrbitPole,
|
|
113
125
|
} from './pointGroups/orbits.js';
|
|
114
126
|
export {
|
|
@@ -117,12 +129,13 @@ export {
|
|
|
117
129
|
tensorFormOf,
|
|
118
130
|
type IntrinsicSymmetry,
|
|
119
131
|
type TensorForm,
|
|
120
|
-
type
|
|
132
|
+
type TensorKind,
|
|
121
133
|
type TensorRank,
|
|
122
134
|
type TensorSpec,
|
|
123
135
|
type TimeParity,
|
|
124
136
|
} from './tensors/tensorForm.js';
|
|
125
137
|
export { TENSOR_PROPERTIES, type TensorProperty, type TensorPropertyName } from './tensors/propertyTable.js';
|
|
138
|
+
export { fromVoigt, toVoigt, type VoigtFactor, type VoigtOptions } from './tensors/voigt.js';
|
|
126
139
|
export {
|
|
127
140
|
allowedProperties,
|
|
128
141
|
allowedPropertiesOf,
|
package/src/notation.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tolerant reading of symbols (#96): the spellings of the overbar, the prime and the Schoenflies
|
|
3
|
+
* subscripts that occur in print, on the web and in pasted text, brought to the one spelling of
|
|
4
|
+
* this library before a symbol is compared (docs/conventions.md, "Reading symbols"). A pure
|
|
5
|
+
* normalisation: it changes how a symbol is written, never which symbol it is. Internal; shared by
|
|
6
|
+
* the entry points. Characters outside ASCII are written as escapes, so that none is invisible.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Combining overbar (U+0304) and combining overline (U+0305), and the macron (U+00AF), as the text
|
|
11
|
+
* layer of the ITA 2016 PDFs gives the overbar, each written after the digit it marks.
|
|
12
|
+
*/
|
|
13
|
+
const OVERBAR_AFTER = /(\d)[\u0304\u0305\u00AF]/g;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An overbar written as a word before the digit it marks: `bar3`, `bar{3}`, and LaTeX's `\bar{3}`,
|
|
17
|
+
* `\bar 3`, `\overline{3}`. A space after the digit is kept.
|
|
18
|
+
*/
|
|
19
|
+
const BAR_WORD = /\\?(?:bar|overline)\s*(?:\{\s*(\d)\s*\}|(\d))/g;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Primes: the prime (U+2032), the modifier letter prime (U+02B9) and the right single quotation
|
|
23
|
+
* mark (U+2019), which text editors put for an apostrophe.
|
|
24
|
+
*/
|
|
25
|
+
const PRIMES = /[\u2032\u02B9\u2019]/g;
|
|
26
|
+
|
|
27
|
+
/** The minus sign (U+2212) and the hyphens (U+2010, U+2011) as the overbar `-`. */
|
|
28
|
+
const MINUS = /[\u2212\u2010\u2011]/g;
|
|
29
|
+
|
|
30
|
+
/** Unicode subscripts of Schoenflies symbols: the digits, h, v, i, s. */
|
|
31
|
+
const SUBSCRIPTS: ReadonlyMap<string, string> = new Map([
|
|
32
|
+
['\u2080', '0'],
|
|
33
|
+
['\u2081', '1'],
|
|
34
|
+
['\u2082', '2'],
|
|
35
|
+
['\u2083', '3'],
|
|
36
|
+
['\u2084', '4'],
|
|
37
|
+
['\u2085', '5'],
|
|
38
|
+
['\u2086', '6'],
|
|
39
|
+
['\u2087', '7'],
|
|
40
|
+
['\u2088', '8'],
|
|
41
|
+
['\u2089', '9'],
|
|
42
|
+
['\u2095', 'h'],
|
|
43
|
+
['\u1D65', 'v'],
|
|
44
|
+
['\u1D62', 'i'],
|
|
45
|
+
['\u209B', 's'],
|
|
46
|
+
]);
|
|
47
|
+
const SUBSCRIPT = /[\u2080-\u2089\u2095\u1D65\u1D62\u209B]/g;
|
|
48
|
+
|
|
49
|
+
/** LaTeX subscripts of Schoenflies symbols: `C_{3v}`, `C_3v`. */
|
|
50
|
+
const LATEX_SUBSCRIPT = /_\{([^{}]*)\}|_/g;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A symbol in the spelling of this library, its spaces normalized (trimmed, every run one space):
|
|
54
|
+
* overbars as `-` before the digit, primes as `'`, Schoenflies subscripts as plain characters
|
|
55
|
+
* (Unicode subscripts, LaTeX's `_{3v}` and `_3`).
|
|
56
|
+
*/
|
|
57
|
+
export function normalizeSymbol(text: string): string {
|
|
58
|
+
return text
|
|
59
|
+
.normalize('NFD')
|
|
60
|
+
.replace(OVERBAR_AFTER, '-$1')
|
|
61
|
+
.replace(BAR_WORD, (_, braced: string | undefined, bare: string | undefined) => `-${braced ?? bare}`)
|
|
62
|
+
.replace(PRIMES, "'")
|
|
63
|
+
.replace(MINUS, '-')
|
|
64
|
+
.replace(SUBSCRIPT, (c) => SUBSCRIPTS.get(c)!)
|
|
65
|
+
.replace(LATEX_SUBSCRIPT, (_, inner: string | undefined) => inner ?? '')
|
|
66
|
+
.trim()
|
|
67
|
+
.replace(/\s+/g, ' ');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A normalized symbol without spaces. */
|
|
71
|
+
export function compactSymbol(text: string): string {
|
|
72
|
+
return normalizeSymbol(text).replace(/ /g, '');
|
|
73
|
+
}
|