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.
Files changed (248) 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/coordinates.d.ts +143 -0
  15. package/dist/coordinates.d.ts.map +1 -0
  16. package/dist/coordinates.js +198 -0
  17. package/dist/coordinates.js.map +1 -0
  18. package/dist/crystalClasses.d.ts +170 -117
  19. package/dist/crystalClasses.d.ts.map +1 -1
  20. package/dist/crystalClasses.js +190 -121
  21. package/dist/crystalClasses.js.map +1 -1
  22. package/dist/freeze.d.ts +7 -0
  23. package/dist/freeze.d.ts.map +1 -0
  24. package/dist/freeze.js +15 -0
  25. package/dist/freeze.js.map +1 -0
  26. package/dist/index.d.ts +13 -10
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +5 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/indices.d.ts +30 -20
  31. package/dist/indices.d.ts.map +1 -1
  32. package/dist/indices.js +101 -31
  33. package/dist/indices.js.map +1 -1
  34. package/dist/lattice.d.ts +15 -1
  35. package/dist/lattice.d.ts.map +1 -1
  36. package/dist/lattice.js +30 -1
  37. package/dist/lattice.js.map +1 -1
  38. package/dist/linalg.d.ts +2 -2
  39. package/dist/linalg.d.ts.map +1 -1
  40. package/dist/linalg.js +3 -3
  41. package/dist/linalg.js.map +1 -1
  42. package/dist/magnetic.d.ts +14 -10
  43. package/dist/magnetic.d.ts.map +1 -1
  44. package/dist/magnetic.js +10 -6
  45. package/dist/magnetic.js.map +1 -1
  46. package/dist/notation.d.ts +16 -0
  47. package/dist/notation.d.ts.map +1 -0
  48. package/dist/notation.js +66 -0
  49. package/dist/notation.js.map +1 -0
  50. package/dist/operations.d.ts +40 -26
  51. package/dist/operations.d.ts.map +1 -1
  52. package/dist/operations.js +48 -60
  53. package/dist/operations.js.map +1 -1
  54. package/dist/plane.d.ts +297 -80
  55. package/dist/plane.d.ts.map +1 -1
  56. package/dist/plane.js +289 -94
  57. package/dist/plane.js.map +1 -1
  58. package/dist/pointGroups/crystalForms.d.ts +6 -21
  59. package/dist/pointGroups/crystalForms.d.ts.map +1 -1
  60. package/dist/pointGroups/crystalForms.js +9 -16
  61. package/dist/pointGroups/crystalForms.js.map +1 -1
  62. package/dist/pointGroups/crystalFormsData.d.ts +4 -1
  63. package/dist/pointGroups/crystalFormsData.d.ts.map +1 -1
  64. package/dist/pointGroups/crystalFormsData.js +64 -1
  65. package/dist/pointGroups/crystalFormsData.js.map +1 -1
  66. package/dist/pointGroups/elements.d.ts +19 -17
  67. package/dist/pointGroups/elements.d.ts.map +1 -1
  68. package/dist/pointGroups/elements.js +65 -83
  69. package/dist/pointGroups/elements.js.map +1 -1
  70. package/dist/pointGroups/identify.d.ts +10 -18
  71. package/dist/pointGroups/identify.d.ts.map +1 -1
  72. package/dist/pointGroups/identify.js +27 -79
  73. package/dist/pointGroups/identify.js.map +1 -1
  74. package/dist/pointGroups/itaOrder.d.ts +15 -14
  75. package/dist/pointGroups/itaOrder.d.ts.map +1 -1
  76. package/dist/pointGroups/itaOrder.js +116 -94
  77. package/dist/pointGroups/itaOrder.js.map +1 -1
  78. package/dist/pointGroups/itcData.d.ts +96 -0
  79. package/dist/pointGroups/itcData.d.ts.map +1 -0
  80. package/dist/pointGroups/itcData.js +336 -0
  81. package/dist/pointGroups/itcData.js.map +1 -0
  82. package/dist/pointGroups/itcMagneticData.d.ts +55 -0
  83. package/dist/pointGroups/itcMagneticData.d.ts.map +1 -0
  84. package/dist/pointGroups/itcMagneticData.js +172 -0
  85. package/dist/pointGroups/itcMagneticData.js.map +1 -0
  86. package/dist/pointGroups/keys.d.ts +32 -0
  87. package/dist/pointGroups/keys.d.ts.map +1 -0
  88. package/dist/pointGroups/keys.js +120 -0
  89. package/dist/pointGroups/keys.js.map +1 -0
  90. package/dist/pointGroups/magneticSymbols.d.ts +6 -5
  91. package/dist/pointGroups/magneticSymbols.d.ts.map +1 -1
  92. package/dist/pointGroups/magneticSymbols.js +15 -12
  93. package/dist/pointGroups/magneticSymbols.js.map +1 -1
  94. package/dist/pointGroups/orbits.d.ts +23 -42
  95. package/dist/pointGroups/orbits.d.ts.map +1 -1
  96. package/dist/pointGroups/orbits.js +20 -62
  97. package/dist/pointGroups/orbits.js.map +1 -1
  98. package/dist/pointGroups/pointGroups.d.ts +145 -68
  99. package/dist/pointGroups/pointGroups.d.ts.map +1 -1
  100. package/dist/pointGroups/pointGroups.js +455 -243
  101. package/dist/pointGroups/pointGroups.js.map +1 -1
  102. package/dist/pointGroups/properties.d.ts +21 -22
  103. package/dist/pointGroups/properties.d.ts.map +1 -1
  104. package/dist/pointGroups/properties.js +40 -37
  105. package/dist/pointGroups/properties.js.map +1 -1
  106. package/dist/pointGroups/seitzData.d.ts +26 -0
  107. package/dist/pointGroups/seitzData.d.ts.map +1 -0
  108. package/dist/pointGroups/seitzData.js +130 -0
  109. package/dist/pointGroups/seitzData.js.map +1 -0
  110. package/dist/pointGroups/shubnikovData.d.ts +11 -0
  111. package/dist/pointGroups/shubnikovData.d.ts.map +1 -0
  112. package/dist/pointGroups/shubnikovData.js +101 -0
  113. package/dist/pointGroups/shubnikovData.js.map +1 -0
  114. package/dist/pointGroups/wyckoff.d.ts +70 -40
  115. package/dist/pointGroups/wyckoff.d.ts.map +1 -1
  116. package/dist/pointGroups/wyckoff.js +98 -91
  117. package/dist/pointGroups/wyckoff.js.map +1 -1
  118. package/dist/pointGroups/wyckoffData.d.ts +7 -4
  119. package/dist/pointGroups/wyckoffData.d.ts.map +1 -1
  120. package/dist/pointGroups/wyckoffData.js +789 -168
  121. package/dist/pointGroups/wyckoffData.js.map +1 -1
  122. package/dist/siteSymmetry.d.ts +8 -16
  123. package/dist/siteSymmetry.d.ts.map +1 -1
  124. package/dist/siteSymmetry.js +34 -24
  125. package/dist/siteSymmetry.js.map +1 -1
  126. package/dist/spaceGroups/affine.d.ts.map +1 -1
  127. package/dist/spaceGroups/affine.js +3 -2
  128. package/dist/spaceGroups/affine.js.map +1 -1
  129. package/dist/spaceGroups/cell.d.ts +43 -31
  130. package/dist/spaceGroups/cell.d.ts.map +1 -1
  131. package/dist/spaceGroups/cell.js +173 -85
  132. package/dist/spaceGroups/cell.js.map +1 -1
  133. package/dist/spaceGroups/describe.d.ts +13 -10
  134. package/dist/spaceGroups/describe.d.ts.map +1 -1
  135. package/dist/spaceGroups/describe.js +11 -10
  136. package/dist/spaceGroups/describe.js.map +1 -1
  137. package/dist/spaceGroups/planeGroupData.d.ts +3 -1
  138. package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
  139. package/dist/spaceGroups/planeGroupData.js +25 -8
  140. package/dist/spaceGroups/planeGroupData.js.map +1 -1
  141. package/dist/spaceGroups/planeGroups.d.ts.map +1 -1
  142. package/dist/spaceGroups/planeGroups.js +2 -1
  143. package/dist/spaceGroups/planeGroups.js.map +1 -1
  144. package/dist/spaceGroups/planeLattice.d.ts +78 -0
  145. package/dist/spaceGroups/planeLattice.d.ts.map +1 -0
  146. package/dist/spaceGroups/planeLattice.js +143 -0
  147. package/dist/spaceGroups/planeLattice.js.map +1 -0
  148. package/dist/spaceGroups/planePointGroups.d.ts +6 -2
  149. package/dist/spaceGroups/planePointGroups.d.ts.map +1 -1
  150. package/dist/spaceGroups/planePointGroups.js +14 -2
  151. package/dist/spaceGroups/planePointGroups.js.map +1 -1
  152. package/dist/spaceGroups/positions.d.ts +48 -19
  153. package/dist/spaceGroups/positions.d.ts.map +1 -1
  154. package/dist/spaceGroups/positions.js +166 -67
  155. package/dist/spaceGroups/positions.js.map +1 -1
  156. package/dist/spaceGroups/rational.d.ts +18 -0
  157. package/dist/spaceGroups/rational.d.ts.map +1 -1
  158. package/dist/spaceGroups/rational.js +58 -0
  159. package/dist/spaceGroups/rational.js.map +1 -1
  160. package/dist/tensors/propertyTable.d.ts +3 -1
  161. package/dist/tensors/propertyTable.d.ts.map +1 -1
  162. package/dist/tensors/propertyTable.js +17 -10
  163. package/dist/tensors/propertyTable.js.map +1 -1
  164. package/dist/tensors/rowEchelon.d.ts +3 -3
  165. package/dist/tensors/rowEchelon.d.ts.map +1 -1
  166. package/dist/tensors/rowEchelon.js +4 -4
  167. package/dist/tensors/rowEchelon.js.map +1 -1
  168. package/dist/tensors/tensorForm.d.ts +75 -34
  169. package/dist/tensors/tensorForm.d.ts.map +1 -1
  170. package/dist/tensors/tensorForm.js +171 -67
  171. package/dist/tensors/tensorForm.js.map +1 -1
  172. package/dist/tensors/tensorProperties.d.ts +10 -9
  173. package/dist/tensors/tensorProperties.d.ts.map +1 -1
  174. package/dist/tensors/tensorProperties.js +22 -12
  175. package/dist/tensors/tensorProperties.js.map +1 -1
  176. package/dist/tensors/voigt.d.ts +56 -0
  177. package/dist/tensors/voigt.d.ts.map +1 -0
  178. package/dist/tensors/voigt.js +188 -0
  179. package/dist/tensors/voigt.js.map +1 -0
  180. package/dist/tolerances.d.ts +56 -1
  181. package/dist/tolerances.d.ts.map +1 -1
  182. package/dist/tolerances.js +51 -1
  183. package/dist/tolerances.js.map +1 -1
  184. package/dist/version.d.ts +1 -1
  185. package/dist/version.js +1 -1
  186. package/package.json +1 -1
  187. package/src/cell.ts +78 -51
  188. package/src/checks.ts +84 -0
  189. package/src/closure.ts +214 -0
  190. package/src/coordinates.ts +370 -0
  191. package/src/crystalClasses.ts +271 -157
  192. package/src/freeze.ts +14 -0
  193. package/src/index.ts +33 -12
  194. package/src/indices.ts +102 -42
  195. package/src/lattice.ts +41 -1
  196. package/src/linalg.ts +3 -3
  197. package/src/magnetic.ts +24 -11
  198. package/src/notation.ts +73 -0
  199. package/src/operations.ts +78 -71
  200. package/src/plane.ts +531 -151
  201. package/src/pointGroups/crystalForms.ts +11 -44
  202. package/src/pointGroups/crystalFormsData.ts +66 -1
  203. package/src/pointGroups/elements.ts +82 -92
  204. package/src/pointGroups/identify.ts +38 -97
  205. package/src/pointGroups/itaOrder.ts +117 -101
  206. package/src/pointGroups/itcData.ts +404 -0
  207. package/src/pointGroups/itcMagneticData.ts +206 -0
  208. package/src/pointGroups/keys.ts +144 -0
  209. package/src/pointGroups/magneticSymbols.ts +18 -17
  210. package/src/pointGroups/orbits.ts +41 -89
  211. package/src/pointGroups/pointGroups.ts +593 -298
  212. package/src/pointGroups/properties.ts +44 -40
  213. package/src/pointGroups/seitzData.ts +147 -0
  214. package/src/pointGroups/shubnikovData.ts +103 -0
  215. package/src/pointGroups/wyckoff.ts +137 -112
  216. package/src/pointGroups/wyckoffData.ts +793 -170
  217. package/src/siteSymmetry.ts +43 -40
  218. package/src/spaceGroups/affine.ts +3 -2
  219. package/src/spaceGroups/cell.ts +227 -116
  220. package/src/spaceGroups/describe.ts +23 -19
  221. package/src/spaceGroups/planeGroupData.ts +28 -9
  222. package/src/spaceGroups/planeGroups.ts +2 -1
  223. package/src/spaceGroups/planeLattice.ts +208 -0
  224. package/src/spaceGroups/planePointGroups.ts +23 -3
  225. package/src/spaceGroups/positions.ts +202 -78
  226. package/src/spaceGroups/rational.ts +59 -0
  227. package/src/tensors/propertyTable.ts +26 -14
  228. package/src/tensors/rowEchelon.ts +4 -3
  229. package/src/tensors/tensorForm.ts +258 -88
  230. package/src/tensors/tensorProperties.ts +34 -14
  231. package/src/tensors/voigt.ts +268 -0
  232. package/src/tolerances.ts +66 -1
  233. package/src/version.ts +1 -1
  234. package/dist/pointGroups/data.d.ts +0 -75
  235. package/dist/pointGroups/data.d.ts.map +0 -1
  236. package/dist/pointGroups/data.js +0 -212
  237. package/dist/pointGroups/data.js.map +0 -1
  238. package/dist/pointGroups/magneticData.d.ts +0 -66
  239. package/dist/pointGroups/magneticData.d.ts.map +0 -1
  240. package/dist/pointGroups/magneticData.js +0 -184
  241. package/dist/pointGroups/magneticData.js.map +0 -1
  242. package/dist/spaceGroups/snap.d.ts +0 -20
  243. package/dist/spaceGroups/snap.d.ts.map +0 -1
  244. package/dist/spaceGroups/snap.js +0 -103
  245. package/dist/spaceGroups/snap.js.map +0 -1
  246. package/src/pointGroups/data.ts +0 -305
  247. package/src/pointGroups/magneticData.ts +0 -328
  248. package/src/spaceGroups/snap.ts +0 -121
package/src/plane.ts CHANGED
@@ -10,10 +10,26 @@
10
10
  * `tolerance` (docs/conventions.md, "Plane groups").
11
11
  */
12
12
 
13
- import { describePlaneOperation } from './spaceGroups/describe.js';
14
- import { planeAsymmetricUnit, planeCellElements } from './spaceGroups/cell.js';
13
+ import { TOLERANCE_KEYS, checkOptions, shown } from './checks.js';
14
+ import { describePlaneOperation, type PlaneOperationKind } from './spaceGroups/describe.js';
15
+ import { planeAsymmetricUnit, planeElements, planeElementsInBox } from './spaceGroups/cell.js';
15
16
  import { toPlain, type ExactOperation } from './spaceGroups/affine.js';
16
17
  import { type PlaneSystem } from './spaceGroups/planeGroupData.js';
18
+ import {
19
+ PLANE_FAMILIES,
20
+ planeBravaisLattice,
21
+ planeLatticeFromParameters,
22
+ planeLatticeParameters,
23
+ planeLaueClass,
24
+ planeMetricTensor,
25
+ planeReciprocalBasis,
26
+ type CellRestrictions,
27
+ type LatticeParameters,
28
+ type Mat2,
29
+ type PlaneBravaisLattice,
30
+ } from './spaceGroups/planeLattice.js';
31
+ import { deepFreeze } from './freeze.js';
32
+ import { changeCoordinates } from './coordinates.js';
17
33
  import {
18
34
  PLANE_GROUP_KEYS as GROUP_KEYS,
19
35
  planeGroupEntry,
@@ -31,12 +47,29 @@ import {
31
47
  planePointGroupSystem,
32
48
  type PlanePointGroupKey,
33
49
  } from './spaceGroups/planePointGroups.js';
34
- import { planeOrbit, planeSiteSymmetry, planeWyckoffPositionOf } from './spaceGroups/positions.js';
35
- import { planeSnapToWyckoffPosition } from './spaceGroups/snap.js';
36
- import { parseRational, rational, toNumber, type Rational } from './spaceGroups/rational.js';
50
+ import {
51
+ planeMetric,
52
+ planeOrbit,
53
+ planeSiteOfPosition,
54
+ planeWyckoffDistances,
55
+ planeWyckoffPositionOf,
56
+ } from './spaceGroups/positions.js';
57
+ import { nearestFraction, parseRational, toNumber, type Rational } from './spaceGroups/rational.js';
37
58
 
38
59
  export { VERSION } from './version.js';
60
+ export { EPSILON, type ToleranceOptions } from './tolerances.js';
61
+ import { toleranceOf, type ToleranceOptions } from './tolerances.js';
62
+ import { compactSymbol } from './notation.js';
39
63
  export type { PlaneSystem } from './spaceGroups/planeGroupData.js';
64
+ export type {
65
+ CellRestrictions,
66
+ LatticeParameters,
67
+ Mat2,
68
+ PlaneBravaisLattice,
69
+ PlaneCellParameter,
70
+ PlaneFixedAngles,
71
+ } from './spaceGroups/planeLattice.js';
72
+ export type { PlaneOperationKind } from './spaceGroups/describe.js';
40
73
 
41
74
  /** The short symbol of a plane group, e.g. `'p2mg'`. */
42
75
  export type PlaneGroupKey =
@@ -69,17 +102,18 @@ export const POINT_GROUP_KEYS: readonly PointGroupKey[] = Object.freeze([...PLAN
69
102
 
70
103
  /** Options that choose the setting of a plane point group. */
71
104
  export interface SettingOptions {
72
- /** 1-based setting: for the point group `3m` 1 is `3m1` (default) and 2 is `31m`; the other point groups have one, and a plane group takes only 1. */
73
- readonly setting?: number;
74
- }
75
-
76
- /** Options of the functions that take a point. */
77
- export interface PointOptions {
78
105
  /**
79
- * Two points count as the same, modulo the lattice, if each coordinate (lattice basis) differs
80
- * by less than this from an integer. Default 10⁻⁶; must be below 1/2.
106
+ * The setting, by its 1-based index or its symbol (spaces ignored): for the point group `3m` 1 or
107
+ * `'3m1'` (default) and 2 or `'31m'`, and the key `'3m'` names the default; the other point groups
108
+ * have one, and a plane group takes only 1 or its own symbol (short or full).
81
109
  */
82
- readonly tolerance?: number;
110
+ readonly setting?: number | string;
111
+ }
112
+
113
+ /** Options of `symbol`: the setting, and the form of a plane group's symbol. */
114
+ export interface SymbolOptions extends SettingOptions {
115
+ /** `'short'` (default): the symbol as one word, the key; `'full'`: the full symbol, positions separated by spaces (`'p 1 m 1'` for `pm`). */
116
+ readonly form?: 'short' | 'full';
83
117
  }
84
118
 
85
119
  /** An operation (W, w) in the lattice basis: x ↦ W·x + w. */
@@ -96,20 +130,23 @@ export interface PlaneGroup {
96
130
  readonly key: PlaneGroupKey;
97
131
  /** The number of the plane group, 1 to 17. */
98
132
  readonly number: number;
99
- /** The full symbol as ITA prints it, e.g. `'p2mg'` or `'p1m1'`. */
100
- readonly fullSymbol: string;
101
133
  /** The plane point group. */
102
134
  readonly pointGroup: PointGroupKey;
103
135
  /** The setting of the point group: 2 for `p31m`, otherwise 1. */
104
136
  readonly pointGroupSetting: number;
105
137
  /** The crystal system. */
106
138
  readonly crystalSystem: PlaneSystem;
139
+ /** The Bravais lattice (ITA 2016 Table 2.1.1.1, p. 143): `'mp'`, `'op'`, `'oc'`, `'tp'` or `'hp'`. */
140
+ readonly bravaisLattice: PlaneBravaisLattice;
141
+ /**
142
+ * The Patterson symmetry as ITA prints it in the headline of the group (Chapter 2.2), a plane group:
143
+ * the lattice of the group with its Laue class, e.g. `'p2mm'` for `p2mg`, `'c2mm'` for `cm`.
144
+ */
145
+ readonly pattersonSymmetry: PlaneGroupKey;
107
146
  /** The centring translations besides (0, 0): `[[0.5, 0.5]]` for `cm` and `c2mm`, otherwise none. */
108
147
  readonly centring: readonly (readonly number[])[];
109
- /** The block "Origin" as ITA prints it, e.g. `'at 2mm'`. */
148
+ /** The block "Origin" as ITA prints it, its positions spaced as printed, e.g. `'at 2 m m'`, `'at 2 1 g'`. */
110
149
  readonly origin: string;
111
- /** The order of the group modulo the lattice: the number of `operations`. */
112
- readonly order: number;
113
150
  }
114
151
 
115
152
  /** A plane point group. */
@@ -120,6 +157,25 @@ export interface PointGroup {
120
157
  readonly crystalSystem: PlaneSystem;
121
158
  /** The order of the group. */
122
159
  readonly order: number;
160
+ /**
161
+ * The Laue class: the point group with the symmetry centre of the plane, the twofold rotation,
162
+ * added (ITA 2016 § 3.2.1.1, p. 720); one of `'2'`, `'2mm'`, `'4'`, `'4mm'`, `'6'`, `'6mm'`.
163
+ */
164
+ readonly laueClass: PointGroupKey;
165
+ }
166
+
167
+ /** A plane group found by `findPlaneGroup`. */
168
+ export interface PlaneGroupFound {
169
+ /** The key of the plane group. */
170
+ readonly key: PlaneGroupKey;
171
+ }
172
+
173
+ /** A plane point group in a setting, as `findPointGroup` finds it. */
174
+ export interface PointGroupInSetting {
175
+ /** The key of the plane point group. */
176
+ readonly key: PointGroupKey;
177
+ /** The 1-based index of the setting. */
178
+ readonly setting: number;
123
179
  }
124
180
 
125
181
  /** A setting of a plane point group. */
@@ -129,15 +185,18 @@ export interface Setting {
129
185
  /** Its symbol: `'3m1'` or `'31m'` for `3m`, otherwise the key. */
130
186
  readonly symbol: string;
131
187
  /** True for the default setting (setting 1). */
132
- readonly default: boolean;
188
+ readonly isDefault: boolean;
133
189
  }
134
190
 
135
191
  /** What an operation is, geometrically, as ITA describes it under "Symmetry operations". */
136
192
  export interface OperationDescription {
137
- /** `'identity'`, `'translation'`, `'rotation'`, `'mirror'` (a reflection in a line) or `'glide'` (a glide reflection). */
138
- readonly kind: 'identity' | 'translation' | 'rotation' | 'mirror' | 'glide';
139
- /** The order of the linear part: 1 for the identity and a translation, 2 for a mirror or glide. */
140
- readonly order: number;
193
+ /**
194
+ * `'identity'`, `'translation'`, `'rotation'`, `'reflection'` (in a line) or `'glide-reflection'`,
195
+ * as ITA names the operations (ITA 2016 Table 2.1.2.1, p. 145).
196
+ */
197
+ readonly kind: PlaneOperationKind;
198
+ /** The n of the linear part (an n-fold rotation): 1 for the identity and a translation, 2 for a reflection or glide reflection. */
199
+ readonly n: number;
141
200
  /** For a rotation of order 3 or more: `'+'` if it turns a towards b, `'-'` otherwise. */
142
201
  readonly sense?: '+' | '-';
143
202
  /** For a translation: the translation vector. */
@@ -150,12 +209,14 @@ export interface OperationDescription {
150
209
  /** For a mirror or glide: the direction of its line, the shortest integer vector, first non-zero component positive. */
151
210
  readonly direction?: readonly number[];
152
211
  /**
153
- * For a mirror or glide: the normal of its line in the lattice basis, its symmetry direction as in
154
- * ITA Table 2.1.3.1: the shortest integer vector along the columns of W − I, first non-zero
155
- * component positive. Without a metric it is not the perpendicular of `direction`: in a hexagonal
212
+ * For a reflection or glide reflection: its axis, the normal of its line in the lattice basis (as
213
+ * the `axis` of a reflection of the point groups is the normal of its plane, #137 C3), its symmetry
214
+ * direction with the sign of its Seitz symbol (ITA 2016 Tables 1.4.2.4, 1.4.2.5, p. 53: `m₁₀`, `m₁₂`,
215
+ * #107, #114): the shortest integer vector along the columns of W − I, first non-zero component
216
+ * positive, which is the Seitz direction for every plane group (tested). Without a metric it is not the perpendicular of `direction`: in a hexagonal
156
217
  * basis the normal of a line along [1,0] is [1,2].
157
218
  */
158
- readonly normal?: readonly number[];
219
+ readonly axis?: readonly number[];
159
220
  /** For a glide: the glide vector (w + W·w)/2, not reduced modulo the lattice. */
160
221
  readonly glide?: readonly number[];
161
222
  }
@@ -172,17 +233,34 @@ export interface WyckoffPosition {
172
233
  readonly coordinates: readonly string[];
173
234
  }
174
235
 
175
- /** A point snapped onto a Wyckoff position: the position, as `wyckoffPositions` gives it, and the point on it. */
176
- export interface SnappedPosition extends WyckoffPosition {
177
- /** The point on the position nearest to the given one, modulo the lattice, in [0, 1). */
236
+ /** The distance of a point to a Wyckoff position: the position, as `wyckoffPositions` gives it, the nearest point of it, and the distance. */
237
+ export interface WyckoffDistance extends WyckoffPosition {
238
+ /** The point of the position nearest to the given one (lattice basis), modulo the lattice, in [0, 1). */
178
239
  readonly point: readonly number[];
240
+ /**
241
+ * The distance of the given point to the position: without a basis the larger of the two
242
+ * coordinate differences modulo the lattice, with a basis Euclidean in its unit.
243
+ */
244
+ readonly distance: number;
245
+ }
246
+
247
+ /** Options of `wyckoffDistances`. */
248
+ export interface WyckoffDistanceOptions {
249
+ /**
250
+ * The Cartesian basis of the lattice, a 2 × 2 matrix whose columns are a and b; with it the
251
+ * distances are Euclidean, without it they are measured per lattice coordinate.
252
+ */
253
+ readonly basis?: readonly (readonly number[])[];
179
254
  }
180
255
 
181
256
  /** The site symmetry of a point under a plane group. */
182
257
  export interface SiteSymmetry {
183
258
  /** Indices into `operations` of those that map the point onto itself modulo the lattice, ascending: a subgroup. */
184
259
  readonly operations: readonly number[];
185
- /** The point set onto the fixed space of its site symmetry, in [0, 1), which removes rounding errors within the tolerance. */
260
+ /**
261
+ * The point set onto the Wyckoff position it lies on (the nearest point of the position, as
262
+ * `wyckoffDistances` gives it), in [0, 1).
263
+ */
186
264
  readonly point: readonly number[];
187
265
  /** The number of points in the conventional cell equivalent to it. */
188
266
  readonly multiplicity: number;
@@ -190,59 +268,74 @@ export interface SiteSymmetry {
190
268
  readonly general: boolean;
191
269
  }
192
270
 
193
- /** The asymmetric unit of a plane group, a convex polygon in the lattice basis. */
271
+ /** The asymmetric unit of a plane group: the printed inequalities, and the convex polygon they bound (lattice basis). */
194
272
  export interface AsymmetricUnit {
195
- /** Its vertices, counter-clockwise (a towards b), starting at the lowest (smallest y, then x). */
196
- readonly vertices: readonly (readonly number[])[];
197
- /** Per edge, the inequality [a, b, c] for a·x + b·y ≤ c (integers, no common factor); entry i holds the edge from vertex i to vertex i + 1. */
273
+ /**
274
+ * The inequalities as ITA prints them, in printed order, each [a, b, c] for a·x + b·y ≤ c
275
+ * (integers, no common factor), also those that hold no edge of the polygon (p3: x ≤ 2/3).
276
+ */
198
277
  readonly inequalities: readonly (readonly number[])[];
278
+ /** The vertices of the polygon, counter-clockwise (a towards b), starting at the lowest (smallest y, then x). */
279
+ readonly vertices: readonly (readonly number[])[];
280
+ /** Per edge, from vertex i to vertex i + 1, the index into `inequalities` of the inequality that holds it. */
281
+ readonly edges: readonly number[];
199
282
  }
200
283
 
201
- /** A rotation centre in the cell. */
202
- export interface RotationCentre {
203
- /** The highest order of a rotation about it. */
204
- readonly order: number;
205
- /** Its position in [0, 1]². */
284
+ /** A rotation point (ITA 2016 Table 2.1.2.1, p. 145: the symmetry element of a rotation in the plane). */
285
+ export interface RotationPoint {
286
+ /** The highest n of an n-fold rotation about it. */
287
+ readonly n: number;
288
+ /** Its location, lattice basis. */
206
289
  readonly point: readonly number[];
207
290
  }
208
291
 
209
- /** A mirror or glide line: the part of it in the cell. */
292
+ /** A mirror or glide line, as a point and a direction (lattice basis). */
210
293
  export interface SymmetryLine {
211
294
  /** `'mirror'` or `'glide'`. */
212
295
  readonly kind: 'mirror' | 'glide';
213
296
  /** The direction of the line, the shortest integer vector, first non-zero component positive. */
214
297
  readonly direction: readonly number[];
215
- /** The normal of the line in the lattice basis, as in `describeOperations`. */
216
- readonly normal: readonly number[];
298
+ /** The normal of the line in the lattice basis, its symmetry direction, as `axis` in `describeOperations`. */
299
+ readonly axis: readonly number[];
217
300
  /** For a glide line its glide vector s·direction, 0 < s < 1; for a mirror line (0, 0). */
218
301
  readonly glide: readonly number[];
219
- /** The two ends of the segment of the line in the cell [0, 1]², in the order of `direction`. */
220
- readonly segment: readonly (readonly number[])[];
302
+ /** A point of the line: its intersection with y = 0, or with x = 0 for a line along a. */
303
+ readonly point: readonly number[];
221
304
  }
222
305
 
223
- /** The symmetry elements of a plane group in its conventional cell [0, 1]², boundary included. */
306
+ /** Symmetry elements of a plane group. */
224
307
  export interface SymmetryElements {
225
- /** The rotation centres, by descending order, then by y and x. */
226
- readonly rotations: readonly RotationCentre[];
227
- /** The mirror and glide lines that cross the cell, by direction, then by the start of the segment (y, then x). */
308
+ /** The rotation points, by descending n, then by y and x. */
309
+ readonly rotationPoints: readonly RotationPoint[];
310
+ /** The mirror and glide lines, by direction, then by their point (x on y = 0, or y on x = 0), mirror before glide. */
228
311
  readonly lines: readonly SymmetryLine[];
229
312
  }
230
313
 
314
+ /** Options of `symmetryElements`. */
315
+ export interface SymmetryElementsOptions {
316
+ /**
317
+ * A box of the plane, lattice basis, as its lower left and its upper right corner (x₀ ≤ x₁,
318
+ * y₀ ≤ y₁; a line or a point of the plane also): all lattice translates of the elements that meet
319
+ * it, boundary included, the lines not clipped.
320
+ */
321
+ readonly box?: readonly (readonly number[])[];
322
+ }
323
+
231
324
  // ---------------------------------------------------------------------------------------------
232
325
 
233
326
  const numbers = (v: readonly Rational[]): number[] => v.map(toNumber);
234
327
 
235
- function isPlaneGroupKey(key: unknown): key is PlaneGroupKey {
328
+ function isGroupKey(key: unknown): key is PlaneGroupKey {
236
329
  return typeof key === 'string' && (GROUP_KEYS as readonly string[]).includes(key);
237
330
  }
238
331
 
239
332
  function unknownKey(key: unknown, what = 'plane group or plane point group'): never {
240
- throw new RangeError(`Unknown ${what}: ${JSON.stringify(key)}`);
333
+ throw new RangeError(`Unknown ${what}: ${shown(key)}`);
241
334
  }
242
335
 
243
336
  /** The plane group of a key; throws for a point group or an unknown key. */
244
337
  function groupKey(key: unknown, what: string): PlaneGroupKey {
245
- if (isPlaneGroupKey(key)) return key;
338
+ if (isGroupKey(key)) return key;
246
339
  if (isPlanePointGroupKey(key)) {
247
340
  throw new RangeError(`${what} takes the key of a plane group, not of the point group ${key}`);
248
341
  }
@@ -252,26 +345,47 @@ function groupKey(key: unknown, what: string): PlaneGroupKey {
252
345
  /** The key of a plane point group; throws for a plane group or an unknown key. */
253
346
  function pointKey(key: unknown, what: string): PointGroupKey {
254
347
  if (isPlanePointGroupKey(key)) return key;
255
- if (isPlaneGroupKey(key)) {
348
+ if (isGroupKey(key)) {
256
349
  throw new RangeError(`${what} takes the key of a plane point group; ${key} is a plane group (planeGroup)`);
257
350
  }
258
351
  return unknownKey(key, 'plane point group');
259
352
  }
260
353
 
261
- function settingOf(options: SettingOptions | undefined): number | undefined {
262
- return options?.setting;
354
+ /**
355
+ * The index of the setting that `options` names for a key, or undefined if it names none: an index
356
+ * is passed on (and checked where it is used), a symbol is looked up among the settings of the key.
357
+ */
358
+ function settingOf(key: PlaneGroupKey | PointGroupKey, options: SettingOptions | undefined): number | undefined {
359
+ const setting = options?.setting;
360
+ if (typeof setting !== 'string') return setting;
361
+ const wanted = compactSymbol(setting);
362
+ if (isGroupKey(key)) {
363
+ if (wanted === key || wanted === planeGroupEntry(key).fullSymbol) return 1;
364
+ throw new RangeError(
365
+ `The plane group ${key} has no setting ${shown(setting)} (its symbols: ${key}, ${planeGroupEntry(key).fullSymbol})`,
366
+ );
367
+ }
368
+ const symbols = Array.from({ length: planePointGroupSettingCount(key) }, (_, i) => planePointGroupSymbol(key, i + 1));
369
+ const index = symbols.findIndex((s) => s === wanted);
370
+ if (index >= 0) return index + 1;
371
+ // The key of a point group with several settings is the symbol of none; it names the default.
372
+ if (wanted === key) return 1;
373
+ throw new RangeError(
374
+ `The plane point group ${key} has no setting ${shown(setting)} (settings: ${symbols.join(', ')})`,
375
+ );
263
376
  }
264
377
 
265
378
  /** The exact operations for a key: a plane group (setting 1 only) or a point group in a setting. */
266
379
  function exact(key: unknown, options: SettingOptions | undefined, generatorsOnly: boolean): ExactOperation[] {
267
- const setting = settingOf(options);
268
- if (isPlaneGroupKey(key)) {
380
+ if (isGroupKey(key)) {
381
+ const setting = settingOf(key, options);
269
382
  if (setting !== undefined && setting !== 1) {
270
383
  throw new RangeError(`The plane group ${key} has no setting ${String(setting)}`);
271
384
  }
272
385
  return generatorsOnly ? planeGroupGenerators(key) : planeGroupOperations(key);
273
386
  }
274
387
  if (isPlanePointGroupKey(key)) {
388
+ const setting = settingOf(key, options);
275
389
  return generatorsOnly ? planePointGroupGenerators(key, setting) : planePointGroupOperations(key, setting);
276
390
  }
277
391
  return unknownKey(key);
@@ -290,44 +404,18 @@ function describe(op: ExactOperation): OperationDescription {
290
404
  const d = describePlaneOperation(op);
291
405
  return Object.freeze({
292
406
  kind: d.kind,
293
- order: d.order,
407
+ n: d.n,
294
408
  ...(d.sense ? { sense: d.sense } : {}),
295
409
  ...(d.translation ? { translation: Object.freeze(numbers(d.translation)) } : {}),
296
410
  ...(d.location ? { location: Object.freeze(numbers(d.location)) } : {}),
297
411
  ...(d.direction ? { direction: Object.freeze([...d.direction]) } : {}),
298
- ...(d.normal ? { normal: Object.freeze([...d.normal]) } : {}),
412
+ ...(d.axis ? { axis: Object.freeze([...d.axis]) } : {}),
299
413
  ...(d.glide ? { glide: Object.freeze(numbers(d.glide)) } : {}),
300
414
  });
301
415
  }
302
416
 
303
- /** Tolerance for reading an integer or a fraction from a double. */
304
- const READ_TOLERANCE = 1e-9;
305
- /** The largest denominator of a translation that `describeOperationsOf` reads. */
306
- const MAX_DENOMINATOR = 12;
307
-
308
- function fractionOf(value: unknown): Rational {
309
- if (typeof value === 'number' && Number.isFinite(value)) {
310
- for (let d = 1; d <= MAX_DENOMINATOR; d++) {
311
- const n = Math.round(value * d);
312
- if (Math.abs(value * d - n) < READ_TOLERANCE * d) return rational(n, d);
313
- }
314
- }
315
- throw new RangeError(
316
- `Not within 10⁻⁹ of a translation with a denominator of at most ${MAX_DENOMINATOR}: ${shown(value)}`,
317
- );
318
- }
319
-
320
- /** A value for an error message; never throws (BigInt, circular objects). */
321
- function shown(value: unknown): string {
322
- try {
323
- return JSON.stringify(value) ?? String(value);
324
- } catch {
325
- return String(value);
326
- }
327
- }
328
-
329
417
  /** An operation from a caller as an exact operation; throws a RangeError unless it has the shape of a plane operation. */
330
- function exactOf(op: unknown): ExactOperation {
418
+ function exactOf(op: unknown, tolerance: number): ExactOperation {
331
419
  const o = op as Partial<PlaneOperation> | null;
332
420
  const m = o?.matrix;
333
421
  const t = o?.translation;
@@ -337,13 +425,64 @@ function exactOf(op: unknown): ExactOperation {
337
425
  }
338
426
  const matrix = m.map((row) =>
339
427
  row.map((v) => {
340
- if (!(typeof v === 'number' && Math.abs(v - Math.round(v)) < READ_TOLERANCE)) {
428
+ if (!(typeof v === 'number' && Math.abs(v - Math.round(v)) < tolerance)) {
341
429
  throw new RangeError(`The matrix of a plane operation has integer entries, not ${shown(m)}`);
342
430
  }
343
431
  return Math.round(v) + 0;
344
432
  }),
345
433
  );
346
- return { matrix, translation: t.map(fractionOf) };
434
+ return { matrix, translation: t.map((v) => nearestFraction(v, tolerance, 'translation')) };
435
+ }
436
+
437
+ /** True if `key` is the key of one of the 17 plane groups (its short symbol, as ITA prints it). */
438
+ export function isPlaneGroupKey(key: string): key is PlaneGroupKey {
439
+ return isGroupKey(key);
440
+ }
441
+
442
+ /** True if `key` is the key of one of the 10 plane point groups. */
443
+ export function isPointGroupKey(key: string): key is PointGroupKey {
444
+ return isPlanePointGroupKey(key);
445
+ }
446
+
447
+ /** The 17 plane groups, in ITA's order (plane group n at index n − 1). */
448
+ export function planeGroups(): readonly PlaneGroup[] {
449
+ return Object.freeze(PLANE_GROUP_KEYS.map((key) => planeGroup(key)));
450
+ }
451
+
452
+ /** The 10 plane point groups, in the order of ITA Table 3.2.1.1. */
453
+ export function pointGroups(): readonly PointGroup[] {
454
+ return Object.freeze(POINT_GROUP_KEYS.map((key) => pointGroup(key)));
455
+ }
456
+
457
+ /**
458
+ * Finds a plane group by a symbol: the key (the short symbol, `'pm'`) or the full symbol (`'p1m1'`,
459
+ * `'p 1 m 1'`), spaces ignored (docs/conventions.md, "Reading symbols"). The lattice letter is
460
+ * lower case, as ITA prints it. Gives `undefined` if the symbol names no plane group; throws a
461
+ * RangeError for a value that is not a string.
462
+ */
463
+ export function findPlaneGroup(symbol: string): PlaneGroupFound | undefined {
464
+ if (typeof symbol !== 'string') throw new RangeError(`A symbol is a string, not ${shown(symbol)}`);
465
+ const wanted = compactSymbol(symbol);
466
+ const key = PLANE_GROUP_KEYS.find((k) => k === wanted || planeGroupEntry(k).fullSymbol === wanted);
467
+ return key === undefined ? undefined : Object.freeze({ key });
468
+ }
469
+
470
+ /**
471
+ * Finds a plane point group by a symbol: the key, or the symbol of a setting (`'3m1'`, `'31m'`),
472
+ * spaces ignored; the key `'3m'` gives the default setting 1. Gives `undefined` if the symbol names
473
+ * no plane point group, also for the symbol of a plane group (that is `findPlaneGroup`); throws a
474
+ * RangeError for a value that is not a string.
475
+ */
476
+ export function findPointGroup(symbol: string): PointGroupInSetting | undefined {
477
+ if (typeof symbol !== 'string') throw new RangeError(`A symbol is a string, not ${shown(symbol)}`);
478
+ const wanted = compactSymbol(symbol);
479
+ for (const key of POINT_GROUP_KEYS) {
480
+ for (let i = 1; i <= planePointGroupSettingCount(key); i++) {
481
+ if (planePointGroupSymbol(key, i) === wanted) return Object.freeze({ key, setting: i });
482
+ }
483
+ if (key === wanted) return Object.freeze({ key, setting: 1 });
484
+ }
485
+ return undefined;
347
486
  }
348
487
 
349
488
  /** The plane group with this key (short symbol). Throws a RangeError for an unknown key. */
@@ -353,22 +492,27 @@ export function planeGroup(key: PlaneGroupKey): PlaneGroup {
353
492
  return Object.freeze({
354
493
  key: entry.symbol as PlaneGroupKey,
355
494
  number: entry.number,
356
- fullSymbol: entry.fullSymbol,
357
495
  pointGroup: point.key,
358
496
  pointGroupSetting: point.setting,
359
497
  crystalSystem: entry.system,
498
+ bravaisLattice: planeBravaisLattice(entry.system, entry.symbol),
499
+ pattersonSymmetry: entry.pattersonSymmetry as PlaneGroupKey,
360
500
  centring: Object.freeze(
361
501
  entry.centring.map((t) => Object.freeze(t.split(',').map((c) => toNumber(parseRational(c))))),
362
502
  ),
363
503
  origin: entry.origin,
364
- order: planeGroupOperations(entry.symbol).length,
365
504
  });
366
505
  }
367
506
 
368
507
  /** The plane point group with this key. Throws a RangeError for an unknown key. */
369
508
  export function pointGroup(key: PointGroupKey): PointGroup {
370
509
  const k = pointKey(key, 'pointGroup');
371
- return Object.freeze({ key: k, crystalSystem: planePointGroupSystem(k), order: planePointGroupOperations(k).length });
510
+ return Object.freeze({
511
+ key: k,
512
+ crystalSystem: planePointGroupSystem(k),
513
+ order: planePointGroupOperations(k).length,
514
+ laueClass: planeLaueClass(k),
515
+ });
372
516
  }
373
517
 
374
518
  /**
@@ -379,14 +523,37 @@ export function settings(key: PointGroupKey): readonly Setting[] {
379
523
  const k = pointKey(key, 'settings');
380
524
  return Object.freeze(
381
525
  Array.from({ length: planePointGroupSettingCount(k) }, (_, i) =>
382
- Object.freeze({ index: i + 1, symbol: planePointGroupSymbol(k, i + 1), default: i === 0 }),
526
+ Object.freeze({ index: i + 1, symbol: planePointGroupSymbol(k, i + 1), isDefault: i === 0 }),
383
527
  ),
384
528
  );
385
529
  }
386
530
 
387
- /** The symbol of a plane point group in a setting: `'3m1'` or `'31m'` for `3m`, otherwise the key. */
388
- export function symbol(key: PointGroupKey, options?: SettingOptions): string {
389
- return planePointGroupSymbol(pointKey(key, 'symbol'), settingOf(options));
531
+ /**
532
+ * The symbol of a plane group or a plane point group (#137 F4). In the short form (the default) the
533
+ * Hermann–Mauguin symbol as one word: for a plane group the key (`'p2mg'`, `'pm'`), for a plane
534
+ * point group in a setting `'3m1'` or `'31m'` for `3m`, otherwise the key. In the form `'full'`
535
+ * the full symbol with its positions separated by spaces, as in the other entry points: `'p 1 m 1'`
536
+ * for `pm` (ITA prints `p1m1`), `'p 2 m g'`, `'3 m 1'`; ITA prints no other full symbol for a plane
537
+ * point group (Ch. 3.2, p. 721, and Table 3.2.3.1). A plane group has setting 1 only. Throws a
538
+ * RangeError for an unknown key, setting or form.
539
+ */
540
+ export function symbol(key: PlaneGroupKey | PointGroupKey, options?: SymbolOptions): string {
541
+ checkOptions(options, ['setting', 'form'], 'symbol');
542
+ const form = options?.form ?? 'short';
543
+ if (form !== 'short' && form !== 'full') {
544
+ throw new RangeError(`Unknown symbol form: ${shown(form)} (short or full)`);
545
+ }
546
+ // Every position of a plane symbol is one character, the lattice letter included.
547
+ const spaced = (text: string) => (form === 'full' ? [...text].join(' ') : text);
548
+ if (isGroupKey(key)) {
549
+ const setting = settingOf(key, options);
550
+ if (setting !== undefined && setting !== 1) {
551
+ throw new RangeError(`The plane group ${key} has no setting ${shown(setting)}`);
552
+ }
553
+ return spaced(form === 'full' ? planeGroupEntry(key).fullSymbol : key);
554
+ }
555
+ if (!isPlanePointGroupKey(key)) return unknownKey(key);
556
+ return spaced(planePointGroupSymbol(key, settingOf(key, options)));
390
557
  }
391
558
 
392
559
  /**
@@ -398,6 +565,7 @@ export function symbol(key: PointGroupKey, options?: SettingOptions): string {
398
565
  * or setting.
399
566
  */
400
567
  export function operations(key: PlaneGroupKey | PointGroupKey, options?: SettingOptions): readonly PlaneOperation[] {
568
+ checkOptions(options, ['setting'], 'operations');
401
569
  return Object.freeze(exact(key, options, false).map(plain));
402
570
  }
403
571
 
@@ -407,18 +575,20 @@ export function operations(key: PlaneGroupKey | PointGroupKey, options?: Setting
407
575
  * generators of its symmorphic plane group. Throws a RangeError for an unknown key or setting.
408
576
  */
409
577
  export function generators(key: PlaneGroupKey | PointGroupKey, options?: SettingOptions): readonly PlaneOperation[] {
578
+ checkOptions(options, ['setting'], 'generators');
410
579
  return Object.freeze(exact(key, options, true).map(plain));
411
580
  }
412
581
 
413
582
  /**
414
583
  * Each operation of `operations` (same key and setting) described geometrically, index for index:
415
- * what it is, its order and sense, where its symmetry element lies, its glide part. Throws a
584
+ * what it is, its n and sense, where its symmetry element lies, its glide part. Throws a
416
585
  * RangeError for an unknown key or setting.
417
586
  */
418
587
  export function describeOperations(
419
588
  key: PlaneGroupKey | PointGroupKey,
420
589
  options?: SettingOptions,
421
590
  ): readonly OperationDescription[] {
591
+ checkOptions(options, ['setting'], 'describeOperations');
422
592
  return Object.freeze(exact(key, options, false).map(describe));
423
593
  }
424
594
 
@@ -427,16 +597,22 @@ export function describeOperations(
427
597
  * `describeOperations` describes those of a group: for instance a product of operations, an
428
598
  * operation shifted by a lattice translation, or the operations of a site symmetry. Each operation is
429
599
  * `{ matrix, translation }` as `operations` gives it. Each matrix must have integer entries (within
430
- * 10⁻⁹) and be the linear part of a crystallographic plane point group (determinant ±1, order 1,
431
- * 2, 3, 4 or 6); each translation must lie within 10⁻⁹ of a fraction with a denominator of at most
432
- * 12 (1/3 as 0.333…), as the translations of `operations` and their products do. Throws a
433
- * RangeError otherwise.
600
+ * the tolerance, per entry) and be the linear part of a crystallographic plane point group
601
+ * (determinant ±1, order 1, 2, 3, 4 or 6); each component of a translation is read as the fraction
602
+ * with a denominator of at most 12 within the tolerance (1/3 from 0.333…), as the translations of
603
+ * `operations` and their products are. Throws a RangeError otherwise, also for a component within
604
+ * the tolerance of two such fractions (which can lie 1/132 apart).
434
605
  */
435
- export function describeOperationsOf(operations: readonly PlaneOperation[]): readonly OperationDescription[] {
606
+ export function describeOperationsOf(
607
+ operations: readonly PlaneOperation[],
608
+ options?: ToleranceOptions,
609
+ ): readonly OperationDescription[] {
610
+ checkOptions(options, TOLERANCE_KEYS, 'describeOperationsOf');
611
+ const tolerance = toleranceOf(options, 'operations');
436
612
  if (!Array.isArray(operations)) {
437
613
  throw new RangeError('describeOperationsOf takes a list of operations { matrix, translation }');
438
614
  }
439
- return Object.freeze(operations.map((op) => describe(exactOf(op))));
615
+ return Object.freeze(operations.map((op) => describe(exactOf(op, tolerance))));
440
616
  }
441
617
 
442
618
  /**
@@ -454,13 +630,15 @@ export function wyckoffPositions(key: PlaneGroupKey): readonly WyckoffPosition[]
454
630
  }
455
631
 
456
632
  /**
457
- * The site symmetry of a point (lattice basis) under a plane group: the operations that map it
458
- * onto itself modulo the lattice within the tolerance, closed into a group, and the point set onto
459
- * their fixed space. Throws a RangeError for an unknown key, a point that is not two finite
460
- * numbers, or a tolerance outside (0, 1/2).
633
+ * The site symmetry of a point (lattice basis) under a plane group, as one notion with its Wyckoff
634
+ * position (#137 F1): the point is set onto the position it lies on within the tolerance
635
+ * (`wyckoffPosition`), and the site symmetry is that of the point there; `point` is the point on the
636
+ * position. Throws a RangeError for an unknown key, a point that is not two finite numbers, or a
637
+ * tolerance outside (0, 1/2).
461
638
  */
462
- export function siteSymmetry(key: PlaneGroupKey, point: readonly number[], options?: PointOptions): SiteSymmetry {
463
- const site = planeSiteSymmetry(groupKey(key, 'siteSymmetry'), point, options);
639
+ export function siteSymmetry(key: PlaneGroupKey, point: readonly number[], options?: ToleranceOptions): SiteSymmetry {
640
+ checkOptions(options, TOLERANCE_KEYS, 'siteSymmetry');
641
+ const site = planeSiteOfPosition(groupKey(key, 'siteSymmetry'), point, options);
464
642
  return Object.freeze({
465
643
  operations: Object.freeze([...site.operations]),
466
644
  point: Object.freeze([...site.point]),
@@ -471,15 +649,18 @@ export function siteSymmetry(key: PlaneGroupKey, point: readonly number[], optio
471
649
 
472
650
  /**
473
651
  * The Wyckoff position of a point (lattice basis) under a plane group, as `wyckoffPositions` gives
474
- * it: the printed position of the point's multiplicity whose coordinates, with the centring, reach
475
- * the point set onto its site symmetry. Throws a RangeError as `siteSymmetry`.
652
+ * it: the most special printed position whose point set lies within the tolerance of the point,
653
+ * measured per coordinate modulo the lattice, and among positions of equal multiplicity the nearest
654
+ * (the distance of `wyckoffDistances`); the general position always holds the point. Throws a
655
+ * RangeError as `siteSymmetry`.
476
656
  */
477
- export function wyckoffPositionOf(
657
+ export function wyckoffPosition(
478
658
  key: PlaneGroupKey,
479
659
  point: readonly number[],
480
- options?: PointOptions,
660
+ options?: ToleranceOptions,
481
661
  ): WyckoffPosition {
482
- const k = groupKey(key, 'wyckoffPositionOf');
662
+ checkOptions(options, TOLERANCE_KEYS, 'wyckoffPosition');
663
+ const k = groupKey(key, 'wyckoffPosition');
483
664
  const { letter } = planeWyckoffPositionOf(k, point, options);
484
665
  const found = wyckoffPositions(k).find((w) => w.letter === letter);
485
666
  if (!found) throw new Error(`No Wyckoff position ${letter} in ${k}`);
@@ -487,76 +668,275 @@ export function wyckoffPositionOf(
487
668
  }
488
669
 
489
670
  /**
490
- * Snaps a point (lattice basis) onto the most special Wyckoff position of a plane group that lies
491
- * within the tolerance of it, measured per coordinate modulo the lattice: a position without a free
492
- * parameter (a point) before one with one (a line), before the general position, which always holds
493
- * the point; among positions of the same kind the nearest. Returns the position, as
494
- * `wyckoffPositions` gives it, and the nearest point on it, in [0, 1). Unlike `wyckoffPositionOf`,
495
- * which asks whether the images of the point lie within the tolerance of it, this asks whether the
496
- * point lies within the tolerance of the position: an application that drags a point and lets it
497
- * snap passes a tolerance such as 10⁻². The point on a line is found by least squares in the
498
- * lattice coordinates. Throws a RangeError as `siteSymmetry`.
671
+ * The distance of a point (lattice basis) to every Wyckoff position of a plane group, in the
672
+ * printed order of `wyckoffPositions`, each with the nearest point of the position (#137 F1, #108).
673
+ * The point set of a position is the union of its printed coordinates with every centring and
674
+ * lattice translation: a point, a line or the plane. Without a basis the distance is the larger of
675
+ * the two coordinate differences modulo the lattice, the metric of the tolerance of
676
+ * `wyckoffPosition`; with a basis (columns a, b) it is Euclidean, and the nearest point is the
677
+ * Euclidean nearest one; per coordinate the nearest point of a line need not be unique (on x,0 every x
678
+ * within the distance is as near), and then it is one of them. The basis should be a reduced cell,
679
+ * such as the conventional one: the nearest lattice translate is sought near the rounded
680
+ * coordinates. How to snap a dragged point onto a position (which position wins, within
681
+ * which radius) is the application's choice; this gives the numbers for it. Throws a RangeError for
682
+ * an unknown key, a point that is not two finite numbers, and a basis that is not a non-singular
683
+ * 2 × 2 matrix.
499
684
  */
500
- export function snapToWyckoffPosition(
685
+ export function wyckoffDistances(
501
686
  key: PlaneGroupKey,
502
687
  point: readonly number[],
503
- options?: PointOptions,
504
- ): SnappedPosition {
505
- const k = groupKey(key, 'snapToWyckoffPosition');
506
- if (!Array.isArray(point)) {
507
- throw new RangeError(`A point of the plane has two finite coordinates, not ${JSON.stringify(point)}`);
508
- }
509
- const snapped = planeSnapToWyckoffPosition(k, point, options?.tolerance);
510
- const position = wyckoffPositions(k)[snapped.row];
511
- return Object.freeze({ ...position, point: Object.freeze([...snapped.point]) });
688
+ options?: WyckoffDistanceOptions,
689
+ ): readonly WyckoffDistance[] {
690
+ checkOptions(options, ['basis'], 'wyckoffDistances');
691
+ const k = groupKey(key, 'wyckoffDistances');
692
+ const g = options?.basis === undefined ? undefined : planeMetric(options.basis);
693
+ const positions = wyckoffPositions(k);
694
+ return Object.freeze(
695
+ planeWyckoffDistances(k, point, g).map((d) =>
696
+ Object.freeze({ ...positions[d.row], point: Object.freeze([...d.point]), distance: d.distance }),
697
+ ),
698
+ );
699
+ }
700
+
701
+ /** One point of the orbit of a point. */
702
+ export interface PointOrbitEntry {
703
+ /** The image, in the lattice basis, in [0, 1). */
704
+ readonly point: readonly number[];
705
+ /** Indices into `operations` of the operations that map the given point here (modulo the lattice), ascending. */
706
+ readonly operations: readonly number[];
512
707
  }
513
708
 
514
709
  /**
515
- * The orbit of a point (lattice basis) under a plane group: its distinct images in the
516
- * conventional cell, each in [0, 1), in the order of the operations that first give them; images
517
- * that coincide within the tolerance are merged. Throws a RangeError as `siteSymmetry`.
710
+ * The orbit of a point (lattice basis) under a plane group: the images of the point set onto its
711
+ * Wyckoff position (as `siteSymmetry` sets it), each in [0, 1), in the order of the operations that
712
+ * first give them, each with the indices of the operations that map the point there (as the
713
+ * entries of the orbits of the point groups): one entry per coset of the site symmetry, so the
714
+ * first entry holds the operations of `siteSymmetry`. Throws a RangeError as `siteSymmetry`.
518
715
  */
519
716
  export function orbit(
520
717
  key: PlaneGroupKey,
521
718
  point: readonly number[],
522
- options?: PointOptions,
523
- ): readonly (readonly number[])[] {
524
- return Object.freeze(planeOrbit(groupKey(key, 'orbit'), point, options).map((p) => Object.freeze(p)));
719
+ options?: ToleranceOptions,
720
+ ): readonly PointOrbitEntry[] {
721
+ checkOptions(options, TOLERANCE_KEYS, 'orbit');
722
+ return Object.freeze(
723
+ planeOrbit(groupKey(key, 'orbit'), point, options).map((e) =>
724
+ Object.freeze({ point: Object.freeze(e.point), operations: Object.freeze(e.operations) }),
725
+ ),
726
+ );
525
727
  }
526
728
 
527
729
  /**
528
- * The asymmetric unit of a plane group as ITA prints it: a convex polygon given by its vertices and,
529
- * per edge, the printed inequality that holds it. Throws a RangeError for an unknown key.
730
+ * The asymmetric unit of a plane group as ITA prints it (#137 F3): the printed inequalities, all of
731
+ * them in printed order (a double inequality and a `min` give one each), and the convex polygon
732
+ * they bound, with its vertices and, per edge, the index of the inequality that holds it. Throws a
733
+ * RangeError for an unknown key.
530
734
  */
531
735
  export function asymmetricUnit(key: PlaneGroupKey): AsymmetricUnit {
532
736
  const unit = planeAsymmetricUnit(groupKey(key, 'asymmetricUnit'));
533
737
  return Object.freeze({
534
- vertices: Object.freeze(unit.vertices.map((v) => Object.freeze(numbers(v)))),
535
738
  inequalities: Object.freeze(unit.inequalities.map((q) => Object.freeze([...q]))),
739
+ vertices: Object.freeze(unit.vertices.map((v) => Object.freeze(numbers(v)))),
740
+ edges: Object.freeze([...unit.edges]),
536
741
  });
537
742
  }
538
743
 
539
744
  /**
540
- * The symmetry elements of a plane group in its conventional cell [0, 1]², boundary included:
541
- * every rotation centre with the highest order of a rotation about it, and every mirror and glide
542
- * line that crosses the cell, with the segment inside it. Throws a RangeError for an unknown key.
745
+ * The symmetry elements of a plane group (#137 F2). Without a box, each element once modulo the
746
+ * lattice translations, the centring (1/2, 1/2) included, as ITA describes them (cm: the mirror line
747
+ * 0,y and the glide line 1/4,y): every rotation point in [0, 1)² with the highest n of a rotation
748
+ * about it, and every mirror and glide line, as a point in [0, 1)² and a direction. With a box, all
749
+ * their lattice translates that meet it, boundary included; the lines are not clipped, since
750
+ * clipping is drawing. Throws a RangeError for an unknown key, a box that is not two corners of
751
+ * finite numbers, the first not above or right of the second, and a box with more than a million
752
+ * rotation points.
543
753
  */
544
- export function symmetryElements(key: PlaneGroupKey): SymmetryElements {
545
- const e = planeCellElements(groupKey(key, 'symmetryElements'));
754
+ export function symmetryElements(key: PlaneGroupKey, options?: SymmetryElementsOptions): SymmetryElements {
755
+ checkOptions(options, ['box'], 'symmetryElements');
756
+ const k = groupKey(key, 'symmetryElements');
757
+ const box = options?.box;
758
+ let e;
759
+ if (box === undefined) e = planeElements(k);
760
+ else {
761
+ const ok =
762
+ Array.isArray(box) &&
763
+ box.length === 2 &&
764
+ box.every(
765
+ (c) => Array.isArray(c) && c.length === 2 && c.every((v) => typeof v === 'number' && Number.isFinite(v)),
766
+ );
767
+ if (!ok || !(box[0][0] <= box[1][0] && box[0][1] <= box[1][1])) {
768
+ throw new RangeError(`A box is two corners [[x0, y0], [x1, y1]] with x0 <= x1 and y0 <= y1, not ${shown(box)}`);
769
+ }
770
+ e = planeElementsInBox(k, [
771
+ [box[0][0], box[0][1]],
772
+ [box[1][0], box[1][1]],
773
+ ]);
774
+ }
546
775
  return Object.freeze({
547
- rotations: Object.freeze(
548
- e.rotations.map((r) => Object.freeze({ order: r.order, point: Object.freeze(numbers(r.point)) })),
776
+ rotationPoints: Object.freeze(
777
+ e.rotationPoints.map((r) => Object.freeze({ n: r.n, point: Object.freeze(numbers(r.point)) })),
549
778
  ),
550
779
  lines: Object.freeze(
551
780
  e.lines.map((l) =>
552
781
  Object.freeze({
553
782
  kind: l.kind,
554
783
  direction: Object.freeze([...l.direction]),
555
- normal: Object.freeze([...l.normal]),
784
+ axis: Object.freeze([...l.axis]),
556
785
  glide: Object.freeze(numbers(l.glide)),
557
- segment: Object.freeze(l.segment.map((p) => Object.freeze(numbers(p)))),
786
+ point: Object.freeze(numbers(l.point)),
558
787
  }),
559
788
  ),
560
789
  ),
561
790
  });
562
791
  }
792
+
793
+ // --- lattices and cells (#119, #137 G5) ---------------------------------------------------------------
794
+
795
+ const PLANE_SYSTEMS = Object.keys(PLANE_FAMILIES) as PlaneSystem[];
796
+
797
+ const copy = (m: Mat2): Mat2 => [
798
+ [m[0][0], m[0][1]],
799
+ [m[1][0], m[1][1]],
800
+ ];
801
+
802
+ /**
803
+ * The restrictions on the cell parameters of a crystal system of the plane, as ITA 2016 Table
804
+ * 2.1.1.1 (p. 143) gives them for the conventional cell: the parameters to be determined, the pairs
805
+ * of equal parameters, the fixed angles, and the angles conventionally taken non-acute. Throws a
806
+ * RangeError for anything that is not one of the four crystal systems of the plane.
807
+ */
808
+ export function cellRestrictions(system: PlaneSystem): CellRestrictions {
809
+ if (!(PLANE_SYSTEMS as readonly unknown[]).includes(system)) {
810
+ throw new RangeError(`Unknown crystal system of the plane: ${shown(system)} (${PLANE_SYSTEMS.join(', ')})`);
811
+ }
812
+ const r = PLANE_FAMILIES[system].restrictions;
813
+ return deepFreeze({
814
+ parameters: [...r.parameters],
815
+ equal: r.equal.map((pair) => [...pair]),
816
+ angles: { ...r.angles },
817
+ nonAcute: [...r.nonAcute],
818
+ });
819
+ }
820
+
821
+ /**
822
+ * The Cartesian basis of a plane cell as the columns of a 2 × 2 matrix: a along x, b at γ from a
823
+ * towards +y (right-handed), in the unit of the edge lengths. Throws a RangeError for an edge that is
824
+ * not a positive number and for γ outside (0°, 180°).
825
+ */
826
+ export function latticeFromParameters(parameters: LatticeParameters): Mat2 {
827
+ return deepFreeze(copy(planeLatticeFromParameters(parameters, 'latticeFromParameters')));
828
+ }
829
+
830
+ /**
831
+ * The parameters a, b, γ of a basis given as the columns of a 2 × 2 Cartesian matrix, independent of
832
+ * its orientation and handedness. Throws a RangeError for a basis that is not a non-singular 2 × 2
833
+ * matrix.
834
+ */
835
+ export function latticeParameters(basis: Mat2): LatticeParameters {
836
+ return Object.freeze(planeLatticeParameters(basis, 'latticeParameters'));
837
+ }
838
+
839
+ /** The metric tensor G = AᵀA of a basis A (columns a, b): g_ij = a_i · a_j. Throws a RangeError for a basis that is not a non-singular 2 × 2 matrix. */
840
+ export function metricTensor(basis: Mat2): Mat2 {
841
+ return deepFreeze(copy(planeMetricTensor(basis, 'metricTensor')));
842
+ }
843
+
844
+ /**
845
+ * The reciprocal basis B = A⁻ᵀ of a basis A (columns a, b) as the columns a*, b*, with
846
+ * a_i · a*_j = δ_ij (no factor 2π). Throws a RangeError for a basis that is not a non-singular 2 × 2
847
+ * matrix.
848
+ */
849
+ export function reciprocalBasis(basis: Mat2): Mat2 {
850
+ return deepFreeze(copy(planeReciprocalBasis(basis, 'reciprocalBasis')));
851
+ }
852
+
853
+ // --- change of the coordinate system (#120, #137 G2) ---------------------------------------------------
854
+
855
+ /** A change of the coordinate system (P, p) of the plane (ITA 2016 § 1.5.1.3, p. 83): (a′, b′) = (a, b)·P, origin O′ = O + p. */
856
+ export interface CoordinateTransformation {
857
+ /** P, the linear part: its columns are the new basis vectors a′, b′ in the old basis; det P ≠ 0, also negative. */
858
+ readonly linearPart: Mat2;
859
+ /** p, the origin shift: the coordinates of the new origin in the old coordinate system; default zero. */
860
+ readonly originShift?: readonly number[];
861
+ }
862
+
863
+ /** An operation (W, w) in the lattice basis, x ↦ W·x + w; a record of `operations` passes as it is. */
864
+ export interface AffineOperation {
865
+ /** The linear part W, a 2 × 2 matrix with integer entries. */
866
+ readonly matrix: readonly (readonly number[])[];
867
+ /** The translation part w; default zero, as for the operations of a point group. */
868
+ readonly translation?: readonly number[];
869
+ }
870
+
871
+ /** An operation (W′, w′) in the new coordinate system. */
872
+ export interface TransformedOperation {
873
+ /** W′ = P⁻¹WP, integer entries. */
874
+ readonly matrix: Mat2;
875
+ /** w′ = P⁻¹(w + (W − I)p), not reduced modulo the lattice. */
876
+ readonly translation: readonly number[];
877
+ }
878
+
879
+ /** The quantities that `changeOfCoordinates` transforms; each is optional. */
880
+ export interface CoordinateQuantities {
881
+ /** Point coordinates x: x′ = P⁻¹(x − p) (eq. (1.5.1.7)). */
882
+ readonly points?: readonly (readonly number[])[];
883
+ /** Coefficients [uv] of vectors, e.g. directions: [uv]′ = P⁻¹[uv] (eq. (1.5.2.3)); not changed by the origin shift. */
884
+ readonly directions?: readonly (readonly number[])[];
885
+ /** Miller indices (hk) of lines: (hk)′ = (hk)P (eq. (1.5.2.2)); not changed by the origin shift. */
886
+ readonly planes?: readonly (readonly number[])[];
887
+ /** The metric tensor G: G′ = PᵀGP (eq. (1.5.2.4)). */
888
+ readonly metric?: Mat2;
889
+ /** Operations (W, w): W′ = P⁻¹WP, w′ = P⁻¹(w + (W − I)p) (eqs. (1.5.2.12), (1.5.2.13)). */
890
+ readonly operations?: readonly AffineOperation[];
891
+ }
892
+
893
+ /** The inverse change of the coordinate system (Q, q) = (P, p)⁻¹. */
894
+ export interface InverseTransformation {
895
+ /** Q = P⁻¹. */
896
+ readonly linearPart: Mat2;
897
+ /** q = −P⁻¹p. */
898
+ readonly originShift: readonly number[];
899
+ }
900
+
901
+ /** The result of `changeOfCoordinates`: the inverse pair and each given quantity in the new coordinate system. */
902
+ export interface CoordinateChange {
903
+ /** (Q, q) = (P⁻¹, −P⁻¹p), which takes the new coordinates back to the old (eq. (1.5.1.7)). */
904
+ readonly inverse: InverseTransformation;
905
+ /** The points, as given, in the new coordinates. */
906
+ readonly points?: readonly (readonly number[])[];
907
+ /** The vector coefficients, as given, in the new basis. */
908
+ readonly directions?: readonly (readonly number[])[];
909
+ /** The Miller indices, as given, in the new basis. */
910
+ readonly planes?: readonly (readonly number[])[];
911
+ /** The metric tensor in the new basis. */
912
+ readonly metric?: Mat2;
913
+ /** The operations, as given, in the new coordinate system. */
914
+ readonly operations?: readonly TransformedOperation[];
915
+ }
916
+
917
+ /**
918
+ * Changes the coordinate system of the plane by the pair (P, p) of ITA (6th ed., 2016) § 1.5.1.3
919
+ * (p. 83), with 2 × 2 matrices: the new basis is (a′, b′) = (a, b)·P and the new origin lies at p.
920
+ * Transforms the given quantities by ITA's equations (§ 1.5.2, pp. 83–85): point coordinates
921
+ * x′ = P⁻¹(x − p), vector coefficients [uv]′ = P⁻¹[uv], Miller indices (hk)′ = (hk)P, the metric
922
+ * tensor G′ = PᵀGP, and operations W′ = P⁻¹WP, w′ = P⁻¹(w + (W − I)p); and gives the inverse pair
923
+ * (Q, q) = (P⁻¹, −P⁻¹p). det P may be negative.
924
+ *
925
+ * P, p and the operations are read each number as the simplest fraction within the tolerance
926
+ * (default `EPSILON`; 0.3333333 is 1/3) and transformed exactly, so that every result, the inverse
927
+ * pair included, can be passed back; the other quantities are floating point. P is rational in a
928
+ * change between lattice bases, as in ITA; an irrational P (a rotation by 30°) is read as the
929
+ * nearby fractions, about as exact as the tolerance, and a much smaller tolerance can make the exact
930
+ * products leave the safe integers, a RangeError.
931
+ * A transformed operation is `{ matrix, translation }`. Throws a RangeError for a singular P, a quantity of the
932
+ * wrong shape, an unknown quantity, an operation with det W ≠ ±1, and one whose W′ is not integral.
933
+ */
934
+ export function changeOfCoordinates(
935
+ transformation: CoordinateTransformation,
936
+ quantities: CoordinateQuantities,
937
+ options?: ToleranceOptions,
938
+ ): CoordinateChange {
939
+ return deepFreeze(
940
+ changeCoordinates(2, transformation, quantities, options, 'changeOfCoordinates') as unknown as CoordinateChange,
941
+ );
942
+ }