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,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two directions spanning a plane, chosen the same way every time.
|
|
3
|
+
*
|
|
4
|
+
* A mirror plane is drawn as a square, and a square needs two in-plane
|
|
5
|
+
* directions that the normal alone does not give. Picking them deterministically
|
|
6
|
+
* is what stops the same plane being drawn at two different rotations on two
|
|
7
|
+
* successive renders.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Vec3 } from './vec3.ts';
|
|
11
|
+
import {
|
|
12
|
+
crossProduct,
|
|
13
|
+
dotProduct,
|
|
14
|
+
normalizeVector,
|
|
15
|
+
scaleVector,
|
|
16
|
+
subtractVectors,
|
|
17
|
+
} from './vec3.ts';
|
|
18
|
+
|
|
19
|
+
/** An orthonormal pair spanning a plane, with the normal that produced it. */
|
|
20
|
+
export interface PlaneFrame {
|
|
21
|
+
/** The unit normal. */
|
|
22
|
+
readonly normal: Vec3;
|
|
23
|
+
/** First in-plane direction. */
|
|
24
|
+
readonly major: Vec3;
|
|
25
|
+
/** Second in-plane direction, `normal × major`. */
|
|
26
|
+
readonly minor: Vec3;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The frame of the plane with this normal.
|
|
31
|
+
* @param normal - The plane normal; need not be normalised.
|
|
32
|
+
* @returns The unit normal and two unit directions in the plane.
|
|
33
|
+
* @throws {RangeError} When the normal is too short to have a direction.
|
|
34
|
+
*/
|
|
35
|
+
export function planeFrame(normal: Vec3): PlaneFrame {
|
|
36
|
+
const unit = normalizeVector(normal);
|
|
37
|
+
const major = perpendicularTo(unit);
|
|
38
|
+
return { normal: unit, major, minor: crossProduct(unit, major) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A unit vector at right angles to `direction`.
|
|
43
|
+
*
|
|
44
|
+
* The seed is `x̂` unless the direction is already close to it, which is the
|
|
45
|
+
* one case where projecting out the direction would leave nothing to normalise.
|
|
46
|
+
* @param direction - Any non-zero vector; need not be normalised.
|
|
47
|
+
* @returns A unit vector orthogonal to it.
|
|
48
|
+
* @throws {RangeError} When the direction is too short to have one.
|
|
49
|
+
*/
|
|
50
|
+
export function perpendicularTo(direction: Vec3): Vec3 {
|
|
51
|
+
const unit = normalizeVector(direction);
|
|
52
|
+
const seed: Vec3 = Math.abs(unit[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0];
|
|
53
|
+
return normalizeVector(
|
|
54
|
+
subtractVectors(seed, scaleVector(unit, dotProduct(seed, unit))),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much room the scene takes, so the camera can frame it.
|
|
3
|
+
*
|
|
4
|
+
* molstar measures a representation's bounding sphere with the largest ball it
|
|
5
|
+
* could ever draw added on, which on a molecule of a dozen atoms is about two
|
|
6
|
+
* ångström of empty frame — the difference between a model that fills the view
|
|
7
|
+
* and one that fills a quarter of it. The atoms are here, so they are measured
|
|
8
|
+
* here.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { MeshPrimitive } from './primitives.ts';
|
|
12
|
+
import { primitivePoints } from './primitives.ts';
|
|
13
|
+
import type { Point3 } from './types.ts';
|
|
14
|
+
|
|
15
|
+
/** A ball holding everything on screen. */
|
|
16
|
+
export interface SceneSphere {
|
|
17
|
+
/** Its centre, Cartesian ångström. */
|
|
18
|
+
readonly centre: Point3;
|
|
19
|
+
/** Its radius, ångström; zero for a single point. */
|
|
20
|
+
readonly radius: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The smallest ball about the centroid that holds every point.
|
|
25
|
+
* @param points - What has to fit; an empty list gives a point at the origin.
|
|
26
|
+
* @param padding - Extra radius, ångström, for whatever is drawn around them.
|
|
27
|
+
* @returns The ball.
|
|
28
|
+
*/
|
|
29
|
+
export function boundingSphereOf(
|
|
30
|
+
points: readonly Point3[],
|
|
31
|
+
padding = 0,
|
|
32
|
+
): SceneSphere {
|
|
33
|
+
if (points.length === 0) return { centre: [0, 0, 0], radius: padding };
|
|
34
|
+
let sumX = 0;
|
|
35
|
+
let sumY = 0;
|
|
36
|
+
let sumZ = 0;
|
|
37
|
+
for (const point of points) {
|
|
38
|
+
sumX += point[0];
|
|
39
|
+
sumY += point[1];
|
|
40
|
+
sumZ += point[2];
|
|
41
|
+
}
|
|
42
|
+
const centre: Point3 = [
|
|
43
|
+
sumX / points.length,
|
|
44
|
+
sumY / points.length,
|
|
45
|
+
sumZ / points.length,
|
|
46
|
+
];
|
|
47
|
+
let radius = 0;
|
|
48
|
+
for (const point of points) {
|
|
49
|
+
const distance = Math.hypot(
|
|
50
|
+
point[0] - centre[0],
|
|
51
|
+
point[1] - centre[1],
|
|
52
|
+
point[2] - centre[2],
|
|
53
|
+
);
|
|
54
|
+
if (distance > radius) radius = distance;
|
|
55
|
+
}
|
|
56
|
+
return { centre, radius: radius + padding };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* One ball holding several — the atoms, the cell and the drawn elements at once.
|
|
61
|
+
* @param spheres - What has to fit; an empty list gives a point at the origin.
|
|
62
|
+
* @returns A ball containing every one of them. It is not the smallest such
|
|
63
|
+
* ball, which is a harder problem than framing a scene deserves, but it never
|
|
64
|
+
* leaves anything outside.
|
|
65
|
+
*/
|
|
66
|
+
export function unionSpheres(spheres: readonly SceneSphere[]): SceneSphere {
|
|
67
|
+
if (spheres.length === 0) return { centre: [0, 0, 0], radius: 0 };
|
|
68
|
+
const first = spheres[0];
|
|
69
|
+
if (spheres.length === 1 && first !== undefined) return first;
|
|
70
|
+
const centres: Point3[] = [];
|
|
71
|
+
for (const sphere of spheres) centres.push(sphere.centre);
|
|
72
|
+
const { centre } = boundingSphereOf(centres);
|
|
73
|
+
let radius = 0;
|
|
74
|
+
for (const sphere of spheres) {
|
|
75
|
+
const reach =
|
|
76
|
+
Math.hypot(
|
|
77
|
+
sphere.centre[0] - centre[0],
|
|
78
|
+
sphere.centre[1] - centre[1],
|
|
79
|
+
sphere.centre[2] - centre[2],
|
|
80
|
+
) + sphere.radius;
|
|
81
|
+
if (reach > radius) radius = reach;
|
|
82
|
+
}
|
|
83
|
+
return { centre, radius };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* How far a set of drawn shapes reaches.
|
|
88
|
+
* @param primitives - The shapes.
|
|
89
|
+
* @param padding - Extra radius, ångström.
|
|
90
|
+
* @returns A ball holding them all.
|
|
91
|
+
*/
|
|
92
|
+
export function primitivesExtent(
|
|
93
|
+
primitives: readonly MeshPrimitive[],
|
|
94
|
+
padding = 0,
|
|
95
|
+
): SceneSphere {
|
|
96
|
+
const points: Point3[] = [];
|
|
97
|
+
for (const primitive of primitives) {
|
|
98
|
+
points.push(...primitivePoints(primitive));
|
|
99
|
+
}
|
|
100
|
+
return boundingSphereOf(points, padding);
|
|
101
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The half of the crystal viewer that has never heard of molstar.
|
|
3
|
+
*
|
|
4
|
+
* A page that only *builds* a scene — repeats a cell, works out which symmetry
|
|
5
|
+
* elements to draw, frames what it has — imports this and pays nothing: the
|
|
6
|
+
* molstar chunk hangs off `viewer/`, which is reached through the lazy canvas
|
|
7
|
+
* and nowhere else.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type { CellSegment } from './cellClip.ts';
|
|
11
|
+
export { cellSection, clipLineToCell } from './cellClip.ts';
|
|
12
|
+
export type { CellEdge } from './cellGeometry.ts';
|
|
13
|
+
export {
|
|
14
|
+
cellAxes,
|
|
15
|
+
cellAxisLabelPoints,
|
|
16
|
+
cellEdges,
|
|
17
|
+
cellPoint,
|
|
18
|
+
clampRepeat,
|
|
19
|
+
latticeShifts,
|
|
20
|
+
} from './cellGeometry.ts';
|
|
21
|
+
export { mergeDrawings, sameDrawings, withoutDrawings } from './drawingSet.ts';
|
|
22
|
+
export type { ElementGroup } from './elementDrawing.ts';
|
|
23
|
+
export { drawingPrimitives, elementGroups } from './elementDrawing.ts';
|
|
24
|
+
export { drawingLabels } from './elementLabels.ts';
|
|
25
|
+
export { plainName } from './labelText.ts';
|
|
26
|
+
export type { PlaneFrame } from './frame.ts';
|
|
27
|
+
export { perpendicularTo, planeFrame } from './frame.ts';
|
|
28
|
+
export type { SceneSphere } from './framing.ts';
|
|
29
|
+
export { boundingSphereOf, primitivesExtent, unionSpheres } from './framing.ts';
|
|
30
|
+
export type { OrientedScene, ViewOrientation } from './orientation.ts';
|
|
31
|
+
export {
|
|
32
|
+
principalAxisOf,
|
|
33
|
+
sceneOrientation,
|
|
34
|
+
threeQuarterView,
|
|
35
|
+
} from './orientation.ts';
|
|
36
|
+
export type { Matrix4 } from './operationMatrix.ts';
|
|
37
|
+
export {
|
|
38
|
+
IDENTITY_MATRIX4,
|
|
39
|
+
ROTATION_PHASE,
|
|
40
|
+
operationAt,
|
|
41
|
+
operationIsRigid,
|
|
42
|
+
operationMatrix,
|
|
43
|
+
} from './operationMatrix.ts';
|
|
44
|
+
export {
|
|
45
|
+
CELL_COLOUR,
|
|
46
|
+
ELEMENT_COLOURS,
|
|
47
|
+
LABEL_COLOUR,
|
|
48
|
+
drawingColour,
|
|
49
|
+
} from './palette.ts';
|
|
50
|
+
export type {
|
|
51
|
+
ElementStyle,
|
|
52
|
+
MeshPrimitive,
|
|
53
|
+
ResolvedElementStyle,
|
|
54
|
+
TextItem,
|
|
55
|
+
} from './primitives.ts';
|
|
56
|
+
export {
|
|
57
|
+
DEFAULT_ELEMENT_STYLE,
|
|
58
|
+
primitivePoints,
|
|
59
|
+
resolveElementStyle,
|
|
60
|
+
} from './primitives.ts';
|
|
61
|
+
export { toXyzText } from './structureText.ts';
|
|
62
|
+
export { supercellAtoms } from './supercell.ts';
|
|
63
|
+
export type {
|
|
64
|
+
CellRepeat,
|
|
65
|
+
DrawingBase,
|
|
66
|
+
GlideDrawing,
|
|
67
|
+
InversionDrawing,
|
|
68
|
+
MirrorDrawing,
|
|
69
|
+
Point3,
|
|
70
|
+
RotationDrawing,
|
|
71
|
+
RotoinversionDrawing,
|
|
72
|
+
ScrewDrawing,
|
|
73
|
+
SymmetryDrawing,
|
|
74
|
+
SymmetryDrawingKind,
|
|
75
|
+
UnitCell,
|
|
76
|
+
ViewerAtom,
|
|
77
|
+
ViewerOperation,
|
|
78
|
+
} from './types.ts';
|
|
79
|
+
|
|
80
|
+
export type { Mat3 } from './mat3.ts';
|
|
81
|
+
export {
|
|
82
|
+
IDENTITY_MATRIX,
|
|
83
|
+
INVERSION_MATRIX,
|
|
84
|
+
applyMatrix,
|
|
85
|
+
matrixDeterminant,
|
|
86
|
+
matrixDistance,
|
|
87
|
+
matrixTrace,
|
|
88
|
+
multiplyMatrices,
|
|
89
|
+
reflectionMatrix,
|
|
90
|
+
rotationMatrix,
|
|
91
|
+
scaleMatrix,
|
|
92
|
+
transposeMatrix,
|
|
93
|
+
} from './mat3.ts';
|
|
94
|
+
export type { Vec3 } from './vec3.ts';
|
|
95
|
+
export {
|
|
96
|
+
addVectors,
|
|
97
|
+
collinear,
|
|
98
|
+
crossProduct,
|
|
99
|
+
dotProduct,
|
|
100
|
+
normalizeVector,
|
|
101
|
+
sameAxis,
|
|
102
|
+
scaleVector,
|
|
103
|
+
subtractVectors,
|
|
104
|
+
vectorDistance,
|
|
105
|
+
vectorNorm,
|
|
106
|
+
} from './vec3.ts';
|
|
107
|
+
export {
|
|
108
|
+
normalToCartesian,
|
|
109
|
+
normalToFractional,
|
|
110
|
+
toCartesian,
|
|
111
|
+
toFractional,
|
|
112
|
+
} from './latticeBasis.ts';
|
|
113
|
+
export { axisRod, faceOf } from './elementExtent.ts';
|
|
114
|
+
export type { AxisRod } from './elementExtent.ts';
|
|
115
|
+
export {
|
|
116
|
+
SUPERCELL_ATOM_CAP,
|
|
117
|
+
largestRepeatThatFits,
|
|
118
|
+
repeatCell,
|
|
119
|
+
repeatedAtomCount,
|
|
120
|
+
} from './cellStack.ts';
|
|
121
|
+
export type {
|
|
122
|
+
CrystalBonds,
|
|
123
|
+
CrystalPacking,
|
|
124
|
+
CrystalView,
|
|
125
|
+
CrystalViewOptions,
|
|
126
|
+
CrystalViewSettings,
|
|
127
|
+
} from './crystalView.ts';
|
|
128
|
+
export {
|
|
129
|
+
CELL_COUNT_RANGE,
|
|
130
|
+
CRYSTAL_BONDS,
|
|
131
|
+
CRYSTAL_PACKINGS,
|
|
132
|
+
DEFAULT_CRYSTAL_VIEW_SETTINGS,
|
|
133
|
+
crystalView,
|
|
134
|
+
} from './crystalView.ts';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An operation's name as a canvas can draw it.
|
|
3
|
+
*
|
|
4
|
+
* The site holds a raised part behind a caret — `C3^2`, `σv^′`, `C2^″(1)` —
|
|
5
|
+
* because the panels beside the view typeset what follows it above the line.
|
|
6
|
+
* A molstar label is plain text and typesets nothing, so the caret is drawn as
|
|
7
|
+
* itself: benzene's two-folds read `C2^′(1)` on the canvas while the list next
|
|
8
|
+
* to them reads C₂′(1). Raising the characters here is what makes the two
|
|
9
|
+
* agree, and it is the last step before the name leaves for the scene — the
|
|
10
|
+
* names the rest of the site matches on are untouched.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Raise what a caret marks, and drop the caret.
|
|
15
|
+
* @param label - The name as the site holds it.
|
|
16
|
+
* @returns The same name with each raised run set above the line: `C3²`,
|
|
17
|
+
* `σv′`, `C2″(1)`.
|
|
18
|
+
*/
|
|
19
|
+
export function plainName(label: string): string {
|
|
20
|
+
return label.replaceAll(RAISED, (_match, raised: string) => raise(raised));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A caret and the run it raises: digits, and the primes already drawn high. */
|
|
24
|
+
const RAISED = /\^(?<raised>[\d′″]+)/gu;
|
|
25
|
+
|
|
26
|
+
/** The digits, above the line. A prime is already a raised glyph. */
|
|
27
|
+
const ABOVE: Record<string, string> = {
|
|
28
|
+
0: '⁰',
|
|
29
|
+
1: '¹',
|
|
30
|
+
2: '²',
|
|
31
|
+
3: '³',
|
|
32
|
+
4: '⁴',
|
|
33
|
+
5: '⁵',
|
|
34
|
+
6: '⁶',
|
|
35
|
+
7: '⁷',
|
|
36
|
+
8: '⁸',
|
|
37
|
+
9: '⁹',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function raise(run: string): string {
|
|
41
|
+
let raised = '';
|
|
42
|
+
for (const character of run) raised += ABOVE[character] ?? character;
|
|
43
|
+
return raised;
|
|
44
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a vector crosses between the crystal basis and Cartesian ångström.
|
|
3
|
+
*
|
|
4
|
+
* There are four ways across and they are not interchangeable. A direction
|
|
5
|
+
* `[uvw]` is a direct-space vector and goes through `M`; a normal `(hkl)` is a
|
|
6
|
+
* reciprocal-space one and goes through `(M⁻¹)ᵀ`. The two agree in an
|
|
7
|
+
* orthogonal cell, so swapping them is only ever caught on a monoclinic or
|
|
8
|
+
* triclinic structure, with the mirror drawn at the wrong tilt.
|
|
9
|
+
*
|
|
10
|
+
* Naming them all together, once, is what stops the third caller writing a
|
|
11
|
+
* fifth matrix loop and picking the wrong transpose in it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { Lattice } from '../../crystal/core/symmetry/lattice.ts';
|
|
15
|
+
|
|
16
|
+
import type { Vec3 } from './vec3.ts';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A fractional point or direction, in Cartesian ångström — `M v`.
|
|
20
|
+
* @param lattice - The cell it is read in.
|
|
21
|
+
* @param point - Its fractional coordinates.
|
|
22
|
+
* @returns The same point, Cartesian ångström.
|
|
23
|
+
*/
|
|
24
|
+
export function toCartesian(lattice: Lattice, point: readonly number[]): Vec3 {
|
|
25
|
+
return applyMatrix(lattice.cartesian, point);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A Cartesian point or direction, in cell fractions — `M⁻¹ v`.
|
|
30
|
+
* @param lattice - The cell it is read in.
|
|
31
|
+
* @param point - Its Cartesian coordinates, ångström.
|
|
32
|
+
* @returns The same point, in fractions of the cell edges.
|
|
33
|
+
*/
|
|
34
|
+
export function toFractional(lattice: Lattice, point: readonly number[]): Vec3 {
|
|
35
|
+
return applyMatrix(lattice.fractional, point);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A normal `(hkl)` written in the crystal basis, as a Cartesian direction —
|
|
40
|
+
* `(M⁻¹)ᵀ v`.
|
|
41
|
+
* @param lattice - The cell it is read in.
|
|
42
|
+
* @param normal - The reciprocal-space normal `(hkl)`.
|
|
43
|
+
* @returns A Cartesian vector at right angles to the plane itself.
|
|
44
|
+
*/
|
|
45
|
+
export function normalToCartesian(
|
|
46
|
+
lattice: Lattice,
|
|
47
|
+
normal: readonly number[],
|
|
48
|
+
): Vec3 {
|
|
49
|
+
return applyTransposed(lattice.fractional, normal);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A Cartesian normal, as the covector that measures heights above the plane in
|
|
54
|
+
* cell fractions — `Mᵀ v`.
|
|
55
|
+
*
|
|
56
|
+
* `n · (x − p)` in ångström is that covector against `x − p` in fractions, so a
|
|
57
|
+
* height can be taken without leaving fractional coordinates. It is the inverse
|
|
58
|
+
* transpose of {@link normalToCartesian}, not its inverse.
|
|
59
|
+
* @param lattice - The cell it is read in.
|
|
60
|
+
* @param normal - A Cartesian plane normal.
|
|
61
|
+
* @returns The covector to dot fractional offsets against.
|
|
62
|
+
*/
|
|
63
|
+
export function normalToFractional(
|
|
64
|
+
lattice: Lattice,
|
|
65
|
+
normal: readonly number[],
|
|
66
|
+
): Vec3 {
|
|
67
|
+
return applyTransposed(lattice.cartesian, normal);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* `A v`.
|
|
72
|
+
* @param matrix - The 3×3 matrix, as its rows.
|
|
73
|
+
* @param point - The vector it is applied to.
|
|
74
|
+
* @returns The image.
|
|
75
|
+
*/
|
|
76
|
+
function applyMatrix(
|
|
77
|
+
matrix: ReadonlyArray<readonly number[]>,
|
|
78
|
+
point: readonly number[],
|
|
79
|
+
): Vec3 {
|
|
80
|
+
const image: number[] = [0, 0, 0];
|
|
81
|
+
for (let i = 0; i < 3; i++) {
|
|
82
|
+
let sum = 0;
|
|
83
|
+
for (let j = 0; j < 3; j++) {
|
|
84
|
+
sum += (matrix[i]?.[j] ?? 0) * (point[j] ?? 0);
|
|
85
|
+
}
|
|
86
|
+
image[i] = sum;
|
|
87
|
+
}
|
|
88
|
+
return [image[0] ?? 0, image[1] ?? 0, image[2] ?? 0];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* `Aᵀ v`, which is `A v` with the two indices swapped.
|
|
93
|
+
* @param matrix - The 3×3 matrix, as its rows.
|
|
94
|
+
* @param point - The vector its transpose is applied to.
|
|
95
|
+
* @returns The image.
|
|
96
|
+
*/
|
|
97
|
+
function applyTransposed(
|
|
98
|
+
matrix: ReadonlyArray<readonly number[]>,
|
|
99
|
+
point: readonly number[],
|
|
100
|
+
): Vec3 {
|
|
101
|
+
const image: number[] = [0, 0, 0];
|
|
102
|
+
for (let i = 0; i < 3; i++) {
|
|
103
|
+
let sum = 0;
|
|
104
|
+
for (let j = 0; j < 3; j++) {
|
|
105
|
+
sum += (matrix[j]?.[i] ?? 0) * (point[j] ?? 0);
|
|
106
|
+
}
|
|
107
|
+
image[i] = sum;
|
|
108
|
+
}
|
|
109
|
+
return [image[0] ?? 0, image[1] ?? 0, image[2] ?? 0];
|
|
110
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Vec3 } from './vec3.ts';
|
|
2
|
+
|
|
3
|
+
/** A 3×3 Cartesian matrix, as its three rows. */
|
|
4
|
+
export type Mat3 = readonly [Vec3, Vec3, Vec3];
|
|
5
|
+
|
|
6
|
+
/** The identity. */
|
|
7
|
+
export const IDENTITY_MATRIX: Mat3 = [
|
|
8
|
+
[1, 0, 0],
|
|
9
|
+
[0, 1, 0],
|
|
10
|
+
[0, 0, 1],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** The inversion, −I. */
|
|
14
|
+
export const INVERSION_MATRIX: Mat3 = [
|
|
15
|
+
[-1, 0, 0],
|
|
16
|
+
[0, -1, 0],
|
|
17
|
+
[0, 0, -1],
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* a · b, so that `applyMatrix(multiplyMatrices(a, b), v)` is a applied after b.
|
|
22
|
+
* @param a - The matrix applied last.
|
|
23
|
+
* @param b - The matrix applied first.
|
|
24
|
+
* @returns The product.
|
|
25
|
+
*/
|
|
26
|
+
export function multiplyMatrices(a: Mat3, b: Mat3): Mat3 {
|
|
27
|
+
return [multiplyRow(a[0], b), multiplyRow(a[1], b), multiplyRow(a[2], b)];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* M · v.
|
|
32
|
+
* @param matrix - The matrix.
|
|
33
|
+
* @param vector - The vector it is applied to.
|
|
34
|
+
* @returns The transformed vector.
|
|
35
|
+
*/
|
|
36
|
+
export function applyMatrix(matrix: Mat3, vector: Vec3): Vec3 {
|
|
37
|
+
return [
|
|
38
|
+
matrix[0][0] * vector[0] +
|
|
39
|
+
matrix[0][1] * vector[1] +
|
|
40
|
+
matrix[0][2] * vector[2],
|
|
41
|
+
matrix[1][0] * vector[0] +
|
|
42
|
+
matrix[1][1] * vector[1] +
|
|
43
|
+
matrix[1][2] * vector[2],
|
|
44
|
+
matrix[2][0] * vector[0] +
|
|
45
|
+
matrix[2][1] * vector[1] +
|
|
46
|
+
matrix[2][2] * vector[2],
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Mᵀ, which is M⁻¹ for the orthogonal matrix of any symmetry operation.
|
|
52
|
+
* @param matrix - The matrix.
|
|
53
|
+
* @returns Its transpose.
|
|
54
|
+
*/
|
|
55
|
+
export function transposeMatrix(matrix: Mat3): Mat3 {
|
|
56
|
+
return [
|
|
57
|
+
[matrix[0][0], matrix[1][0], matrix[2][0]],
|
|
58
|
+
[matrix[0][1], matrix[1][1], matrix[2][1]],
|
|
59
|
+
[matrix[0][2], matrix[1][2], matrix[2][2]],
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* det M: +1 for a proper operation, −1 for an improper one.
|
|
65
|
+
* @param matrix - The matrix.
|
|
66
|
+
* @returns Its determinant.
|
|
67
|
+
*/
|
|
68
|
+
export function matrixDeterminant(matrix: Mat3): number {
|
|
69
|
+
return (
|
|
70
|
+
matrix[0][0] * (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1]) -
|
|
71
|
+
matrix[0][1] * (matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0]) +
|
|
72
|
+
matrix[0][2] * (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0])
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* tr M, which is `±1 + 2cos θ` for a symmetry operation.
|
|
78
|
+
* @param matrix - The matrix.
|
|
79
|
+
* @returns Its trace.
|
|
80
|
+
*/
|
|
81
|
+
export function matrixTrace(matrix: Mat3): number {
|
|
82
|
+
return matrix[0][0] + matrix[1][1] + matrix[2][2];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* M · factor.
|
|
87
|
+
* @param matrix - The matrix.
|
|
88
|
+
* @param factor - The scalar every entry is multiplied by.
|
|
89
|
+
* @returns The scaled matrix.
|
|
90
|
+
*/
|
|
91
|
+
export function scaleMatrix(matrix: Mat3, factor: number): Mat3 {
|
|
92
|
+
return [
|
|
93
|
+
[matrix[0][0] * factor, matrix[0][1] * factor, matrix[0][2] * factor],
|
|
94
|
+
[matrix[1][0] * factor, matrix[1][1] * factor, matrix[1][2] * factor],
|
|
95
|
+
[matrix[2][0] * factor, matrix[2][1] * factor, matrix[2][2] * factor],
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* ‖a − b‖_F, the distance two operation matrices are compared with.
|
|
101
|
+
* @param a - The first matrix.
|
|
102
|
+
* @param b - The second matrix.
|
|
103
|
+
* @returns The Frobenius norm of their difference.
|
|
104
|
+
*/
|
|
105
|
+
export function matrixDistance(a: Mat3, b: Mat3): number {
|
|
106
|
+
let sum = 0;
|
|
107
|
+
for (let i = 0; i < 3; i++) {
|
|
108
|
+
const rowA = a[i] as Vec3;
|
|
109
|
+
const rowB = b[i] as Vec3;
|
|
110
|
+
for (let j = 0; j < 3; j++) {
|
|
111
|
+
const difference = (rowA[j] as number) - (rowB[j] as number);
|
|
112
|
+
sum += difference * difference;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return Math.sqrt(sum);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The rotation by `angle` radians about the unit vector `axis`, right-handed,
|
|
120
|
+
* from Rodrigues' formula `R = cos θ I + sin θ [n̂]ₓ + (1 − cos θ) n̂ n̂ᵀ`.
|
|
121
|
+
* @param axis - The unit vector rotated about.
|
|
122
|
+
* @param angle - The angle, in radians.
|
|
123
|
+
* @returns The rotation matrix.
|
|
124
|
+
*/
|
|
125
|
+
export function rotationMatrix(axis: Vec3, angle: number): Mat3 {
|
|
126
|
+
const [x, y, z] = axis;
|
|
127
|
+
const c = Math.cos(angle);
|
|
128
|
+
const s = Math.sin(angle);
|
|
129
|
+
const t = 1 - c;
|
|
130
|
+
return [
|
|
131
|
+
[t * x * x + c, t * x * y - s * z, t * x * z + s * y],
|
|
132
|
+
[t * x * y + s * z, t * y * y + c, t * y * z - s * x],
|
|
133
|
+
[t * x * z - s * y, t * y * z + s * x, t * z * z + c],
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The reflection `I − 2 n̂ n̂ᵀ` in the plane through the origin with unit normal `normal`.
|
|
139
|
+
* @param normal - The unit normal of the mirror plane.
|
|
140
|
+
* @returns The reflection matrix.
|
|
141
|
+
*/
|
|
142
|
+
export function reflectionMatrix(normal: Vec3): Mat3 {
|
|
143
|
+
const [x, y, z] = normal;
|
|
144
|
+
return [
|
|
145
|
+
[1 - 2 * x * x, -2 * x * y, -2 * x * z],
|
|
146
|
+
[-2 * x * y, 1 - 2 * y * y, -2 * y * z],
|
|
147
|
+
[-2 * x * z, -2 * y * z, 1 - 2 * z * z],
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* One row of a · b.
|
|
153
|
+
* @param row - The row of a.
|
|
154
|
+
* @param b - The right-hand matrix.
|
|
155
|
+
* @returns That row of the product.
|
|
156
|
+
*/
|
|
157
|
+
function multiplyRow(row: Vec3, b: Mat3): Vec3 {
|
|
158
|
+
return [
|
|
159
|
+
row[0] * b[0][0] + row[1] * b[1][0] + row[2] * b[2][0],
|
|
160
|
+
row[0] * b[0][1] + row[1] * b[1][1] + row[2] * b[2][1],
|
|
161
|
+
row[0] * b[0][2] + row[1] * b[1][2] + row[2] * b[2][2],
|
|
162
|
+
];
|
|
163
|
+
}
|