react-cheminfo 0.135.0 → 0.137.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 +1 -1
- package/lib/crystal/core/cellAtoms.d.ts +43 -0
- package/lib/crystal/core/cellAtoms.d.ts.map +1 -0
- package/lib/crystal/core/cellAtoms.js +70 -0
- package/lib/crystal/core/cellAtoms.js.map +1 -0
- package/lib/crystal/core/index.d.ts +2 -0
- package/lib/crystal/core/index.d.ts.map +1 -1
- package/lib/crystal/core/index.js +1 -0
- package/lib/crystal/core/index.js.map +1 -1
- package/lib/crystal/core/molecules.d.ts.map +1 -1
- package/lib/crystal/core/molecules.js +6 -40
- package/lib/crystal/core/molecules.js.map +1 -1
- package/lib/crystal3d/core/cellClip.d.ts +46 -0
- package/lib/crystal3d/core/cellClip.d.ts.map +1 -0
- package/lib/crystal3d/core/cellClip.js +198 -0
- package/lib/crystal3d/core/cellClip.js.map +1 -0
- package/lib/crystal3d/core/cellGeometry.d.ts +63 -0
- package/lib/crystal3d/core/cellGeometry.d.ts.map +1 -0
- package/lib/crystal3d/core/cellGeometry.js +153 -0
- package/lib/crystal3d/core/cellGeometry.js.map +1 -0
- package/lib/crystal3d/core/cellStack.d.ts +51 -0
- package/lib/crystal3d/core/cellStack.d.ts.map +1 -0
- package/lib/crystal3d/core/cellStack.js +79 -0
- package/lib/crystal3d/core/cellStack.js.map +1 -0
- package/lib/crystal3d/core/crystalView.d.ts +81 -0
- package/lib/crystal3d/core/crystalView.d.ts.map +1 -0
- package/lib/crystal3d/core/crystalView.js +55 -0
- package/lib/crystal3d/core/crystalView.js.map +1 -0
- package/lib/crystal3d/core/drawingSet.d.ts +31 -0
- package/lib/crystal3d/core/drawingSet.d.ts.map +1 -0
- package/lib/crystal3d/core/drawingSet.js +63 -0
- package/lib/crystal3d/core/drawingSet.js.map +1 -0
- package/lib/crystal3d/core/elementDrawing.d.ts +50 -0
- package/lib/crystal3d/core/elementDrawing.d.ts.map +1 -0
- package/lib/crystal3d/core/elementDrawing.js +100 -0
- package/lib/crystal3d/core/elementDrawing.js.map +1 -0
- package/lib/crystal3d/core/elementExtent.d.ts +42 -0
- package/lib/crystal3d/core/elementExtent.d.ts.map +1 -0
- package/lib/crystal3d/core/elementExtent.js +56 -0
- package/lib/crystal3d/core/elementExtent.js.map +1 -0
- package/lib/crystal3d/core/elementLabels.d.ts +31 -0
- package/lib/crystal3d/core/elementLabels.d.ts.map +1 -0
- package/lib/crystal3d/core/elementLabels.js +99 -0
- package/lib/crystal3d/core/elementLabels.js.map +1 -0
- package/lib/crystal3d/core/elementShapes.d.ts +43 -0
- package/lib/crystal3d/core/elementShapes.d.ts.map +1 -0
- package/lib/crystal3d/core/elementShapes.js +115 -0
- package/lib/crystal3d/core/elementShapes.js.map +1 -0
- package/lib/crystal3d/core/frame.d.ts +36 -0
- package/lib/crystal3d/core/frame.d.ts.map +1 -0
- package/lib/crystal3d/core/frame.js +35 -0
- package/lib/crystal3d/core/frame.js.map +1 -0
- package/lib/crystal3d/core/framing.d.ts +41 -0
- package/lib/crystal3d/core/framing.d.ts.map +1 -0
- package/lib/crystal3d/core/framing.js +79 -0
- package/lib/crystal3d/core/framing.js.map +1 -0
- package/lib/crystal3d/core/index.d.ts +42 -0
- package/lib/crystal3d/core/index.d.ts.map +1 -0
- package/lib/crystal3d/core/index.js +29 -0
- package/lib/crystal3d/core/index.js.map +1 -0
- package/lib/crystal3d/core/labelText.d.ts +19 -0
- package/lib/crystal3d/core/labelText.d.ts.map +1 -0
- package/lib/crystal3d/core/labelText.js +42 -0
- package/lib/crystal3d/core/labelText.js.map +1 -0
- package/lib/crystal3d/core/latticeBasis.d.ts +49 -0
- package/lib/crystal3d/core/latticeBasis.d.ts.map +1 -0
- package/lib/crystal3d/core/latticeBasis.js +89 -0
- package/lib/crystal3d/core/latticeBasis.js.map +1 -0
- package/lib/crystal3d/core/mat3.d.ts +68 -0
- package/lib/crystal3d/core/mat3.d.ts.map +1 -0
- package/lib/crystal3d/core/mat3.js +146 -0
- package/lib/crystal3d/core/mat3.js.map +1 -0
- package/lib/crystal3d/core/operationMatrix.d.ts +44 -0
- package/lib/crystal3d/core/operationMatrix.d.ts.map +1 -0
- package/lib/crystal3d/core/operationMatrix.js +172 -0
- package/lib/crystal3d/core/operationMatrix.js.map +1 -0
- package/lib/crystal3d/core/orientation.d.ts +62 -0
- package/lib/crystal3d/core/orientation.d.ts.map +1 -0
- package/lib/crystal3d/core/orientation.js +166 -0
- package/lib/crystal3d/core/orientation.js.map +1 -0
- package/lib/crystal3d/core/palette.d.ts +24 -0
- package/lib/crystal3d/core/palette.d.ts.map +1 -0
- package/lib/crystal3d/core/palette.js +34 -0
- package/lib/crystal3d/core/palette.js.map +1 -0
- package/lib/crystal3d/core/primitives.d.ts +133 -0
- package/lib/crystal3d/core/primitives.d.ts.map +1 -0
- package/lib/crystal3d/core/primitives.js +80 -0
- package/lib/crystal3d/core/primitives.js.map +1 -0
- package/lib/crystal3d/core/structureText.d.ts +20 -0
- package/lib/crystal3d/core/structureText.d.ts.map +1 -0
- package/lib/crystal3d/core/structureText.js +37 -0
- package/lib/crystal3d/core/structureText.js.map +1 -0
- package/lib/crystal3d/core/supercell.d.ts +20 -0
- package/lib/crystal3d/core/supercell.d.ts.map +1 -0
- package/lib/crystal3d/core/supercell.js +35 -0
- package/lib/crystal3d/core/supercell.js.map +1 -0
- package/lib/crystal3d/core/types.d.ts +166 -0
- package/lib/crystal3d/core/types.d.ts.map +1 -0
- package/lib/crystal3d/core/types.js +10 -0
- package/lib/crystal3d/core/types.js.map +1 -0
- package/lib/crystal3d/core/vec3.d.ts +75 -0
- package/lib/crystal3d/core/vec3.d.ts.map +1 -0
- package/lib/crystal3d/core/vec3.js +119 -0
- package/lib/crystal3d/core/vec3.js.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +52 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js +250 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts +17 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.js +79 -0
- package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts +22 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js +29 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts +29 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.js +24 -0
- package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts +72 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js +70 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js.map +1 -0
- package/lib/crystal3d/ui/crystalScene.d.ts +97 -0
- package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalScene.js +10 -0
- package/lib/crystal3d/ui/crystalScene.js.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +52 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js +2 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js.map +1 -0
- package/lib/crystal3d/ui/index.d.ts +16 -0
- package/lib/crystal3d/ui/index.d.ts.map +1 -0
- package/lib/crystal3d/ui/index.js +12 -0
- package/lib/crystal3d/ui/index.js.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts +14 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.js +32 -0
- package/lib/crystal3d/ui/useCrystalCaption.js.map +1 -0
- package/lib/crystal3d/viewer/animate.d.ts +49 -0
- package/lib/crystal3d/viewer/animate.d.ts.map +1 -0
- package/lib/crystal3d/viewer/animate.js +83 -0
- package/lib/crystal3d/viewer/animate.js.map +1 -0
- package/lib/crystal3d/viewer/camera.d.ts +44 -0
- package/lib/crystal3d/viewer/camera.d.ts.map +1 -0
- package/lib/crystal3d/viewer/camera.js +103 -0
- package/lib/crystal3d/viewer/camera.js.map +1 -0
- package/lib/crystal3d/viewer/index.d.ts +13 -0
- package/lib/crystal3d/viewer/index.d.ts.map +1 -0
- package/lib/crystal3d/viewer/index.js +8 -0
- package/lib/crystal3d/viewer/index.js.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts +24 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.js +39 -0
- package/lib/crystal3d/viewer/layerRegistry.js.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts +13 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.js +76 -0
- package/lib/crystal3d/viewer/meshPrimitives.js.map +1 -0
- package/lib/crystal3d/viewer/plugin.d.ts +133 -0
- package/lib/crystal3d/viewer/plugin.d.ts.map +1 -0
- package/lib/crystal3d/viewer/plugin.js +181 -0
- package/lib/crystal3d/viewer/plugin.js.map +1 -0
- package/lib/crystal3d/viewer/renderCell.d.ts +43 -0
- package/lib/crystal3d/viewer/renderCell.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderCell.js +53 -0
- package/lib/crystal3d/viewer/renderCell.js.map +1 -0
- package/lib/crystal3d/viewer/renderElements.d.ts +54 -0
- package/lib/crystal3d/viewer/renderElements.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderElements.js +77 -0
- package/lib/crystal3d/viewer/renderElements.js.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts +80 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.js +143 -0
- package/lib/crystal3d/viewer/renderStructure.js.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts +32 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.js +77 -0
- package/lib/crystal3d/viewer/sceneParts.js.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts +41 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.js +57 -0
- package/lib/crystal3d/viewer/shapeLayer.js.map +1 -0
- package/lib/crystal3d/viewer/textLayer.d.ts +21 -0
- package/lib/crystal3d/viewer/textLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/textLayer.js +59 -0
- package/lib/crystal3d/viewer/textLayer.js.map +1 -0
- package/lib/crystal3d/viewer/viewer.d.ts +119 -0
- package/lib/crystal3d/viewer/viewer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/viewer.js +172 -0
- package/lib/crystal3d/viewer/viewer.js.map +1 -0
- package/lib/crystal3d.d.ts +12 -0
- package/lib/crystal3d.d.ts.map +1 -0
- package/lib/crystal3d.js +12 -0
- package/lib/crystal3d.js.map +1 -0
- package/lib/download/core/croppedMarkup.d.ts.map +1 -1
- package/lib/download/core/croppedMarkup.js +16 -40
- package/lib/download/core/croppedMarkup.js.map +1 -1
- package/lib/download/core/dataUrl.d.ts +27 -0
- package/lib/download/core/dataUrl.d.ts.map +1 -0
- package/lib/download/core/dataUrl.js +54 -0
- package/lib/download/core/dataUrl.js.map +1 -0
- package/lib/download/core/index.d.ts +3 -0
- package/lib/download/core/index.d.ts.map +1 -1
- package/lib/download/core/index.js +2 -0
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/core/svgMarkup.d.ts +39 -0
- package/lib/download/core/svgMarkup.d.ts.map +1 -0
- package/lib/download/core/svgMarkup.js +100 -0
- package/lib/download/core/svgMarkup.js.map +1 -0
- package/lib/drawing/ui/movingFigure.d.ts.map +1 -1
- package/lib/drawing/ui/movingFigure.js +4 -30
- package/lib/drawing/ui/movingFigure.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +26 -1
- package/lib/locales/en.json +26 -1
- package/lib/locales/es.json +26 -1
- package/lib/locales/fr.json +26 -1
- package/lib/locales/it.json +26 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.js +16 -27
- package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
- package/lib/molstar/bonds/bondRule.d.ts +16 -0
- package/lib/molstar/bonds/bondRule.d.ts.map +1 -0
- package/lib/molstar/bonds/bondRule.js +23 -0
- package/lib/molstar/bonds/bondRule.js.map +1 -0
- package/lib/molstar/bonds/index.d.ts +9 -0
- package/lib/molstar/bonds/index.d.ts.map +1 -0
- package/lib/molstar/bonds/index.js +9 -0
- package/lib/molstar/bonds/index.js.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts +47 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.js +28 -0
- package/lib/molstar/ui/MolstarToolbar.js.map +1 -0
- package/lib/molstar/ui/index.d.ts +10 -0
- package/lib/molstar/ui/index.d.ts.map +1 -0
- package/lib/molstar/ui/index.js +8 -0
- package/lib/molstar/ui/index.js.map +1 -0
- package/lib/molstar/ui/useMolstarTools.d.ts +63 -0
- package/lib/molstar/ui/useMolstarTools.d.ts.map +1 -0
- package/lib/molstar/ui/useMolstarTools.js +36 -0
- package/lib/molstar/ui/useMolstarTools.js.map +1 -0
- package/package.json +2 -1
- package/src/crystal/core/cellAtoms.ts +106 -0
- package/src/crystal/core/index.ts +2 -0
- package/src/crystal/core/molecules.ts +7 -44
- package/src/crystal3d/core/cellClip.ts +229 -0
- package/src/crystal3d/core/cellGeometry.ts +193 -0
- package/src/crystal3d/core/cellStack.ts +87 -0
- package/src/crystal3d/core/crystalView.ts +131 -0
- package/src/crystal3d/core/drawingSet.ts +71 -0
- package/src/crystal3d/core/elementDrawing.ts +147 -0
- package/src/crystal3d/core/elementExtent.ts +81 -0
- package/src/crystal3d/core/elementLabels.ts +130 -0
- package/src/crystal3d/core/elementShapes.ts +141 -0
- package/src/crystal3d/core/frame.ts +56 -0
- package/src/crystal3d/core/framing.ts +101 -0
- package/src/crystal3d/core/index.ts +134 -0
- package/src/crystal3d/core/labelText.ts +44 -0
- package/src/crystal3d/core/latticeBasis.ts +110 -0
- package/src/crystal3d/core/mat3.ts +163 -0
- package/src/crystal3d/core/operationMatrix.ts +255 -0
- package/src/crystal3d/core/orientation.ts +229 -0
- package/src/crystal3d/core/palette.ts +43 -0
- package/src/crystal3d/core/primitives.ts +183 -0
- package/src/crystal3d/core/structureText.ts +43 -0
- package/src/crystal3d/core/supercell.ts +40 -0
- package/src/crystal3d/core/types.ts +186 -0
- package/src/crystal3d/core/vec3.ts +127 -0
- package/src/crystal3d/ui/CrystalCanvas3D.tsx +393 -0
- package/src/crystal3d/ui/CrystalStructureView.tsx +153 -0
- package/src/crystal3d/ui/CrystalStructureViewer.tsx +39 -0
- package/src/crystal3d/ui/CrystalViewControls.tsx +129 -0
- package/src/crystal3d/ui/CrystalViewer3D.tsx +183 -0
- package/src/crystal3d/ui/crystalScene.ts +106 -0
- package/src/crystal3d/ui/crystalStructureViewerProps.ts +54 -0
- package/src/crystal3d/ui/index.ts +20 -0
- package/src/crystal3d/ui/useCrystalCaption.ts +38 -0
- package/src/crystal3d/viewer/animate.ts +113 -0
- package/src/crystal3d/viewer/camera.ts +139 -0
- package/src/crystal3d/viewer/index.ts +13 -0
- package/src/crystal3d/viewer/layerRegistry.ts +47 -0
- package/src/crystal3d/viewer/meshPrimitives.ts +102 -0
- package/src/crystal3d/viewer/plugin.ts +258 -0
- package/src/crystal3d/viewer/renderCell.ts +98 -0
- package/src/crystal3d/viewer/renderElements.ts +121 -0
- package/src/crystal3d/viewer/renderStructure.ts +209 -0
- package/src/crystal3d/viewer/sceneParts.ts +119 -0
- package/src/crystal3d/viewer/shapeLayer.ts +108 -0
- package/src/crystal3d/viewer/textLayer.ts +85 -0
- package/src/crystal3d/viewer/viewer.ts +223 -0
- package/src/crystal3d.ts +12 -0
- package/src/download/core/croppedMarkup.ts +16 -42
- package/src/download/core/dataUrl.ts +59 -0
- package/src/download/core/index.ts +3 -0
- package/src/download/core/svgMarkup.ts +113 -0
- package/src/drawing/ui/movingFigure.ts +4 -28
- package/src/locales/de.json +26 -1
- package/src/locales/en.json +26 -1
- package/src/locales/es.json +26 -1
- package/src/locales/fr.json +26 -1
- package/src/locales/it.json +26 -1
- package/src/molecule3d/ui/MoleculeCanvas3D.tsx +45 -71
- package/src/molstar/bonds/bondRule.ts +34 -0
- package/src/molstar/bonds/index.ts +9 -0
- package/src/molstar/ui/MolstarToolbar.tsx +103 -0
- package/src/molstar/ui/index.ts +14 -0
- package/src/molstar/ui/useMolstarTools.ts +98 -0
- package/styles/chrome.css +90 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a crystal view draws, from the atoms of one cell: its molecules whole
|
|
3
|
+
* or the atoms the cell walls cut, repeated over as many cells as fit.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { packMolecules } from '../../crystal/core/packing.ts';
|
|
7
|
+
import type {
|
|
8
|
+
BondLimit,
|
|
9
|
+
PackedAtom,
|
|
10
|
+
} from '../../crystal/core/periodicBonds.ts';
|
|
11
|
+
import type { Lattice } from '../../crystal/core/symmetry/lattice.ts';
|
|
12
|
+
import { fractionalToCartesian } from '../../crystal/core/symmetry/lattice.ts';
|
|
13
|
+
|
|
14
|
+
import { largestRepeatThatFits } from './cellStack.ts';
|
|
15
|
+
import { supercellAtoms } from './supercell.ts';
|
|
16
|
+
import type { ViewerAtom } from './types.ts';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How the cell is drawn: each molecule whole, in the cell its centre falls in,
|
|
20
|
+
* or every atom inside the cell, cut where its walls cut it.
|
|
21
|
+
*/
|
|
22
|
+
export type CrystalPacking = 'molecules' | 'cell';
|
|
23
|
+
|
|
24
|
+
/** Every packing, in the order a control offers them. */
|
|
25
|
+
export const CRYSTAL_PACKINGS: readonly CrystalPacking[] = [
|
|
26
|
+
'molecules',
|
|
27
|
+
'cell',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Which bonds are drawn: every one, all but those to a metal atom (molstar
|
|
32
|
+
* draws those dashed, and a coordination network of them hides the rest), or
|
|
33
|
+
* none.
|
|
34
|
+
*/
|
|
35
|
+
export type CrystalBonds = 'all' | 'noMetal' | 'none';
|
|
36
|
+
|
|
37
|
+
/** Every choice of bonds, in the order a control offers them. */
|
|
38
|
+
export const CRYSTAL_BONDS: readonly CrystalBonds[] = [
|
|
39
|
+
'all',
|
|
40
|
+
'noMetal',
|
|
41
|
+
'none',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/** The cells along each axis a control offers, and a link may ask for. */
|
|
45
|
+
export const CELL_COUNT_RANGE = { minimum: 1, maximum: 4 } as const;
|
|
46
|
+
|
|
47
|
+
/** Options of {@link crystalView}. */
|
|
48
|
+
export interface CrystalViewOptions {
|
|
49
|
+
/**
|
|
50
|
+
* How the cell is drawn.
|
|
51
|
+
* @default 'molecules'
|
|
52
|
+
*/
|
|
53
|
+
packing?: CrystalPacking;
|
|
54
|
+
/**
|
|
55
|
+
* Cells along each axis asked for; fewer are drawn when they would hold too
|
|
56
|
+
* many atoms.
|
|
57
|
+
* @default 1
|
|
58
|
+
*/
|
|
59
|
+
cells?: number;
|
|
60
|
+
/**
|
|
61
|
+
* When two atoms are bonded, which is what completes a molecule. Pass the
|
|
62
|
+
* rule the viewer draws bonds with, so what is completed is what is joined.
|
|
63
|
+
*/
|
|
64
|
+
bondLimit: BondLimit;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What {@link crystalView} found. */
|
|
68
|
+
export interface CrystalView {
|
|
69
|
+
/** The atoms to draw, Cartesian ångström, repeated over the cells. */
|
|
70
|
+
readonly atoms: ViewerAtom[];
|
|
71
|
+
/** Cells drawn along each axis: what was asked, or fewer. */
|
|
72
|
+
readonly cells: number;
|
|
73
|
+
/** Atoms in one cell, as drawn. */
|
|
74
|
+
readonly atomsPerCell: number;
|
|
75
|
+
/** Molecules in one cell, 0 when the cell is drawn as it is cut. */
|
|
76
|
+
readonly molecules: number;
|
|
77
|
+
/** Whether some atoms belong to a network running through the crystal. */
|
|
78
|
+
readonly extended: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The atoms a crystal view draws.
|
|
83
|
+
* @param cellAtoms - Every atom of one cell, fractional, wrapped into [0, 1).
|
|
84
|
+
* @param lattice - The cell they sit in.
|
|
85
|
+
* @param options - See {@link CrystalViewOptions}.
|
|
86
|
+
* @returns The atoms and what they hold.
|
|
87
|
+
*/
|
|
88
|
+
export function crystalView(
|
|
89
|
+
cellAtoms: readonly PackedAtom[],
|
|
90
|
+
lattice: Lattice,
|
|
91
|
+
options: CrystalViewOptions,
|
|
92
|
+
): CrystalView {
|
|
93
|
+
const { packing = 'molecules', cells: asked = 1, bondLimit } = options;
|
|
94
|
+
const packed =
|
|
95
|
+
packing === 'molecules'
|
|
96
|
+
? packMolecules(cellAtoms, lattice, bondLimit)
|
|
97
|
+
: { atoms: cellAtoms, molecules: 0, extended: false };
|
|
98
|
+
const cells = largestRepeatThatFits(packed.atoms.length, asked);
|
|
99
|
+
const oneCell: ViewerAtom[] = [];
|
|
100
|
+
for (const atom of packed.atoms) {
|
|
101
|
+
const [x = 0, y = 0, z = 0] = fractionalToCartesian(lattice, atom.position);
|
|
102
|
+
oneCell.push({ element: atom.element, position: [x, y, z] });
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
atoms: supercellAtoms(oneCell, lattice.cell, [cells, cells, cells]),
|
|
106
|
+
cells,
|
|
107
|
+
atomsPerCell: packed.atoms.length,
|
|
108
|
+
molecules: packed.molecules,
|
|
109
|
+
extended: packed.extended,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** How a crystal view is set: what a control changes and a link may carry. */
|
|
114
|
+
export interface CrystalViewSettings {
|
|
115
|
+
/** How the cell is drawn. */
|
|
116
|
+
readonly packing: CrystalPacking;
|
|
117
|
+
/** Cells along each axis. */
|
|
118
|
+
readonly cells: number;
|
|
119
|
+
/** Whether the box of the unit cell is drawn. */
|
|
120
|
+
readonly unitCell: boolean;
|
|
121
|
+
/** Which bonds are drawn. */
|
|
122
|
+
readonly bonds: CrystalBonds;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** One cell, its molecules whole, inside its box. */
|
|
126
|
+
export const DEFAULT_CRYSTAL_VIEW_SETTINGS: CrystalViewSettings = {
|
|
127
|
+
packing: 'molecules',
|
|
128
|
+
cells: 1,
|
|
129
|
+
unitCell: true,
|
|
130
|
+
bonds: 'all',
|
|
131
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The set of symmetry elements currently drawn, kept as a list so a page can
|
|
3
|
+
* add and remove one at a time without rebuilding its own bookkeeping.
|
|
4
|
+
*
|
|
5
|
+
* The mesh behind them is rebuilt whole on every change — a handful of rods and
|
|
6
|
+
* squares costs nothing — but the *set* is edited, which is what lets a chip bar
|
|
7
|
+
* turn the mirrors off and leave the axes alone.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { SymmetryDrawing } from './types.ts';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Add the drawings, replacing any that carry an id already present.
|
|
14
|
+
* @param current - What is drawn now.
|
|
15
|
+
* @param incoming - What to add or replace.
|
|
16
|
+
* @returns The new set: the current order kept, anything genuinely new appended.
|
|
17
|
+
*/
|
|
18
|
+
export function mergeDrawings(
|
|
19
|
+
current: readonly SymmetryDrawing[],
|
|
20
|
+
incoming: readonly SymmetryDrawing[],
|
|
21
|
+
): SymmetryDrawing[] {
|
|
22
|
+
const replacements = new Map<string, SymmetryDrawing>();
|
|
23
|
+
for (const drawing of incoming) replacements.set(drawing.id, drawing);
|
|
24
|
+
const merged: SymmetryDrawing[] = [];
|
|
25
|
+
for (const drawing of current) {
|
|
26
|
+
merged.push(replacements.get(drawing.id) ?? drawing);
|
|
27
|
+
replacements.delete(drawing.id);
|
|
28
|
+
}
|
|
29
|
+
for (const drawing of incoming) {
|
|
30
|
+
const pending = replacements.get(drawing.id);
|
|
31
|
+
if (pending === undefined) continue;
|
|
32
|
+
merged.push(pending);
|
|
33
|
+
replacements.delete(drawing.id);
|
|
34
|
+
}
|
|
35
|
+
return merged;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Drop the drawings with these ids.
|
|
40
|
+
* @param current - What is drawn now.
|
|
41
|
+
* @param ids - Which to remove; an id that is not drawn is ignored.
|
|
42
|
+
* @returns The rest, in the order they were in.
|
|
43
|
+
*/
|
|
44
|
+
export function withoutDrawings(
|
|
45
|
+
current: readonly SymmetryDrawing[],
|
|
46
|
+
ids: readonly string[],
|
|
47
|
+
): SymmetryDrawing[] {
|
|
48
|
+
const dropped = new Set(ids);
|
|
49
|
+
const kept: SymmetryDrawing[] = [];
|
|
50
|
+
for (const drawing of current) {
|
|
51
|
+
if (!dropped.has(drawing.id)) kept.push(drawing);
|
|
52
|
+
}
|
|
53
|
+
return kept;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether two sets would draw the same thing, so an unchanged render is skipped.
|
|
58
|
+
* @param a - One set.
|
|
59
|
+
* @param b - The other.
|
|
60
|
+
* @returns Whether they hold the same drawings, in the same order.
|
|
61
|
+
*/
|
|
62
|
+
export function sameDrawings(
|
|
63
|
+
a: readonly SymmetryDrawing[],
|
|
64
|
+
b: readonly SymmetryDrawing[],
|
|
65
|
+
): boolean {
|
|
66
|
+
if (a.length !== b.length) return false;
|
|
67
|
+
for (let index = 0; index < a.length; index++) {
|
|
68
|
+
if (a[index] !== b[index]) return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A symmetry element as shapes: the whole of what the 3D view draws over a
|
|
3
|
+
* structure, worked out without a canvas anywhere in sight.
|
|
4
|
+
*
|
|
5
|
+
* The rules are the ones a crystallographic diagram uses. A proper axis is a
|
|
6
|
+
* solid rod; a screw carries an arrow as long as its pitch, beside the rod so
|
|
7
|
+
* neither hides the other; a rotoinversion is broken, with a ball at the point
|
|
8
|
+
* it inverts through; a plane is a translucent face with its rim drawn, and a
|
|
9
|
+
* glide plane wears its glide vector as an arrow lying in it.
|
|
10
|
+
*
|
|
11
|
+
* A plane drawn over a cell is handed the polygon it cuts out of that cell, so
|
|
12
|
+
* what is on screen is the slice itself rather than a square hanging in the
|
|
13
|
+
* middle of the box. Without one — a molecule has no cell to cut — it falls
|
|
14
|
+
* back to a square of `size`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { spacedLabels } from './elementLabels.ts';
|
|
18
|
+
import { arrow, planeFace, rodEnds } from './elementShapes.ts';
|
|
19
|
+
import { perpendicularTo } from './frame.ts';
|
|
20
|
+
import { plainName } from './labelText.ts';
|
|
21
|
+
import { drawingColour } from './palette.ts';
|
|
22
|
+
import type { ElementStyle, MeshPrimitive, TextItem } from './primitives.ts';
|
|
23
|
+
import { resolveElementStyle } from './primitives.ts';
|
|
24
|
+
import type { Point3, SymmetryDrawing } from './types.ts';
|
|
25
|
+
import {
|
|
26
|
+
addVectors,
|
|
27
|
+
normalizeVector,
|
|
28
|
+
scaleVector,
|
|
29
|
+
vectorNorm,
|
|
30
|
+
} from './vec3.ts';
|
|
31
|
+
|
|
32
|
+
/** One element, ready to become one pickable, labelled group of a mesh. */
|
|
33
|
+
export interface ElementGroup {
|
|
34
|
+
/** The drawing's own id, unchanged. */
|
|
35
|
+
readonly id: string;
|
|
36
|
+
/** What the pointer reads. */
|
|
37
|
+
readonly label: string;
|
|
38
|
+
/** `#rrggbb`. */
|
|
39
|
+
readonly colour: string;
|
|
40
|
+
/** Its shapes. */
|
|
41
|
+
readonly primitives: readonly MeshPrimitive[];
|
|
42
|
+
/** Its floating text, empty when labels are off. */
|
|
43
|
+
readonly labels: readonly TextItem[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Turn the drawings into groups, in the order they were given.
|
|
48
|
+
* @param drawings - The elements to draw.
|
|
49
|
+
* @param options - Sizes, and whether the labels are drawn.
|
|
50
|
+
* @param options.style - Sizes of the shapes, over the defaults.
|
|
51
|
+
* @param options.labels - Whether the labels are drawn; true by default.
|
|
52
|
+
* @returns One group per drawing.
|
|
53
|
+
*/
|
|
54
|
+
export function elementGroups(
|
|
55
|
+
drawings: readonly SymmetryDrawing[],
|
|
56
|
+
options: { style?: ElementStyle; labels?: boolean } = {},
|
|
57
|
+
): ElementGroup[] {
|
|
58
|
+
const style = resolveElementStyle(options.style);
|
|
59
|
+
const withLabels = options.labels ?? true;
|
|
60
|
+
const groups: ElementGroup[] = [];
|
|
61
|
+
const taken: Point3[] = [];
|
|
62
|
+
for (const drawing of drawings) {
|
|
63
|
+
groups.push({
|
|
64
|
+
id: drawing.id,
|
|
65
|
+
label: plainName(drawing.label),
|
|
66
|
+
colour: drawingColour(drawing.kind, drawing.colour),
|
|
67
|
+
primitives: drawingPrimitives(drawing, style),
|
|
68
|
+
labels: withLabels ? spacedLabels(drawing, style, taken) : [],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return groups;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The shapes one element is drawn as.
|
|
76
|
+
* @param drawing - The element.
|
|
77
|
+
* @param style - Sizes; the defaults are used for anything left out.
|
|
78
|
+
* @returns Its shapes, in drawing order.
|
|
79
|
+
*/
|
|
80
|
+
export function drawingPrimitives(
|
|
81
|
+
drawing: SymmetryDrawing,
|
|
82
|
+
style: ElementStyle = {},
|
|
83
|
+
): MeshPrimitive[] {
|
|
84
|
+
const sizes = resolveElementStyle(style);
|
|
85
|
+
switch (drawing.kind) {
|
|
86
|
+
case 'inversion': {
|
|
87
|
+
return [
|
|
88
|
+
{ shape: 'sphere', centre: drawing.point, radius: sizes.centreRadius },
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
case 'mirror': {
|
|
92
|
+
return planeFace(drawing, sizes);
|
|
93
|
+
}
|
|
94
|
+
case 'glide': {
|
|
95
|
+
const length = vectorNorm(drawing.glide);
|
|
96
|
+
return [
|
|
97
|
+
...planeFace(drawing, sizes),
|
|
98
|
+
...arrow(drawing.point, drawing.glide, length, sizes),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
case 'rotoinversion': {
|
|
102
|
+
const [start, end] = rodEnds(
|
|
103
|
+
drawing.point,
|
|
104
|
+
drawing.direction,
|
|
105
|
+
drawing.length,
|
|
106
|
+
);
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
shape: 'dashes',
|
|
110
|
+
start,
|
|
111
|
+
end,
|
|
112
|
+
radius: sizes.axisRadius,
|
|
113
|
+
segments: sizes.dashSegments,
|
|
114
|
+
},
|
|
115
|
+
{ shape: 'sphere', centre: drawing.point, radius: sizes.centreRadius },
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
case 'screw': {
|
|
119
|
+
const [start, end] = rodEnds(
|
|
120
|
+
drawing.point,
|
|
121
|
+
drawing.direction,
|
|
122
|
+
drawing.length,
|
|
123
|
+
);
|
|
124
|
+
const unit = normalizeVector(drawing.direction);
|
|
125
|
+
const beside = addVectors(
|
|
126
|
+
drawing.point,
|
|
127
|
+
scaleVector(
|
|
128
|
+
perpendicularTo(unit),
|
|
129
|
+
sizes.arrowOffset * sizes.axisRadius,
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
return [
|
|
133
|
+
{ shape: 'rod', start, end, radius: sizes.axisRadius },
|
|
134
|
+
...arrow(beside, unit, drawing.pitch, sizes),
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
case 'rotation': {
|
|
138
|
+
const [start, end] = rodEnds(
|
|
139
|
+
drawing.point,
|
|
140
|
+
drawing.direction,
|
|
141
|
+
drawing.length,
|
|
142
|
+
);
|
|
143
|
+
return [{ shape: 'rod', start, end, radius: sizes.axisRadius }];
|
|
144
|
+
}
|
|
145
|
+
// no default
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much of an element is drawn.
|
|
3
|
+
*
|
|
4
|
+
* `cellClip.ts` answers where an unbounded line or plane meets the cell; this
|
|
5
|
+
* is the decision taken on that answer. It has one job beyond passing the call
|
|
6
|
+
* along: when the element misses the box, or only grazes a corner of it, the
|
|
7
|
+
* clipped form would be nothing at all, so the caller falls back to the rod or
|
|
8
|
+
* the square it asked for rather than drawing an element that is not there.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Lattice } from '../../crystal/core/symmetry/lattice.ts';
|
|
12
|
+
|
|
13
|
+
import { cellSection, clipLineToCell } from './cellClip.ts';
|
|
14
|
+
import type { Point3 } from './types.ts';
|
|
15
|
+
import {
|
|
16
|
+
addVectors,
|
|
17
|
+
scaleVector,
|
|
18
|
+
subtractVectors,
|
|
19
|
+
vectorNorm,
|
|
20
|
+
} from './vec3.ts';
|
|
21
|
+
|
|
22
|
+
/** Where an axis rod starts, which way it runs and how long it is. */
|
|
23
|
+
export interface AxisRod {
|
|
24
|
+
readonly point: Point3;
|
|
25
|
+
readonly direction: Point3;
|
|
26
|
+
readonly length: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The rod an axis is drawn as: the piece inside the cell when the caller asked
|
|
31
|
+
* for that, and a rod of `length` centred on the element's own point when it
|
|
32
|
+
* did not, or when the axis misses the box.
|
|
33
|
+
* @param lattice - The cell it is cut against.
|
|
34
|
+
* @param point - A point of the axis, Cartesian ångström.
|
|
35
|
+
* @param direction - Its direction, Cartesian.
|
|
36
|
+
* @param length - The rod to draw when it is not clipped, ångström.
|
|
37
|
+
* @param clip - Whether to cut it off at the cell.
|
|
38
|
+
* @returns The rod, centred on its own middle.
|
|
39
|
+
*/
|
|
40
|
+
export function axisRod(
|
|
41
|
+
lattice: Lattice,
|
|
42
|
+
point: Point3,
|
|
43
|
+
direction: Point3,
|
|
44
|
+
length: number,
|
|
45
|
+
clip: boolean,
|
|
46
|
+
): AxisRod {
|
|
47
|
+
if (!clip) return { point, direction, length };
|
|
48
|
+
const segment = clipLineToCell(lattice, point, direction);
|
|
49
|
+
if (segment === null) return { point, direction, length };
|
|
50
|
+
const span = subtractVectors(segment.end, segment.start);
|
|
51
|
+
const reach = vectorNorm(span);
|
|
52
|
+
if (reach < MINIMUM_ROD) return { point, direction, length };
|
|
53
|
+
return {
|
|
54
|
+
point: addVectors(segment.start, scaleVector(span, 0.5)),
|
|
55
|
+
direction,
|
|
56
|
+
length: reach,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The polygon a plane cuts out of the cell, when the caller asked for it.
|
|
62
|
+
* @param lattice - The cell it is cut against.
|
|
63
|
+
* @param point - A point of the plane, Cartesian ångström.
|
|
64
|
+
* @param normal - Its normal, Cartesian.
|
|
65
|
+
* @param clip - Whether to cut it to the cell.
|
|
66
|
+
* @returns An `outline` to draw the plane between, or nothing, which leaves the
|
|
67
|
+
* plane its square.
|
|
68
|
+
*/
|
|
69
|
+
export function faceOf(
|
|
70
|
+
lattice: Lattice,
|
|
71
|
+
point: Point3,
|
|
72
|
+
normal: Point3,
|
|
73
|
+
clip: boolean,
|
|
74
|
+
): { outline?: readonly Point3[] } {
|
|
75
|
+
if (!clip) return {};
|
|
76
|
+
const outline = cellSection(lattice, point, normal);
|
|
77
|
+
return outline.length < 3 ? {} : { outline };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Below this, ångström, a line only grazes a corner of the cell. */
|
|
81
|
+
const MINIMUM_ROD = 1e-6;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an element's name floats, and whether it is written at all.
|
|
3
|
+
*
|
|
4
|
+
* Naming a symmetry element is harder than drawing it, because symmetry piles
|
|
5
|
+
* elements on top of each other: the nine mirror planes of a cubic cell all
|
|
6
|
+
* meet at its eight corners. So a name is placed as far from the structure as
|
|
7
|
+
* its element reaches, and is dropped when another name already sits there.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { faceCorners } from './elementShapes.ts';
|
|
11
|
+
import { plainName } from './labelText.ts';
|
|
12
|
+
import type {
|
|
13
|
+
ElementStyle,
|
|
14
|
+
ResolvedElementStyle,
|
|
15
|
+
TextItem,
|
|
16
|
+
} from './primitives.ts';
|
|
17
|
+
import { resolveElementStyle } from './primitives.ts';
|
|
18
|
+
import type {
|
|
19
|
+
GlideDrawing,
|
|
20
|
+
MirrorDrawing,
|
|
21
|
+
Point3,
|
|
22
|
+
SymmetryDrawing,
|
|
23
|
+
} from './types.ts';
|
|
24
|
+
import type { Vec3 } from './vec3.ts';
|
|
25
|
+
import {
|
|
26
|
+
addVectors,
|
|
27
|
+
normalizeVector,
|
|
28
|
+
scaleVector,
|
|
29
|
+
subtractVectors,
|
|
30
|
+
vectorNorm,
|
|
31
|
+
} from './vec3.ts';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Where one element's text floats, and what it reads.
|
|
35
|
+
* @param drawing - The element.
|
|
36
|
+
* @param style - Sizes; the defaults are used for anything left out.
|
|
37
|
+
* @returns One line of text, or none when the element carries no label.
|
|
38
|
+
*/
|
|
39
|
+
export function drawingLabels(
|
|
40
|
+
drawing: SymmetryDrawing,
|
|
41
|
+
style: ElementStyle = {},
|
|
42
|
+
): TextItem[] {
|
|
43
|
+
const text = plainName(drawing.badge ?? drawing.label);
|
|
44
|
+
if (text === '') return [];
|
|
45
|
+
const sizes = resolveElementStyle(style);
|
|
46
|
+
const size = sizes.labelSize;
|
|
47
|
+
if (drawing.kind === 'inversion') {
|
|
48
|
+
const offset = scaleVector(LABEL_UP, sizes.centreRadius + sizes.labelGap);
|
|
49
|
+
return [{ text, position: addVectors(drawing.point, offset), size }];
|
|
50
|
+
}
|
|
51
|
+
if (drawing.kind === 'mirror' || drawing.kind === 'glide') {
|
|
52
|
+
return [{ text, position: planeLabelPoint(drawing, sizes), size }];
|
|
53
|
+
}
|
|
54
|
+
const unit = normalizeVector(drawing.direction);
|
|
55
|
+
const reach = drawing.length / 2 + sizes.labelGap;
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
text,
|
|
59
|
+
position: addVectors(drawing.point, scaleVector(unit, reach)),
|
|
60
|
+
size,
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The element's name, unless another name already sits where it would go.
|
|
67
|
+
*
|
|
68
|
+
* Symmetry puts elements on top of each other — nine mirror planes of a cubic
|
|
69
|
+
* cell meet at the same eight corners — and two names in one place are not two
|
|
70
|
+
* names, they are a smudge. The one drawn first keeps the spot; the rest are
|
|
71
|
+
* still on the pointer and in the list beside the view.
|
|
72
|
+
* @param drawing - The element.
|
|
73
|
+
* @param style - Resolved sizes.
|
|
74
|
+
* @param taken - Where names already sit; the kept one is added to it.
|
|
75
|
+
* @returns Its text, or none when the spot is taken.
|
|
76
|
+
*/
|
|
77
|
+
export function spacedLabels(
|
|
78
|
+
drawing: SymmetryDrawing,
|
|
79
|
+
style: ResolvedElementStyle,
|
|
80
|
+
taken: Point3[],
|
|
81
|
+
): TextItem[] {
|
|
82
|
+
const kept: TextItem[] = [];
|
|
83
|
+
for (const item of drawingLabels(drawing, style)) {
|
|
84
|
+
let clear = true;
|
|
85
|
+
for (const other of taken) {
|
|
86
|
+
if (vectorNorm(subtractVectors(item.position, other)) < style.labelSize) {
|
|
87
|
+
clear = false;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!clear) continue;
|
|
92
|
+
taken.push(item.position);
|
|
93
|
+
kept.push(item);
|
|
94
|
+
}
|
|
95
|
+
return kept;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Where a plane's name sits: a corner of the drawn face, pushed out of it.
|
|
100
|
+
*
|
|
101
|
+
* A corner is as far from the structure as the element gets, so the names of
|
|
102
|
+
* ten planes through one cell end up spread round its edges rather than piled
|
|
103
|
+
* on the atoms in the middle.
|
|
104
|
+
* @param drawing - The mirror or glide plane.
|
|
105
|
+
* @param sizes - The resolved sizes, for the gap off the face.
|
|
106
|
+
* @returns The label's position, Cartesian ångström.
|
|
107
|
+
*/
|
|
108
|
+
function planeLabelPoint(
|
|
109
|
+
drawing: GlideDrawing | MirrorDrawing,
|
|
110
|
+
sizes: ResolvedElementStyle,
|
|
111
|
+
): Point3 {
|
|
112
|
+
const corners = faceCorners(drawing);
|
|
113
|
+
const first = corners[0];
|
|
114
|
+
if (first === undefined) return drawing.point;
|
|
115
|
+
let centre: Point3 = [0, 0, 0];
|
|
116
|
+
for (const corner of corners) centre = addVectors(centre, corner);
|
|
117
|
+
centre = scaleVector(centre, 1 / corners.length);
|
|
118
|
+
const outward = subtractVectors(first, centre);
|
|
119
|
+
if (vectorNorm(outward) < FLAT) return first;
|
|
120
|
+
return addVectors(
|
|
121
|
+
first,
|
|
122
|
+
scaleVector(normalizeVector(outward), sizes.labelGap),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Which way an inversion centre's label sits, having no direction of its own. */
|
|
127
|
+
const LABEL_UP: Vec3 = [0, 0, 1];
|
|
128
|
+
|
|
129
|
+
/** Below this, ångström, a corner is the centre and has no outward direction. */
|
|
130
|
+
const FLAT = 1e-9;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape vocabulary a symmetry element is drawn in: rods, arrows and faces.
|
|
3
|
+
*
|
|
4
|
+
* A crystallographic diagram draws six kinds of element out of three shapes, so
|
|
5
|
+
* the kinds are the switch and these are the words it is written in. Each one
|
|
6
|
+
* takes plain geometry and hands back primitives, which is what makes the whole
|
|
7
|
+
* of the drawing testable without a canvas.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { planeFrame } from './frame.ts';
|
|
11
|
+
import type { MeshPrimitive, ResolvedElementStyle } from './primitives.ts';
|
|
12
|
+
import type { GlideDrawing, MirrorDrawing, Point3 } from './types.ts';
|
|
13
|
+
import { addVectors, normalizeVector, scaleVector } from './vec3.ts';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The two ends of a rod of `length` centred on `point`.
|
|
17
|
+
* @param point - Its middle.
|
|
18
|
+
* @param direction - Which way it runs; need not be normalised.
|
|
19
|
+
* @param length - Its total length, ångström.
|
|
20
|
+
* @returns The two ends, the one against `direction` first.
|
|
21
|
+
*/
|
|
22
|
+
export function rodEnds(
|
|
23
|
+
point: Point3,
|
|
24
|
+
direction: Point3,
|
|
25
|
+
length: number,
|
|
26
|
+
): [Point3, Point3] {
|
|
27
|
+
const half = scaleVector(normalizeVector(direction), length / 2);
|
|
28
|
+
return [addVectors(point, scaleVector(half, -1)), addVectors(point, half)];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A shaft and a head, pointing along `direction` for `length` ångström.
|
|
33
|
+
* @param base - Where the arrow starts.
|
|
34
|
+
* @param direction - Which way it points; need not be normalised.
|
|
35
|
+
* @param length - How far it reaches. A negative length points the other way,
|
|
36
|
+
* which is how a left-handed screw is told from a right-handed one.
|
|
37
|
+
* @param sizes - Resolved sizes.
|
|
38
|
+
* @returns The shaft, when there is room for one, and the head.
|
|
39
|
+
*/
|
|
40
|
+
export function arrow(
|
|
41
|
+
base: Point3,
|
|
42
|
+
direction: Point3,
|
|
43
|
+
length: number,
|
|
44
|
+
sizes: ResolvedElementStyle,
|
|
45
|
+
): MeshPrimitive[] {
|
|
46
|
+
const reach = Math.abs(length);
|
|
47
|
+
if (reach < MINIMUM_ARROW) return [];
|
|
48
|
+
const unit = scaleVector(normalizeVector(direction), Math.sign(length));
|
|
49
|
+
const head = Math.min(sizes.arrowLength, reach);
|
|
50
|
+
const shaftEnd = addVectors(base, scaleVector(unit, reach - head));
|
|
51
|
+
const tip = addVectors(base, scaleVector(unit, reach));
|
|
52
|
+
const primitives: MeshPrimitive[] = [];
|
|
53
|
+
if (reach > head) {
|
|
54
|
+
primitives.push({
|
|
55
|
+
shape: 'rod',
|
|
56
|
+
start: base,
|
|
57
|
+
end: shaftEnd,
|
|
58
|
+
radius: sizes.axisRadius,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
primitives.push({
|
|
62
|
+
shape: 'cone',
|
|
63
|
+
base: shaftEnd,
|
|
64
|
+
tip,
|
|
65
|
+
radius: sizes.arrowRadius,
|
|
66
|
+
});
|
|
67
|
+
return primitives;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A plane as a face and the rim round it, so a stack of them stays readable.
|
|
72
|
+
* @param drawing - The mirror or glide plane.
|
|
73
|
+
* @param sizes - Resolved sizes.
|
|
74
|
+
* @returns The face and one rod per edge, or the square when the plane was
|
|
75
|
+
* given no outline to be cut to.
|
|
76
|
+
*/
|
|
77
|
+
export function planeFace(
|
|
78
|
+
drawing: GlideDrawing | MirrorDrawing,
|
|
79
|
+
sizes: ResolvedElementStyle,
|
|
80
|
+
): MeshPrimitive[] {
|
|
81
|
+
const outline = drawing.outline;
|
|
82
|
+
if (outline === undefined || outline.length < 3) {
|
|
83
|
+
return [plate(drawing.point, drawing.normal, drawing.size)];
|
|
84
|
+
}
|
|
85
|
+
const primitives: MeshPrimitive[] = [{ shape: 'face', points: outline }];
|
|
86
|
+
for (let index = 0; index < outline.length; index++) {
|
|
87
|
+
const start = outline[index];
|
|
88
|
+
const end = outline[(index + 1) % outline.length];
|
|
89
|
+
if (start === undefined || end === undefined) continue;
|
|
90
|
+
primitives.push({ shape: 'rod', start, end, radius: sizes.rimRadius });
|
|
91
|
+
}
|
|
92
|
+
return primitives;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The face a plane is drawn as: the outline it was given, or a square.
|
|
97
|
+
* @param drawing - The mirror or glide plane.
|
|
98
|
+
* @returns Its corners, in order around the plane.
|
|
99
|
+
*/
|
|
100
|
+
export function faceCorners(drawing: GlideDrawing | MirrorDrawing): Point3[] {
|
|
101
|
+
const outline = drawing.outline;
|
|
102
|
+
if (outline !== undefined && outline.length >= 3) return [...outline];
|
|
103
|
+
const { major, minor } = planeFrame(drawing.normal);
|
|
104
|
+
const half = drawing.size / 2;
|
|
105
|
+
const corners: Point3[] = [];
|
|
106
|
+
for (const [along, across] of SQUARE) {
|
|
107
|
+
corners.push(
|
|
108
|
+
addVectors(
|
|
109
|
+
drawing.point,
|
|
110
|
+
addVectors(
|
|
111
|
+
scaleVector(major, along * half),
|
|
112
|
+
scaleVector(minor, across * half),
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return corners;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The square a mirror or a glide plane is drawn as.
|
|
122
|
+
* @param point - Its centre, Cartesian ångström.
|
|
123
|
+
* @param normal - The plane's normal, Cartesian.
|
|
124
|
+
* @param size - The side of the square, ångström.
|
|
125
|
+
* @returns The plate primitive.
|
|
126
|
+
*/
|
|
127
|
+
function plate(point: Point3, normal: Point3, size: number): MeshPrimitive {
|
|
128
|
+
const { major, minor } = planeFrame(normal);
|
|
129
|
+
return { shape: 'plate', centre: point, major, minor, size };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The four corners of a square, as multiples of its half-side. */
|
|
133
|
+
const SQUARE: ReadonlyArray<readonly [number, number]> = [
|
|
134
|
+
[-1, -1],
|
|
135
|
+
[1, -1],
|
|
136
|
+
[1, 1],
|
|
137
|
+
[-1, 1],
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
/** Below this, ångström, an arrow is a blob and is left out. */
|
|
141
|
+
const MINIMUM_ARROW = 1e-6;
|