symcrys 0.10.1 → 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.
- 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/crystalClasses.d.ts +145 -117
- package/dist/crystalClasses.d.ts.map +1 -1
- package/dist/crystalClasses.js +161 -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 +11 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/indices.d.ts +31 -5
- package/dist/indices.d.ts.map +1 -1
- package/dist/indices.js +104 -13
- 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 +12 -10
- package/dist/magnetic.d.ts.map +1 -1
- package/dist/magnetic.js +8 -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 +141 -79
- package/dist/plane.d.ts.map +1 -1
- package/dist/plane.js +147 -77
- 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 +135 -67
- package/dist/pointGroups/pointGroups.d.ts.map +1 -1
- package/dist/pointGroups/pointGroups.js +409 -244
- 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/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 +12 -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 +1 -1
- package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
- package/dist/spaceGroups/planeGroupData.js +8 -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/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/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/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/crystalClasses.ts +232 -157
- package/src/freeze.ts +14 -0
- package/src/index.ts +21 -10
- package/src/indices.ts +108 -18
- package/src/lattice.ts +41 -1
- package/src/linalg.ts +3 -3
- package/src/magnetic.ts +14 -9
- package/src/notation.ts +73 -0
- package/src/operations.ts +78 -71
- package/src/plane.ts +253 -127
- 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 +540 -297
- package/src/pointGroups/properties.ts +44 -40
- package/src/pointGroups/seitzData.ts +147 -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 +22 -19
- package/src/spaceGroups/planeGroupData.ts +9 -9
- package/src/spaceGroups/planeGroups.ts +2 -1
- package/src/spaceGroups/positions.ts +202 -78
- 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/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/siteSymmetry.ts
CHANGED
|
@@ -3,25 +3,16 @@
|
|
|
3
3
|
* fixed (docs/conventions.md, "Site symmetry and Wyckoff positions").
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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 `
|
|
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,33 +28,44 @@ 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: ${
|
|
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:
|
|
46
|
-
const w = apply(op.
|
|
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:
|
|
51
|
-
return op.
|
|
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
46
|
/**
|
|
55
47
|
* The products of a list of operations, looked up as needed: `i * n + j` → index of op[i]·op[j] in
|
|
56
|
-
* the list, or -1.
|
|
57
|
-
* (#
|
|
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).
|
|
58
53
|
*/
|
|
59
|
-
function productLookup(operations: readonly
|
|
54
|
+
function productLookup(operations: readonly CartesianOperation[], tolerance: number): (i: number, j: number) => number {
|
|
60
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;
|
|
61
58
|
return (i, j) => {
|
|
62
59
|
const key = i * operations.length + j;
|
|
63
60
|
let k = table.get(key);
|
|
64
61
|
if (k === undefined) {
|
|
65
|
-
const product = multiply(operations[i].
|
|
66
|
-
|
|
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
|
+
);
|
|
67
69
|
table.set(key, k);
|
|
68
70
|
}
|
|
69
71
|
return k;
|
|
@@ -89,11 +91,11 @@ function closeWithin(product: (i: number, j: number) => number, indices: readonl
|
|
|
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
|
|
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].
|
|
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?:
|
|
110
|
-
|
|
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.
|
|
123
|
-
* `
|
|
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
125
|
* direction or do not settle into a group (a tolerance far too large, e.g. 0.5).
|
|
126
126
|
*/
|
|
127
|
-
export function
|
|
128
|
-
operations: readonly
|
|
127
|
+
export function siteSymmetryOf(
|
|
128
|
+
operations: readonly CartesianOperation[],
|
|
129
129
|
direction: Vec3,
|
|
130
|
-
options?:
|
|
130
|
+
options?: ToleranceOptions,
|
|
131
131
|
): SiteSymmetry {
|
|
132
|
+
checkOptions(options, TOLERANCE_KEYS, 'siteSymmetryOf');
|
|
132
133
|
const tolerance = siteTolerance(options);
|
|
133
|
-
|
|
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,14 +146,14 @@ 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
|
-
const product = productLookup(operations);
|
|
149
|
+
const product = productLookup(operations, tolerance);
|
|
147
150
|
let set = closeWithin(product, fixing(v));
|
|
148
151
|
let settled: { indices: number[]; projected: Vec3 } | undefined;
|
|
149
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 ${
|
|
156
|
+
`No common fixed direction for the operations fixing ${shown(direction)} within ${tolerance} (tolerance too large?)`,
|
|
154
157
|
);
|
|
155
158
|
}
|
|
156
159
|
const next = closeWithin(product, fixing(mean));
|
|
@@ -161,7 +164,7 @@ export function siteSymmetry(
|
|
|
161
164
|
// Only for a tolerance far too large; the site symmetry would be neither closed nor its direction
|
|
162
165
|
// projected (#91).
|
|
163
166
|
throw new RangeError(
|
|
164
|
-
`The site symmetry of ${
|
|
167
|
+
`The site symmetry of ${shown(direction)} does not settle within ${tolerance} (tolerance too large?)`,
|
|
165
168
|
);
|
|
166
169
|
}
|
|
167
170
|
const { indices, projected } = settled;
|
|
@@ -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: ${
|
|
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: ${
|
|
122
|
+
throw new RangeError(`Determinant ${det} is not ±1: ${shown(op.matrix)}`);
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
|
package/src/spaceGroups/cell.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The asymmetric unit of a plane group and its symmetry elements
|
|
3
|
-
*
|
|
4
|
-
* the elements as rotation
|
|
5
|
-
*
|
|
6
|
-
* applications. Internal for now.
|
|
2
|
+
* The asymmetric unit of a plane group and its symmetry elements, as numbers (CLAUDE.md, "Elements
|
|
3
|
+
* and the asymmetric unit as data"): the asymmetric unit as its printed inequalities with the
|
|
4
|
+
* polygon they bound, the elements as rotation points with their n and as mirror and glide lines
|
|
5
|
+
* by a point and a direction, once modulo the lattice or all translates in a box. Exact, in the
|
|
6
|
+
* lattice basis; drawing them stays with the applications. Internal for now.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { shown } from '../checks.js';
|
|
9
10
|
import { type ExactOperation } from './affine.js';
|
|
10
11
|
import { describePlaneOperation } from './describe.js';
|
|
11
12
|
import { planeGroupEntry, planeGroupOperations } from './planeGroups.js';
|
|
@@ -28,44 +29,49 @@ import {
|
|
|
28
29
|
/** An inequality a·x + b·y ≤ c with integer coefficients without a common factor. */
|
|
29
30
|
export type Inequality = readonly [a: number, b: number, c: number];
|
|
30
31
|
|
|
31
|
-
/** The asymmetric unit of a plane group,
|
|
32
|
+
/** The asymmetric unit of a plane group: the printed inequalities, and the convex polygon they bound. */
|
|
32
33
|
export interface AsymmetricUnit {
|
|
33
|
-
/**
|
|
34
|
-
readonly vertices: readonly (readonly Rational[])[];
|
|
35
|
-
/** Its edges as inequalities: inequality i holds the edge from vertex i to vertex i + 1. */
|
|
34
|
+
/** The inequalities as printed, in printed order, also those that hold no edge (p3: x ≤ 2/3). */
|
|
36
35
|
readonly inequalities: readonly Inequality[];
|
|
36
|
+
/** The vertices of the polygon, counter-clockwise in the lattice basis (a towards b), starting at the vertex with the smallest y, then x. */
|
|
37
|
+
readonly vertices: readonly (readonly Rational[])[];
|
|
38
|
+
/** Per edge, from vertex i to vertex i + 1, the index into `inequalities` of the one that holds it. */
|
|
39
|
+
readonly edges: readonly number[];
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
/** A rotation
|
|
40
|
-
export interface
|
|
41
|
-
/** The highest
|
|
42
|
-
readonly
|
|
43
|
-
/** Its
|
|
42
|
+
/** A rotation point (ITA 2016 Table 2.1.2.1, p. 145: the symmetry element of a rotation in the plane). */
|
|
43
|
+
export interface RotationPoint {
|
|
44
|
+
/** The highest n of an n-fold rotation about it. */
|
|
45
|
+
readonly n: number;
|
|
46
|
+
/** Its location. */
|
|
44
47
|
readonly point: readonly Rational[];
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
/** A mirror or glide line,
|
|
50
|
+
/** A mirror or glide line, as a point and a direction. */
|
|
48
51
|
export interface SymmetryLine {
|
|
49
52
|
/** `'mirror'` or `'glide'`. */
|
|
50
53
|
readonly kind: 'mirror' | 'glide';
|
|
51
54
|
/** The direction of the line, the shortest integer vector, first non-zero component positive. */
|
|
52
55
|
readonly direction: readonly [number, number];
|
|
53
|
-
/** The normal of the line in the lattice basis, as `PlaneOperationDescription.
|
|
54
|
-
readonly
|
|
56
|
+
/** The normal of the line in the lattice basis, as `PlaneOperationDescription.axis`. */
|
|
57
|
+
readonly axis: readonly [number, number];
|
|
55
58
|
/** For a glide line: its glide vector s·direction with 0 < s < 1; for a mirror line (0, 0). */
|
|
56
59
|
readonly glide: readonly Rational[];
|
|
57
|
-
/**
|
|
58
|
-
readonly
|
|
60
|
+
/** A point of the line: its intersection with y = 0, or with x = 0 for a line along a. */
|
|
61
|
+
readonly point: readonly Rational[];
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
/**
|
|
64
|
+
/** Symmetry elements of a plane group. */
|
|
62
65
|
export interface CellElements {
|
|
63
|
-
/** The rotation
|
|
64
|
-
readonly
|
|
65
|
-
/** The mirror and glide lines
|
|
66
|
+
/** The rotation points, by descending n, then by y and x. */
|
|
67
|
+
readonly rotationPoints: readonly RotationPoint[];
|
|
68
|
+
/** The mirror and glide lines, by direction, then by their point (x on y = 0, or y on x = 0), then mirror before glide. */
|
|
66
69
|
readonly lines: readonly SymmetryLine[];
|
|
67
70
|
}
|
|
68
71
|
|
|
72
|
+
/** A box [x₀, y₀] – [x₁, y₁] of the plane, lattice basis, boundary included. */
|
|
73
|
+
export type Box = readonly [readonly [number, number], readonly [number, number]];
|
|
74
|
+
|
|
69
75
|
// ---------------------------------------------------------------------------------------------
|
|
70
76
|
// Asymmetric unit
|
|
71
77
|
|
|
@@ -215,9 +221,10 @@ const samePoint = (p: readonly Rational[], q: readonly Rational[]): boolean =>
|
|
|
215
221
|
const unitCache = new Map<string, AsymmetricUnit>();
|
|
216
222
|
|
|
217
223
|
/**
|
|
218
|
-
* The asymmetric unit of a plane group as ITA prints it
|
|
219
|
-
*
|
|
220
|
-
*
|
|
224
|
+
* The asymmetric unit of a plane group as ITA prints it (#137 F3): the printed inequalities
|
|
225
|
+
* a·x + b·y ≤ c, all of them in printed order (a double inequality and a `min` give one each), and
|
|
226
|
+
* the convex polygon they bound: its vertices and, per edge, the index of the inequality that holds
|
|
227
|
+
* it. Frozen.
|
|
221
228
|
*/
|
|
222
229
|
export function planeAsymmetricUnit(key: string | number): AsymmetricUnit {
|
|
223
230
|
const entry = planeGroupEntry(key);
|
|
@@ -225,15 +232,16 @@ export function planeAsymmetricUnit(key: string | number): AsymmetricUnit {
|
|
|
225
232
|
if (!unit) {
|
|
226
233
|
const printed = parseAsymmetricUnit(entry.asymmetricUnit);
|
|
227
234
|
const vertices = polygon(printed);
|
|
228
|
-
const
|
|
235
|
+
const edges = vertices.map((p, i) => {
|
|
229
236
|
const q = vertices[(i + 1) % vertices.length];
|
|
230
|
-
const edge = printed.
|
|
231
|
-
if (
|
|
232
|
-
return
|
|
237
|
+
const edge = printed.findIndex((e) => excess(e, p)[0] === 0 && excess(e, q)[0] === 0);
|
|
238
|
+
if (edge < 0) throw new Error(`No printed inequality of ${entry.symbol} holds an edge`);
|
|
239
|
+
return edge;
|
|
233
240
|
});
|
|
234
241
|
unit = Object.freeze({
|
|
242
|
+
inequalities: Object.freeze(printed.map((e) => Object.freeze(e))),
|
|
235
243
|
vertices: Object.freeze(vertices.map((v) => Object.freeze(v))),
|
|
236
|
-
|
|
244
|
+
edges: Object.freeze(edges),
|
|
237
245
|
});
|
|
238
246
|
unitCache.set(entry.symbol, unit);
|
|
239
247
|
}
|
|
@@ -241,74 +249,103 @@ export function planeAsymmetricUnit(key: string | number): AsymmetricUnit {
|
|
|
241
249
|
}
|
|
242
250
|
|
|
243
251
|
// ---------------------------------------------------------------------------------------------
|
|
244
|
-
// Symmetry elements
|
|
252
|
+
// Symmetry elements
|
|
245
253
|
|
|
246
254
|
const inCell = (p: readonly Rational[]): boolean => p.every((v) => v[0] >= 0 && v[0] <= v[1]);
|
|
247
255
|
|
|
248
256
|
/**
|
|
249
257
|
* The lattice shifts t, |t_i| ≤ 3, added to each coset representative (W, w), w in [0, 1). Enough to
|
|
250
|
-
* reach every element that meets the cell
|
|
251
|
-
* t = (I − W)p − w, and the entries of I − W (at most 2 on the
|
|
252
|
-
* (I − W)p in [−2, 3]; a line through p in the cell, taken with its glide
|
|
253
|
-
* g = d/2 (in a plane group s is 0 or 1/2, and |d_i| ≤ 2, so |g_i| ≤ 1), has
|
|
258
|
+
* reach every element that meets the cell [0, 1]², and so every element modulo the lattice: a centre
|
|
259
|
+
* p in [0, 1]² of (W, w + t) has t = (I − W)p − w, and the entries of I − W (at most 2 on the
|
|
260
|
+
* diagonal, 1 off it) give (I − W)p in [−2, 3]; a line through p in the cell, taken with its glide
|
|
261
|
+
* g along it reduced to g = d/2 (in a plane group s is 0 or 1/2, and |d_i| ≤ 2, so |g_i| ≤ 1), has
|
|
262
|
+
* t = (I − W)p + g − w, where for a reflection (I − W)p lies in [−1, 2].
|
|
254
263
|
*/
|
|
255
264
|
const SHIFTS: Rational[][] = [];
|
|
256
265
|
for (let i = -3; i <= 3; i++) for (let j = -3; j <= 3; j++) SHIFTS.push([r(i), r(j)]);
|
|
257
266
|
|
|
258
|
-
/**
|
|
259
|
-
* The segment of the line through p along d in [0, 1]², or undefined if it has no length there.
|
|
260
|
-
* Exact: the parameter λ of p + λd is bounded by each coordinate.
|
|
261
|
-
*/
|
|
262
|
-
function clip(
|
|
263
|
-
p: readonly Rational[],
|
|
264
|
-
d: readonly [number, number],
|
|
265
|
-
): [readonly Rational[], readonly Rational[]] | undefined {
|
|
266
|
-
let lo: Rational | undefined;
|
|
267
|
-
let hi: Rational | undefined;
|
|
268
|
-
for (let k = 0; k < 2; k++) {
|
|
269
|
-
if (d[k] === 0) {
|
|
270
|
-
if (p[k][0] < 0 || p[k][0] > p[k][1]) return undefined;
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
// 0 ≤ p_k + λ d_k ≤ 1
|
|
274
|
-
const a = rational(-p[k][0], p[k][1] * d[k]);
|
|
275
|
-
const b = rational(p[k][1] - p[k][0], p[k][1] * d[k]);
|
|
276
|
-
const [l, h] = d[k] > 0 ? [a, b] : [b, a];
|
|
277
|
-
if (lo === undefined || toNumber(subtract(l, lo)) > 0) lo = l;
|
|
278
|
-
if (hi === undefined || toNumber(subtract(h, hi)) < 0) hi = h;
|
|
279
|
-
}
|
|
280
|
-
if (lo === undefined || hi === undefined || toNumber(subtract(hi, lo)) <= 0) return undefined;
|
|
281
|
-
const at = (lambda: Rational) => [add(p[0], scale(d[0], lambda)), add(p[1], scale(d[1], lambda))];
|
|
282
|
-
return [at(lo), at(hi)];
|
|
283
|
-
}
|
|
284
|
-
|
|
285
267
|
/** s mod 1 in [0, 1). */
|
|
286
268
|
function frac(s: Rational): Rational {
|
|
287
269
|
const n = Math.floor(s[0] / s[1]);
|
|
288
270
|
return subtract(s, r(n));
|
|
289
271
|
}
|
|
290
272
|
|
|
291
|
-
|
|
273
|
+
/** A line: {x : (−d_y, d_x)·x = c} with its glide s·d; for a class, c as `classOffset` chooses it. */
|
|
274
|
+
interface LineClass {
|
|
275
|
+
kind: 'mirror' | 'glide';
|
|
276
|
+
direction: [number, number];
|
|
277
|
+
axis: readonly [number, number];
|
|
278
|
+
s: Rational;
|
|
279
|
+
c: Rational;
|
|
280
|
+
/** The step of c between the translates of the line (1, or 1/2 under a centring). */
|
|
281
|
+
step: Rational;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The point of the line (d, c) on y = 0, or on x = 0 for a line along a. */
|
|
285
|
+
function linePoint(d: readonly [number, number], c: Rational): Rational[] {
|
|
286
|
+
return d[1] !== 0 ? [rational(-c[0], c[1] * d[1]), ZERO] : [ZERO, rational(c[0], c[1] * d[0])];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** The coordinate of that point that is not 0: where the line crosses y = 0 (or x = 0). */
|
|
290
|
+
const lineParameter = (l: LineClass): number => {
|
|
291
|
+
const p = linePoint(l.direction, l.c);
|
|
292
|
+
return toNumber(l.direction[1] !== 0 ? p[0] : p[1]);
|
|
293
|
+
};
|
|
292
294
|
|
|
293
295
|
/**
|
|
294
|
-
* The
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
296
|
+
* The offset c of a line class, one for all its lattice translates: a lattice translation t changes c
|
|
297
|
+
* by (−d_y, d_x)·t, which for a primitive lattice is any integer and with the centring (1/2, 1/2) also
|
|
298
|
+
* (d_x − d_y)/2; so the class is c modulo `step` (1, or 1/2 where that is odd in a centred group). Of
|
|
299
|
+
* the translates the one is taken whose point on y = 0 (on x = 0 for a line along a) lies nearest to
|
|
300
|
+
* 0 from above.
|
|
298
301
|
*/
|
|
299
|
-
|
|
302
|
+
function classOffset(d: readonly [number, number], c: Rational, step: Rational): Rational {
|
|
303
|
+
const modulo = (v: Rational, m: Rational): Rational =>
|
|
304
|
+
subtract(v, scale(Math.floor(toNumber(v) / toNumber(m) + 1e-12), m));
|
|
305
|
+
const reduced = modulo(c, step);
|
|
306
|
+
if (d[1] === 0) return reduced; // the point is (0, c/d_x) with d_x = 1
|
|
307
|
+
// x = −c/d_y; c' = c − m·step moves x by m·step/d_y: take x in [0, step/|d_y|).
|
|
308
|
+
const x = rational(-reduced[0], reduced[1] * d[1]);
|
|
309
|
+
const shifted = modulo(x, rational(step[0], step[1] * Math.abs(d[1])));
|
|
310
|
+
return rational(-shifted[0] * d[1], shifted[1]);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** The centring translations of a plane group besides (0, 0), exact. */
|
|
314
|
+
function centrings(entry: { readonly centring: readonly string[] }): Rational[][] {
|
|
315
|
+
return entry.centring.map((t) => t.split(',').map((v) => parseRational(v.trim())));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** The step of c for a line along d under the lattice with these centrings: 1, or a fraction of it. */
|
|
319
|
+
function lineStep(d: readonly [number, number], taus: readonly Rational[][]): Rational {
|
|
320
|
+
let step = r(1);
|
|
321
|
+
for (const tau of taus) {
|
|
322
|
+
const shift = frac(add(scale(-d[1], tau[0]), scale(d[0], tau[1])));
|
|
323
|
+
if (shift[0] !== 0 && toNumber(shift) < toNumber(step)) step = shift;
|
|
324
|
+
}
|
|
325
|
+
return step;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Of the points p + τ (mod 1) of one class under the centrings, the lowest (y, then x). */
|
|
329
|
+
function classPoint(p: readonly Rational[], taus: readonly Rational[][]): Rational[] {
|
|
330
|
+
let best = [...p];
|
|
331
|
+
for (const tau of taus) {
|
|
332
|
+
const q = [frac(add(p[0], tau[0])), frac(add(p[1], tau[1]))];
|
|
333
|
+
const dy = toNumber(subtract(q[1], best[1]));
|
|
334
|
+
if (dy < 0 || (dy === 0 && toNumber(subtract(q[0], best[0])) < 0)) best = q;
|
|
335
|
+
}
|
|
336
|
+
return best;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const classCache = new Map<string, { rotations: { n: number; point: Rational[] }[]; lines: LineClass[] }>();
|
|
340
|
+
|
|
341
|
+
/** The elements of a plane group modulo the lattice: rotation points in [0, 1)², one translate of each line (`classOffset`). */
|
|
342
|
+
function elementClasses(key: string | number) {
|
|
300
343
|
const entry = planeGroupEntry(key);
|
|
301
|
-
const cached =
|
|
344
|
+
const cached = classCache.get(entry.symbol);
|
|
302
345
|
if (cached) return cached;
|
|
303
|
-
const rotations: {
|
|
304
|
-
const lines:
|
|
305
|
-
|
|
306
|
-
direction: [number, number];
|
|
307
|
-
normal: readonly [number, number];
|
|
308
|
-
s: Rational;
|
|
309
|
-
c: Rational;
|
|
310
|
-
segment: [readonly Rational[], readonly Rational[]];
|
|
311
|
-
}[] = [];
|
|
346
|
+
const rotations: { n: number; point: Rational[] }[] = [];
|
|
347
|
+
const lines: LineClass[] = [];
|
|
348
|
+
const taus = centrings(entry);
|
|
312
349
|
for (const op of planeGroupOperations(entry.symbol)) {
|
|
313
350
|
for (const t of SHIFTS) {
|
|
314
351
|
const shifted: ExactOperation = {
|
|
@@ -317,66 +354,140 @@ export function planeCellElements(key: string | number): CellElements {
|
|
|
317
354
|
};
|
|
318
355
|
const d = describePlaneOperation(shifted);
|
|
319
356
|
if (d.kind === 'rotation') {
|
|
320
|
-
const
|
|
321
|
-
if (!inCell(
|
|
357
|
+
const loc = d.location ?? [];
|
|
358
|
+
if (!inCell(loc)) continue;
|
|
359
|
+
const p = classPoint(loc.map(frac), taus);
|
|
322
360
|
const known = rotations.find((x) => samePoint(x.point, p));
|
|
323
|
-
if (!known) rotations.push({
|
|
324
|
-
else known.
|
|
325
|
-
} else if (d.kind === '
|
|
361
|
+
if (!known) rotations.push({ n: d.n, point: p });
|
|
362
|
+
else known.n = Math.max(known.n, d.n);
|
|
363
|
+
} else if (d.kind === 'reflection' || d.kind === 'glide-reflection') {
|
|
326
364
|
const dir = d.direction ?? [0, 0];
|
|
327
365
|
const p = d.location ?? [];
|
|
328
366
|
// The glide vector is s·dir; s modulo 1, since a lattice translation along the line changes nothing.
|
|
329
367
|
const g = d.glide ?? [ZERO, ZERO];
|
|
330
368
|
const s = frac(dir[0] !== 0 ? rational(g[0][0], g[0][1] * dir[0]) : rational(g[1][0], g[1][1] * dir[1]));
|
|
331
|
-
// The line is the set of x with (−dir_y, dir_x)·x = c.
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
369
|
+
// The line is the set of x with (−dir_y, dir_x)·x = c; the lattice shifts c by multiples of step.
|
|
370
|
+
const step = lineStep([dir[0], dir[1]], taus);
|
|
371
|
+
const c = classOffset([dir[0], dir[1]], add(scale(-dir[1], p[0]), scale(dir[0], p[1])), step);
|
|
372
|
+
const known = lines.some(
|
|
373
|
+
(l) =>
|
|
374
|
+
l.direction[0] === dir[0] && l.direction[1] === dir[1] && rationalsEqual(l.c, c) && rationalsEqual(l.s, s),
|
|
375
|
+
);
|
|
376
|
+
if (!known) {
|
|
377
|
+
lines.push({
|
|
378
|
+
kind: s[0] === 0 ? 'mirror' : 'glide',
|
|
379
|
+
direction: [dir[0], dir[1]],
|
|
380
|
+
axis: d.axis ?? [0, 0],
|
|
381
|
+
s,
|
|
382
|
+
c,
|
|
383
|
+
step,
|
|
384
|
+
});
|
|
343
385
|
}
|
|
344
|
-
const segment = clip(p, dir);
|
|
345
|
-
if (!segment) continue;
|
|
346
|
-
lines.push({
|
|
347
|
-
kind: s[0] === 0 ? 'mirror' : 'glide',
|
|
348
|
-
direction: [dir[0], dir[1]],
|
|
349
|
-
normal: d.normal ?? [0, 0],
|
|
350
|
-
s,
|
|
351
|
-
c,
|
|
352
|
-
segment,
|
|
353
|
-
});
|
|
354
386
|
}
|
|
355
387
|
}
|
|
356
388
|
}
|
|
357
|
-
const
|
|
358
|
-
|
|
389
|
+
const result = { rotations, lines };
|
|
390
|
+
classCache.set(entry.symbol, result);
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const num = (v: Rational) => toNumber(v);
|
|
395
|
+
|
|
396
|
+
/** The elements as frozen records, sorted. */
|
|
397
|
+
function freezeElements(rotations: { n: number; point: Rational[] }[], lines: LineClass[]): CellElements {
|
|
398
|
+
rotations.sort((a, b) => b.n - a.n || num(a.point[1]) - num(b.point[1]) || num(a.point[0]) - num(b.point[0]));
|
|
359
399
|
lines.sort(
|
|
360
400
|
(a, b) =>
|
|
361
401
|
a.direction[0] - b.direction[0] ||
|
|
362
402
|
a.direction[1] - b.direction[1] ||
|
|
363
|
-
|
|
364
|
-
num(a.
|
|
403
|
+
lineParameter(a) - lineParameter(b) ||
|
|
404
|
+
num(a.s) - num(b.s),
|
|
365
405
|
);
|
|
366
|
-
|
|
367
|
-
|
|
406
|
+
return Object.freeze({
|
|
407
|
+
rotationPoints: Object.freeze(rotations.map((x) => Object.freeze({ n: x.n, point: Object.freeze(x.point) }))),
|
|
368
408
|
lines: Object.freeze(
|
|
369
409
|
lines.map((l) =>
|
|
370
410
|
Object.freeze({
|
|
371
411
|
kind: l.kind,
|
|
372
|
-
direction: Object.freeze(l.direction) as readonly [number, number],
|
|
373
|
-
|
|
412
|
+
direction: Object.freeze([...l.direction]) as readonly [number, number],
|
|
413
|
+
axis: Object.freeze([...l.axis]) as readonly [number, number],
|
|
374
414
|
glide: Object.freeze([scale(l.direction[0], l.s), scale(l.direction[1], l.s)]),
|
|
375
|
-
|
|
415
|
+
point: Object.freeze(linePoint(l.direction, l.c)),
|
|
376
416
|
}),
|
|
377
417
|
),
|
|
378
418
|
),
|
|
379
419
|
});
|
|
380
|
-
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const elementCache = new Map<string, CellElements>();
|
|
423
|
+
|
|
424
|
+
/** The most rotation points a box may hold: a guard against a box far larger than any drawing. */
|
|
425
|
+
const MAX_ELEMENTS = 1_000_000;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The symmetry elements of a plane group, each once modulo the lattice translations (the centring
|
|
429
|
+
* included), as ITA
|
|
430
|
+
* describes them (#137 F2): every rotation point in [0, 1)² with the highest n of a rotation about
|
|
431
|
+
* it, and every mirror and glide line, as a point and a direction. A line that carries a glide is a
|
|
432
|
+
* glide line with its shortest glide vector along the line (between 0 and the lattice vector). Frozen.
|
|
433
|
+
*/
|
|
434
|
+
export function planeElements(key: string | number): CellElements {
|
|
435
|
+
const entry = planeGroupEntry(key);
|
|
436
|
+
let result = elementCache.get(entry.symbol);
|
|
437
|
+
if (!result) {
|
|
438
|
+
const { rotations, lines } = elementClasses(entry.symbol);
|
|
439
|
+
result = freezeElements(
|
|
440
|
+
rotations.map((x) => ({ n: x.n, point: [...x.point] })),
|
|
441
|
+
lines.map((l) => ({ ...l })),
|
|
442
|
+
);
|
|
443
|
+
elementCache.set(entry.symbol, result);
|
|
444
|
+
}
|
|
381
445
|
return result;
|
|
382
446
|
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* The symmetry elements of a plane group with all their lattice translates that meet a box
|
|
450
|
+
* (boundary included): the rotation points inside it, and the lines that cross or touch it, as a
|
|
451
|
+
* point and a direction (not clipped). Frozen.
|
|
452
|
+
*/
|
|
453
|
+
export function planeElementsInBox(key: string | number, box: Box): CellElements {
|
|
454
|
+
const [[x0, y0], [x1, y1]] = box;
|
|
455
|
+
const entry = planeGroupEntry(key);
|
|
456
|
+
const { rotations, lines } = elementClasses(entry.symbol);
|
|
457
|
+
const taus = [[ZERO, ZERO], ...centrings(entry)];
|
|
458
|
+
// A bound on the output (#121 step 10b review): the rotation points of a class in the box.
|
|
459
|
+
const estimate = rotations.length * taus.length * (x1 - x0 + 2) * (y1 - y0 + 2);
|
|
460
|
+
if (!(estimate <= MAX_ELEMENTS)) {
|
|
461
|
+
throw new RangeError(
|
|
462
|
+
`The box ${shown(box)} holds about ${Math.round(estimate)} rotation points, more than ${MAX_ELEMENTS}`,
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
const inside: { n: number; point: Rational[] }[] = [];
|
|
466
|
+
for (const { n, point } of rotations) {
|
|
467
|
+
for (const tau of taus) {
|
|
468
|
+
const base = [add(point[0], tau[0]), add(point[1], tau[1])];
|
|
469
|
+
const [px, py] = base.map(num);
|
|
470
|
+
for (let i = Math.ceil(x0 - px - 1e-12); i <= Math.floor(x1 - px + 1e-12); i++) {
|
|
471
|
+
for (let j = Math.ceil(y0 - py - 1e-12); j <= Math.floor(y1 - py + 1e-12); j++) {
|
|
472
|
+
const p = [add(base[0], r(i)), add(base[1], r(j))];
|
|
473
|
+
const [qx, qy] = p.map(num);
|
|
474
|
+
if (qx >= x0 - 1e-12 && qx <= x1 + 1e-12 && qy >= y0 - 1e-12 && qy <= y1 + 1e-12)
|
|
475
|
+
inside.push({ n, point: p });
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const crossing: LineClass[] = [];
|
|
481
|
+
for (const l of lines) {
|
|
482
|
+
// (−d_y, d_x)·x over the corners of the box: the translate c + k·step meets it if that lies within.
|
|
483
|
+
const values = [x0, x1].flatMap((x) => [y0, y1].map((y) => -l.direction[1] * x + l.direction[0] * y));
|
|
484
|
+
const lo = Math.min(...values);
|
|
485
|
+
const hi = Math.max(...values);
|
|
486
|
+
const c = num(l.c);
|
|
487
|
+
const step = num(l.step);
|
|
488
|
+
for (let k = Math.ceil((lo - c) / step - 1e-12); k <= Math.floor((hi - c) / step + 1e-12); k++) {
|
|
489
|
+
crossing.push({ ...l, c: add(l.c, scale(k, l.step)) });
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return freezeElements(inside, crossing);
|
|
493
|
+
}
|