symcrys 0.10.0 → 0.11.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.
Files changed (218) hide show
  1. package/README.md +6 -6
  2. package/dist/cell.d.ts +19 -16
  3. package/dist/cell.d.ts.map +1 -1
  4. package/dist/cell.js +63 -35
  5. package/dist/cell.js.map +1 -1
  6. package/dist/checks.d.ts +29 -0
  7. package/dist/checks.d.ts.map +1 -0
  8. package/dist/checks.js +79 -0
  9. package/dist/checks.js.map +1 -0
  10. package/dist/closure.d.ts +43 -0
  11. package/dist/closure.d.ts.map +1 -0
  12. package/dist/closure.js +201 -0
  13. package/dist/closure.js.map +1 -0
  14. package/dist/crystalClasses.d.ts +146 -118
  15. package/dist/crystalClasses.d.ts.map +1 -1
  16. package/dist/crystalClasses.js +163 -124
  17. package/dist/crystalClasses.js.map +1 -1
  18. package/dist/freeze.d.ts +7 -0
  19. package/dist/freeze.d.ts.map +1 -0
  20. package/dist/freeze.js +15 -0
  21. package/dist/freeze.js.map +1 -0
  22. package/dist/index.d.ts +11 -10
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/indices.d.ts +31 -5
  27. package/dist/indices.d.ts.map +1 -1
  28. package/dist/indices.js +104 -13
  29. package/dist/indices.js.map +1 -1
  30. package/dist/lattice.d.ts +15 -1
  31. package/dist/lattice.d.ts.map +1 -1
  32. package/dist/lattice.js +30 -1
  33. package/dist/lattice.js.map +1 -1
  34. package/dist/linalg.d.ts +2 -2
  35. package/dist/linalg.d.ts.map +1 -1
  36. package/dist/linalg.js +3 -3
  37. package/dist/linalg.js.map +1 -1
  38. package/dist/magnetic.d.ts +12 -10
  39. package/dist/magnetic.d.ts.map +1 -1
  40. package/dist/magnetic.js +8 -6
  41. package/dist/magnetic.js.map +1 -1
  42. package/dist/notation.d.ts +16 -0
  43. package/dist/notation.d.ts.map +1 -0
  44. package/dist/notation.js +66 -0
  45. package/dist/notation.js.map +1 -0
  46. package/dist/operations.d.ts +40 -26
  47. package/dist/operations.d.ts.map +1 -1
  48. package/dist/operations.js +48 -60
  49. package/dist/operations.js.map +1 -1
  50. package/dist/plane.d.ts +141 -79
  51. package/dist/plane.d.ts.map +1 -1
  52. package/dist/plane.js +147 -77
  53. package/dist/plane.js.map +1 -1
  54. package/dist/pointGroups/crystalForms.d.ts +6 -21
  55. package/dist/pointGroups/crystalForms.d.ts.map +1 -1
  56. package/dist/pointGroups/crystalForms.js +9 -16
  57. package/dist/pointGroups/crystalForms.js.map +1 -1
  58. package/dist/pointGroups/crystalFormsData.d.ts +4 -1
  59. package/dist/pointGroups/crystalFormsData.d.ts.map +1 -1
  60. package/dist/pointGroups/crystalFormsData.js +64 -1
  61. package/dist/pointGroups/crystalFormsData.js.map +1 -1
  62. package/dist/pointGroups/elements.d.ts +19 -17
  63. package/dist/pointGroups/elements.d.ts.map +1 -1
  64. package/dist/pointGroups/elements.js +65 -83
  65. package/dist/pointGroups/elements.js.map +1 -1
  66. package/dist/pointGroups/identify.d.ts +10 -18
  67. package/dist/pointGroups/identify.d.ts.map +1 -1
  68. package/dist/pointGroups/identify.js +27 -79
  69. package/dist/pointGroups/identify.js.map +1 -1
  70. package/dist/pointGroups/itaOrder.d.ts +15 -14
  71. package/dist/pointGroups/itaOrder.d.ts.map +1 -1
  72. package/dist/pointGroups/itaOrder.js +116 -94
  73. package/dist/pointGroups/itaOrder.js.map +1 -1
  74. package/dist/pointGroups/itcData.d.ts +96 -0
  75. package/dist/pointGroups/itcData.d.ts.map +1 -0
  76. package/dist/pointGroups/itcData.js +336 -0
  77. package/dist/pointGroups/itcData.js.map +1 -0
  78. package/dist/pointGroups/itcMagneticData.d.ts +55 -0
  79. package/dist/pointGroups/itcMagneticData.d.ts.map +1 -0
  80. package/dist/pointGroups/itcMagneticData.js +172 -0
  81. package/dist/pointGroups/itcMagneticData.js.map +1 -0
  82. package/dist/pointGroups/keys.d.ts +32 -0
  83. package/dist/pointGroups/keys.d.ts.map +1 -0
  84. package/dist/pointGroups/keys.js +120 -0
  85. package/dist/pointGroups/keys.js.map +1 -0
  86. package/dist/pointGroups/magneticSymbols.d.ts +6 -5
  87. package/dist/pointGroups/magneticSymbols.d.ts.map +1 -1
  88. package/dist/pointGroups/magneticSymbols.js +15 -12
  89. package/dist/pointGroups/magneticSymbols.js.map +1 -1
  90. package/dist/pointGroups/orbits.d.ts +23 -42
  91. package/dist/pointGroups/orbits.d.ts.map +1 -1
  92. package/dist/pointGroups/orbits.js +20 -62
  93. package/dist/pointGroups/orbits.js.map +1 -1
  94. package/dist/pointGroups/pointGroups.d.ts +135 -67
  95. package/dist/pointGroups/pointGroups.d.ts.map +1 -1
  96. package/dist/pointGroups/pointGroups.js +409 -244
  97. package/dist/pointGroups/pointGroups.js.map +1 -1
  98. package/dist/pointGroups/properties.d.ts +21 -22
  99. package/dist/pointGroups/properties.d.ts.map +1 -1
  100. package/dist/pointGroups/properties.js +40 -37
  101. package/dist/pointGroups/properties.js.map +1 -1
  102. package/dist/pointGroups/seitzData.d.ts +26 -0
  103. package/dist/pointGroups/seitzData.d.ts.map +1 -0
  104. package/dist/pointGroups/seitzData.js +130 -0
  105. package/dist/pointGroups/seitzData.js.map +1 -0
  106. package/dist/pointGroups/wyckoff.d.ts +70 -40
  107. package/dist/pointGroups/wyckoff.d.ts.map +1 -1
  108. package/dist/pointGroups/wyckoff.js +98 -91
  109. package/dist/pointGroups/wyckoff.js.map +1 -1
  110. package/dist/pointGroups/wyckoffData.d.ts +7 -4
  111. package/dist/pointGroups/wyckoffData.d.ts.map +1 -1
  112. package/dist/pointGroups/wyckoffData.js +789 -168
  113. package/dist/pointGroups/wyckoffData.js.map +1 -1
  114. package/dist/siteSymmetry.d.ts +9 -17
  115. package/dist/siteSymmetry.d.ts.map +1 -1
  116. package/dist/siteSymmetry.js +62 -47
  117. package/dist/siteSymmetry.js.map +1 -1
  118. package/dist/spaceGroups/affine.d.ts.map +1 -1
  119. package/dist/spaceGroups/affine.js +3 -2
  120. package/dist/spaceGroups/affine.js.map +1 -1
  121. package/dist/spaceGroups/cell.d.ts +43 -31
  122. package/dist/spaceGroups/cell.d.ts.map +1 -1
  123. package/dist/spaceGroups/cell.js +173 -85
  124. package/dist/spaceGroups/cell.js.map +1 -1
  125. package/dist/spaceGroups/describe.d.ts +12 -10
  126. package/dist/spaceGroups/describe.d.ts.map +1 -1
  127. package/dist/spaceGroups/describe.js +11 -10
  128. package/dist/spaceGroups/describe.js.map +1 -1
  129. package/dist/spaceGroups/planeGroupData.d.ts +1 -1
  130. package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
  131. package/dist/spaceGroups/planeGroupData.js +8 -8
  132. package/dist/spaceGroups/planeGroupData.js.map +1 -1
  133. package/dist/spaceGroups/planeGroups.d.ts.map +1 -1
  134. package/dist/spaceGroups/planeGroups.js +2 -1
  135. package/dist/spaceGroups/planeGroups.js.map +1 -1
  136. package/dist/spaceGroups/positions.d.ts +48 -19
  137. package/dist/spaceGroups/positions.d.ts.map +1 -1
  138. package/dist/spaceGroups/positions.js +166 -67
  139. package/dist/spaceGroups/positions.js.map +1 -1
  140. package/dist/tensors/propertyTable.d.ts +3 -1
  141. package/dist/tensors/propertyTable.d.ts.map +1 -1
  142. package/dist/tensors/propertyTable.js +17 -10
  143. package/dist/tensors/propertyTable.js.map +1 -1
  144. package/dist/tensors/rowEchelon.d.ts +12 -4
  145. package/dist/tensors/rowEchelon.d.ts.map +1 -1
  146. package/dist/tensors/rowEchelon.js +24 -11
  147. package/dist/tensors/rowEchelon.js.map +1 -1
  148. package/dist/tensors/tensorForm.d.ts +75 -34
  149. package/dist/tensors/tensorForm.d.ts.map +1 -1
  150. package/dist/tensors/tensorForm.js +173 -68
  151. package/dist/tensors/tensorForm.js.map +1 -1
  152. package/dist/tensors/tensorProperties.d.ts +10 -9
  153. package/dist/tensors/tensorProperties.d.ts.map +1 -1
  154. package/dist/tensors/tensorProperties.js +22 -12
  155. package/dist/tensors/tensorProperties.js.map +1 -1
  156. package/dist/tolerances.d.ts +56 -1
  157. package/dist/tolerances.d.ts.map +1 -1
  158. package/dist/tolerances.js +51 -1
  159. package/dist/tolerances.js.map +1 -1
  160. package/dist/version.d.ts +1 -1
  161. package/dist/version.js +1 -1
  162. package/package.json +1 -1
  163. package/src/cell.ts +78 -51
  164. package/src/checks.ts +84 -0
  165. package/src/closure.ts +214 -0
  166. package/src/crystalClasses.ts +234 -160
  167. package/src/freeze.ts +14 -0
  168. package/src/index.ts +21 -10
  169. package/src/indices.ts +108 -18
  170. package/src/lattice.ts +41 -1
  171. package/src/linalg.ts +3 -3
  172. package/src/magnetic.ts +14 -9
  173. package/src/notation.ts +73 -0
  174. package/src/operations.ts +78 -69
  175. package/src/plane.ts +253 -127
  176. package/src/pointGroups/crystalForms.ts +11 -44
  177. package/src/pointGroups/crystalFormsData.ts +66 -1
  178. package/src/pointGroups/elements.ts +82 -92
  179. package/src/pointGroups/identify.ts +38 -97
  180. package/src/pointGroups/itaOrder.ts +117 -101
  181. package/src/pointGroups/itcData.ts +404 -0
  182. package/src/pointGroups/itcMagneticData.ts +206 -0
  183. package/src/pointGroups/keys.ts +144 -0
  184. package/src/pointGroups/magneticSymbols.ts +18 -17
  185. package/src/pointGroups/orbits.ts +41 -89
  186. package/src/pointGroups/pointGroups.ts +540 -297
  187. package/src/pointGroups/properties.ts +44 -40
  188. package/src/pointGroups/seitzData.ts +147 -0
  189. package/src/pointGroups/wyckoff.ts +137 -112
  190. package/src/pointGroups/wyckoffData.ts +793 -170
  191. package/src/siteSymmetry.ts +71 -64
  192. package/src/spaceGroups/affine.ts +3 -2
  193. package/src/spaceGroups/cell.ts +227 -116
  194. package/src/spaceGroups/describe.ts +22 -19
  195. package/src/spaceGroups/planeGroupData.ts +9 -9
  196. package/src/spaceGroups/planeGroups.ts +2 -1
  197. package/src/spaceGroups/positions.ts +202 -78
  198. package/src/tensors/propertyTable.ts +29 -17
  199. package/src/tensors/rowEchelon.ts +28 -9
  200. package/src/tensors/tensorForm.ts +260 -89
  201. package/src/tensors/tensorProperties.ts +34 -14
  202. package/src/tolerances.ts +66 -1
  203. package/src/version.ts +1 -1
  204. package/dist/pointGroups/data.d.ts +0 -75
  205. package/dist/pointGroups/data.d.ts.map +0 -1
  206. package/dist/pointGroups/data.js +0 -212
  207. package/dist/pointGroups/data.js.map +0 -1
  208. package/dist/pointGroups/magneticData.d.ts +0 -66
  209. package/dist/pointGroups/magneticData.d.ts.map +0 -1
  210. package/dist/pointGroups/magneticData.js +0 -184
  211. package/dist/pointGroups/magneticData.js.map +0 -1
  212. package/dist/spaceGroups/snap.d.ts +0 -20
  213. package/dist/spaceGroups/snap.d.ts.map +0 -1
  214. package/dist/spaceGroups/snap.js +0 -103
  215. package/dist/spaceGroups/snap.js.map +0 -1
  216. package/src/pointGroups/data.ts +0 -305
  217. package/src/pointGroups/magneticData.ts +0 -328
  218. package/src/spaceGroups/snap.ts +0 -121
@@ -3,25 +3,16 @@
3
3
  * fixed (docs/conventions.md, "Site symmetry and Wyckoff positions").
4
4
  */
5
5
 
6
- import { apply, matricesEqual, multiply, type Vec3 } from './linalg.js';
7
- import { checkOrthogonalWithin, type Operation } from './operations.js';
8
- import { EPSILON } from './tolerances.js';
9
-
10
- /** Options of `siteSymmetry` and `wyckoffPositionOf`. */
11
- export interface SiteSymmetryOptions {
12
- /**
13
- * A direction counts as fixed by an operation if the operation moves its unit vector by less
14
- * than this (Euclidean distance). Default 10⁻⁶; a caller whose directions carry
15
- * rounding errors (e.g. read from a rounded link) passes a larger value.
16
- */
17
- readonly tolerance?: number;
18
- }
6
+ import { checkNumbers, checkOptions, shown, TOLERANCE_KEYS } from './checks.js';
7
+ import { apply, multiply, type Vec3 } from './linalg.js';
8
+ import { checkCartesianOperations, type CartesianOperation } from './operations.js';
9
+ import { EPSILON, TOLERANCE_BOUND, toleranceOf, type ToleranceOptions } from './tolerances.js';
19
10
 
20
11
  /** The site symmetry of a direction. */
21
12
  export interface SiteSymmetry {
22
13
  /**
23
14
  * Indices into the given operations of those that leave the direction fixed, ascending: for a group,
24
- * a subgroup (the operations fixing within the tolerance, closed under products, see `siteSymmetry`).
15
+ * a subgroup (the operations fixing within the tolerance, closed under products, see `siteSymmetryOf`).
25
16
  */
26
17
  readonly operations: readonly number[];
27
18
  /**
@@ -37,47 +28,58 @@ export interface SiteSymmetry {
37
28
  }
38
29
 
39
30
  function unit(v: Vec3): Vec3 {
31
+ checkNumbers(v, 3, 'A direction');
40
32
  const n = Math.hypot(v[0], v[1], v[2]);
41
- if (!(n > 0) || !Number.isFinite(n)) throw new RangeError(`Not a direction: ${JSON.stringify(v)}`);
33
+ if (!(n > 0) || !Number.isFinite(n)) throw new RangeError(`Not a direction: ${shown(v)}`);
42
34
  return [v[0] / n, v[1] / n, v[2] / n];
43
35
  }
44
36
 
45
- function fixes(op: Operation, v: Vec3, tolerance: number): boolean {
46
- const w = apply(op.matrix, v);
37
+ function fixes(op: CartesianOperation, v: Vec3, tolerance: number): boolean {
38
+ const w = apply(op.cartesian, v);
47
39
  return Math.hypot(w[0] - v[0], w[1] - v[1], w[2] - v[2]) < tolerance;
48
40
  }
49
41
 
50
- function isIdentity(op: Operation): boolean {
51
- return op.matrix.every((row, i) => row.every((v, j) => Math.abs(v - (i === j ? 1 : 0)) < EPSILON));
42
+ function isIdentity(op: CartesianOperation): boolean {
43
+ return op.cartesian.every((row, i) => row.every((v, j) => Math.abs(v - (i === j ? 1 : 0)) < EPSILON));
52
44
  }
53
45
 
54
- /** Products already looked up, per list of operations: `i * n + j` → index of op[i]·op[j] in the list, or -1. */
55
- const productTables = new WeakMap<readonly Operation[], Map<number, number>>();
56
-
57
- function productIndex(operations: readonly Operation[], i: number, j: number): number {
58
- let table = productTables.get(operations);
59
- if (!table) {
60
- table = new Map();
61
- productTables.set(operations, table);
62
- }
63
- const key = i * operations.length + j;
64
- let k = table.get(key);
65
- if (k === undefined) {
66
- const product = multiply(operations[i].matrix, operations[j].matrix);
67
- k = operations.findIndex((op) => matricesEqual(op.matrix, product));
68
- table.set(key, k);
69
- }
70
- return k;
46
+ /**
47
+ * The products of a list of operations, looked up as needed: `i * n + j` → index of op[i]·op[j] in
48
+ * the list, or -1. The product is the whole operation, time reversal included, so that in a grey
49
+ * group, where every matrix occurs twice, it finds the copy with the right time reversal (#133).
50
+ * Matrices count as equal per entry within the tolerance, at least `EPSILON` and at most the bound
51
+ * for operations (a tolerance for directions may be larger). Made per call, not kept between
52
+ * calls: a caller may change its list in place (#90).
53
+ */
54
+ function productLookup(operations: readonly CartesianOperation[], tolerance: number): (i: number, j: number) => number {
55
+ const table = new Map<number, number>();
56
+ const within = Math.min(Math.max(tolerance, EPSILON), TOLERANCE_BOUND.operations);
57
+ const reversed = (op: CartesianOperation): boolean => op.timeReversal === true;
58
+ return (i, j) => {
59
+ const key = i * operations.length + j;
60
+ let k = table.get(key);
61
+ if (k === undefined) {
62
+ const product = multiply(operations[i].cartesian, operations[j].cartesian);
63
+ const timeReversal = reversed(operations[i]) !== reversed(operations[j]);
64
+ k = operations.findIndex(
65
+ (op) =>
66
+ reversed(op) === timeReversal &&
67
+ op.cartesian.every((row, a) => row.every((v, b) => Math.abs(v - product[a][b]) < within)),
68
+ );
69
+ table.set(key, k);
70
+ }
71
+ return k;
72
+ };
71
73
  }
72
74
 
73
75
  /** The indices plus those of every product of two of them that is itself in the list, until closed. */
74
- function closeWithin(operations: readonly Operation[], indices: readonly number[]): number[] {
76
+ function closeWithin(product: (i: number, j: number) => number, indices: readonly number[]): number[] {
75
77
  const set = [...indices];
76
78
  const inSet = new Set(set);
77
79
  // Each element is multiplied with every element before it once, in both orders, as it is added.
78
80
  for (let i = 0; i < set.length; i++) {
79
81
  for (let j = 0; j <= i; j++) {
80
- for (const k of [productIndex(operations, set[i], set[j]), productIndex(operations, set[j], set[i])]) {
82
+ for (const k of [product(set[i], set[j]), product(set[j], set[i])]) {
81
83
  if (k >= 0 && !inSet.has(k)) {
82
84
  inSet.add(k);
83
85
  set.push(k);
@@ -89,11 +91,11 @@ function closeWithin(operations: readonly Operation[], indices: readonly number[
89
91
  }
90
92
 
91
93
  /** The normalised mean of the images of v under the operations at `indices`; undefined if it vanishes. */
92
- function meanImage(operations: readonly Operation[], indices: readonly number[], v: Vec3): Vec3 | undefined {
94
+ function meanImage(operations: readonly CartesianOperation[], indices: readonly number[], v: Vec3): Vec3 | undefined {
93
95
  if (indices.length === 0) return v;
94
96
  const sum: [number, number, number] = [0, 0, 0];
95
97
  for (const i of indices) {
96
- const w = apply(operations[i].matrix, v);
98
+ const w = apply(operations[i].cartesian, v);
97
99
  sum[0] += w[0];
98
100
  sum[1] += w[1];
99
101
  sum[2] += w[2];
@@ -105,11 +107,9 @@ function meanImage(operations: readonly Operation[], indices: readonly number[],
105
107
  const sameIndices = (a: readonly number[], b: readonly number[]): boolean =>
106
108
  a.length === b.length && a.every((x, i) => x === b[i]);
107
109
 
108
- /** The tolerance of the options, checked. */
109
- export function siteTolerance(options?: SiteSymmetryOptions): number {
110
- const t = options?.tolerance ?? EPSILON;
111
- if (!(typeof t === 'number' && t > 0 && t < 1)) throw new RangeError(`Invalid tolerance: ${String(t)}`);
112
- return t;
110
+ /** The tolerance of the options for directions, checked. */
111
+ export function siteTolerance(options?: ToleranceOptions): number {
112
+ return toleranceOf(options, 'directions');
113
113
  }
114
114
 
115
115
  /**
@@ -119,18 +119,21 @@ export function siteTolerance(options?: SiteSymmetryOptions): number {
119
119
  * within the tolerance are closed under the products found in the list and the direction is set onto
120
120
  * their fixed space, repeated until stable, so that for a group the result is a subgroup and the
121
121
  * set direction lies exactly on its elements. For a list that is not a group, `multiplicity` may
122
- * not be an integer. The matrices must be Cartesian and orthogonal (not those of
123
- * `latticeOperations`). Throws a RangeError for a matrix that is not orthogonal (within
122
+ * not be an integer. Each operation is read by its Cartesian matrix
123
+ * (`cartesian`). Throws a RangeError for an operation without an orthogonal Cartesian matrix (`cartesian`; within
124
124
  * `tolerance`, at least `EPSILON`), for a zero vector, and if the closed operations fix no common
125
- * direction (a tolerance far too large, e.g. 0.5).
125
+ * direction or do not settle into a group (a tolerance far too large, e.g. 0.5).
126
126
  */
127
- export function siteSymmetry(
128
- operations: readonly Operation[],
127
+ export function siteSymmetryOf(
128
+ operations: readonly CartesianOperation[],
129
129
  direction: Vec3,
130
- options?: SiteSymmetryOptions,
130
+ options?: ToleranceOptions,
131
131
  ): SiteSymmetry {
132
+ checkOptions(options, TOLERANCE_KEYS, 'siteSymmetryOf');
132
133
  const tolerance = siteTolerance(options);
133
- operations.forEach((op, i) => checkOrthogonalWithin(op.matrix, `Operation ${i}`, tolerance));
134
+ // Operations are checked in their own metric, at most with the bound for operations.
135
+ checkCartesianOperations(operations, Math.min(tolerance, TOLERANCE_BOUND.operations));
136
+ if (operations.length === 0) throw new RangeError('siteSymmetryOf takes a list of at least one operation');
134
137
  const v = unit(direction);
135
138
  const fixing = (w: Vec3): number[] => {
136
139
  const out: number[] = [];
@@ -143,24 +146,28 @@ export function siteSymmetry(
143
146
  // as fixing while its square does not). Close them under products found in the list, set v onto the
144
147
  // fixed space of the closure (the mean of its images, the projector for a group), and repeat on the
145
148
  // projected direction until the set is stable.
146
- let indices = fixing(v);
147
- let projected = v;
148
- let set = closeWithin(operations, indices);
149
- for (let pass = 0; pass < 8; pass++) {
149
+ const product = productLookup(operations, tolerance);
150
+ let set = closeWithin(product, fixing(v));
151
+ let settled: { indices: number[]; projected: Vec3 } | undefined;
152
+ for (let pass = 0; pass < 8 && !settled; pass++) {
150
153
  const mean = meanImage(operations, set, v);
151
154
  if (mean === undefined) {
152
155
  throw new RangeError(
153
- `No common fixed direction for the operations fixing ${JSON.stringify(direction)} within ${tolerance} (tolerance too large?)`,
156
+ `No common fixed direction for the operations fixing ${shown(direction)} within ${tolerance} (tolerance too large?)`,
154
157
  );
155
158
  }
156
- const next = closeWithin(operations, fixing(mean));
157
- if (sameIndices(next, set)) {
158
- indices = set;
159
- projected = mean;
160
- break;
161
- }
162
- set = next;
159
+ const next = closeWithin(product, fixing(mean));
160
+ if (sameIndices(next, set)) settled = { indices: set, projected: mean };
161
+ else set = next;
162
+ }
163
+ if (!settled) {
164
+ // Only for a tolerance far too large; the site symmetry would be neither closed nor its direction
165
+ // projected (#91).
166
+ throw new RangeError(
167
+ `The site symmetry of ${shown(direction)} does not settle within ${tolerance} (tolerance too large?)`,
168
+ );
163
169
  }
170
+ const { indices, projected } = settled;
164
171
  return Object.freeze({
165
172
  operations: Object.freeze(indices),
166
173
  direction: Object.freeze(projected) as Vec3,
@@ -5,6 +5,7 @@
5
5
  * space groups). CLAUDE.md, "Plane groups (and later space groups)".
6
6
  */
7
7
 
8
+ import { shown } from '../checks.js';
8
9
  import {
9
10
  ZERO,
10
11
  add,
@@ -63,7 +64,7 @@ function checkDimension(d: number): number {
63
64
  export function dimensionOf(op: ExactOperation): number {
64
65
  const d = op.matrix.length;
65
66
  if (d < 1 || d > 3 || op.translation.length !== d || op.matrix.some((row) => row.length !== d)) {
66
- throw new RangeError(`Not an operation of dimension 1 to 3: ${JSON.stringify(op)}`);
67
+ throw new RangeError(`Not an operation of dimension 1 to 3: ${shown(op)}`);
67
68
  }
68
69
  for (const row of op.matrix) {
69
70
  for (const v of row) {
@@ -118,7 +119,7 @@ export function checkUnimodular(op: ExactOperation): void {
118
119
  dimensionOf(op);
119
120
  const det = determinant(op.matrix);
120
121
  if (det !== 1 && det !== -1) {
121
- throw new RangeError(`Determinant ${det} is not ±1: ${JSON.stringify(op.matrix)}`);
122
+ throw new RangeError(`Determinant ${det} is not ±1: ${shown(op.matrix)}`);
122
123
  }
123
124
  }
124
125