react-cheminfo 0.135.0 → 0.136.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/lib/crystal/core/cellAtoms.d.ts +43 -0
  2. package/lib/crystal/core/cellAtoms.d.ts.map +1 -0
  3. package/lib/crystal/core/cellAtoms.js +70 -0
  4. package/lib/crystal/core/cellAtoms.js.map +1 -0
  5. package/lib/crystal/core/index.d.ts +2 -0
  6. package/lib/crystal/core/index.d.ts.map +1 -1
  7. package/lib/crystal/core/index.js +1 -0
  8. package/lib/crystal/core/index.js.map +1 -1
  9. package/lib/crystal/core/molecules.d.ts.map +1 -1
  10. package/lib/crystal/core/molecules.js +6 -40
  11. package/lib/crystal/core/molecules.js.map +1 -1
  12. package/lib/crystal3d/core/cellClip.d.ts +46 -0
  13. package/lib/crystal3d/core/cellClip.d.ts.map +1 -0
  14. package/lib/crystal3d/core/cellClip.js +198 -0
  15. package/lib/crystal3d/core/cellClip.js.map +1 -0
  16. package/lib/crystal3d/core/cellGeometry.d.ts +63 -0
  17. package/lib/crystal3d/core/cellGeometry.d.ts.map +1 -0
  18. package/lib/crystal3d/core/cellGeometry.js +153 -0
  19. package/lib/crystal3d/core/cellGeometry.js.map +1 -0
  20. package/lib/crystal3d/core/cellStack.d.ts +51 -0
  21. package/lib/crystal3d/core/cellStack.d.ts.map +1 -0
  22. package/lib/crystal3d/core/cellStack.js +79 -0
  23. package/lib/crystal3d/core/cellStack.js.map +1 -0
  24. package/lib/crystal3d/core/crystalView.d.ts +71 -0
  25. package/lib/crystal3d/core/crystalView.d.ts.map +1 -0
  26. package/lib/crystal3d/core/crystalView.js +48 -0
  27. package/lib/crystal3d/core/crystalView.js.map +1 -0
  28. package/lib/crystal3d/core/drawingSet.d.ts +31 -0
  29. package/lib/crystal3d/core/drawingSet.d.ts.map +1 -0
  30. package/lib/crystal3d/core/drawingSet.js +63 -0
  31. package/lib/crystal3d/core/drawingSet.js.map +1 -0
  32. package/lib/crystal3d/core/elementDrawing.d.ts +50 -0
  33. package/lib/crystal3d/core/elementDrawing.d.ts.map +1 -0
  34. package/lib/crystal3d/core/elementDrawing.js +100 -0
  35. package/lib/crystal3d/core/elementDrawing.js.map +1 -0
  36. package/lib/crystal3d/core/elementExtent.d.ts +42 -0
  37. package/lib/crystal3d/core/elementExtent.d.ts.map +1 -0
  38. package/lib/crystal3d/core/elementExtent.js +56 -0
  39. package/lib/crystal3d/core/elementExtent.js.map +1 -0
  40. package/lib/crystal3d/core/elementLabels.d.ts +31 -0
  41. package/lib/crystal3d/core/elementLabels.d.ts.map +1 -0
  42. package/lib/crystal3d/core/elementLabels.js +99 -0
  43. package/lib/crystal3d/core/elementLabels.js.map +1 -0
  44. package/lib/crystal3d/core/elementShapes.d.ts +43 -0
  45. package/lib/crystal3d/core/elementShapes.d.ts.map +1 -0
  46. package/lib/crystal3d/core/elementShapes.js +115 -0
  47. package/lib/crystal3d/core/elementShapes.js.map +1 -0
  48. package/lib/crystal3d/core/frame.d.ts +36 -0
  49. package/lib/crystal3d/core/frame.d.ts.map +1 -0
  50. package/lib/crystal3d/core/frame.js +35 -0
  51. package/lib/crystal3d/core/frame.js.map +1 -0
  52. package/lib/crystal3d/core/framing.d.ts +41 -0
  53. package/lib/crystal3d/core/framing.d.ts.map +1 -0
  54. package/lib/crystal3d/core/framing.js +79 -0
  55. package/lib/crystal3d/core/framing.js.map +1 -0
  56. package/lib/crystal3d/core/index.d.ts +42 -0
  57. package/lib/crystal3d/core/index.d.ts.map +1 -0
  58. package/lib/crystal3d/core/index.js +29 -0
  59. package/lib/crystal3d/core/index.js.map +1 -0
  60. package/lib/crystal3d/core/labelText.d.ts +19 -0
  61. package/lib/crystal3d/core/labelText.d.ts.map +1 -0
  62. package/lib/crystal3d/core/labelText.js +42 -0
  63. package/lib/crystal3d/core/labelText.js.map +1 -0
  64. package/lib/crystal3d/core/latticeBasis.d.ts +49 -0
  65. package/lib/crystal3d/core/latticeBasis.d.ts.map +1 -0
  66. package/lib/crystal3d/core/latticeBasis.js +89 -0
  67. package/lib/crystal3d/core/latticeBasis.js.map +1 -0
  68. package/lib/crystal3d/core/mat3.d.ts +68 -0
  69. package/lib/crystal3d/core/mat3.d.ts.map +1 -0
  70. package/lib/crystal3d/core/mat3.js +146 -0
  71. package/lib/crystal3d/core/mat3.js.map +1 -0
  72. package/lib/crystal3d/core/operationMatrix.d.ts +44 -0
  73. package/lib/crystal3d/core/operationMatrix.d.ts.map +1 -0
  74. package/lib/crystal3d/core/operationMatrix.js +172 -0
  75. package/lib/crystal3d/core/operationMatrix.js.map +1 -0
  76. package/lib/crystal3d/core/orientation.d.ts +62 -0
  77. package/lib/crystal3d/core/orientation.d.ts.map +1 -0
  78. package/lib/crystal3d/core/orientation.js +166 -0
  79. package/lib/crystal3d/core/orientation.js.map +1 -0
  80. package/lib/crystal3d/core/palette.d.ts +24 -0
  81. package/lib/crystal3d/core/palette.d.ts.map +1 -0
  82. package/lib/crystal3d/core/palette.js +34 -0
  83. package/lib/crystal3d/core/palette.js.map +1 -0
  84. package/lib/crystal3d/core/primitives.d.ts +133 -0
  85. package/lib/crystal3d/core/primitives.d.ts.map +1 -0
  86. package/lib/crystal3d/core/primitives.js +80 -0
  87. package/lib/crystal3d/core/primitives.js.map +1 -0
  88. package/lib/crystal3d/core/structureText.d.ts +20 -0
  89. package/lib/crystal3d/core/structureText.d.ts.map +1 -0
  90. package/lib/crystal3d/core/structureText.js +37 -0
  91. package/lib/crystal3d/core/structureText.js.map +1 -0
  92. package/lib/crystal3d/core/supercell.d.ts +20 -0
  93. package/lib/crystal3d/core/supercell.d.ts.map +1 -0
  94. package/lib/crystal3d/core/supercell.js +35 -0
  95. package/lib/crystal3d/core/supercell.js.map +1 -0
  96. package/lib/crystal3d/core/types.d.ts +166 -0
  97. package/lib/crystal3d/core/types.d.ts.map +1 -0
  98. package/lib/crystal3d/core/types.js +10 -0
  99. package/lib/crystal3d/core/types.js.map +1 -0
  100. package/lib/crystal3d/core/vec3.d.ts +75 -0
  101. package/lib/crystal3d/core/vec3.d.ts.map +1 -0
  102. package/lib/crystal3d/core/vec3.js +119 -0
  103. package/lib/crystal3d/core/vec3.js.map +1 -0
  104. package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +52 -0
  105. package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -0
  106. package/lib/crystal3d/ui/CrystalCanvas3D.js +242 -0
  107. package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -0
  108. package/lib/crystal3d/ui/CrystalStructureView.d.ts +17 -0
  109. package/lib/crystal3d/ui/CrystalStructureView.d.ts.map +1 -0
  110. package/lib/crystal3d/ui/CrystalStructureView.js +76 -0
  111. package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -0
  112. package/lib/crystal3d/ui/CrystalStructureViewer.d.ts +22 -0
  113. package/lib/crystal3d/ui/CrystalStructureViewer.d.ts.map +1 -0
  114. package/lib/crystal3d/ui/CrystalStructureViewer.js +29 -0
  115. package/lib/crystal3d/ui/CrystalStructureViewer.js.map +1 -0
  116. package/lib/crystal3d/ui/CrystalViewControls.d.ts +25 -0
  117. package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -0
  118. package/lib/crystal3d/ui/CrystalViewControls.js +22 -0
  119. package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -0
  120. package/lib/crystal3d/ui/CrystalViewer3D.d.ts +72 -0
  121. package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -0
  122. package/lib/crystal3d/ui/CrystalViewer3D.js +70 -0
  123. package/lib/crystal3d/ui/CrystalViewer3D.js.map +1 -0
  124. package/lib/crystal3d/ui/crystalScene.d.ts +91 -0
  125. package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -0
  126. package/lib/crystal3d/ui/crystalScene.js +10 -0
  127. package/lib/crystal3d/ui/crystalScene.js.map +1 -0
  128. package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +52 -0
  129. package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -0
  130. package/lib/crystal3d/ui/crystalStructureViewerProps.js +2 -0
  131. package/lib/crystal3d/ui/crystalStructureViewerProps.js.map +1 -0
  132. package/lib/crystal3d/ui/index.d.ts +16 -0
  133. package/lib/crystal3d/ui/index.d.ts.map +1 -0
  134. package/lib/crystal3d/ui/index.js +12 -0
  135. package/lib/crystal3d/ui/index.js.map +1 -0
  136. package/lib/crystal3d/ui/useCrystalCaption.d.ts +14 -0
  137. package/lib/crystal3d/ui/useCrystalCaption.d.ts.map +1 -0
  138. package/lib/crystal3d/ui/useCrystalCaption.js +32 -0
  139. package/lib/crystal3d/ui/useCrystalCaption.js.map +1 -0
  140. package/lib/crystal3d/viewer/animate.d.ts +49 -0
  141. package/lib/crystal3d/viewer/animate.d.ts.map +1 -0
  142. package/lib/crystal3d/viewer/animate.js +83 -0
  143. package/lib/crystal3d/viewer/animate.js.map +1 -0
  144. package/lib/crystal3d/viewer/camera.d.ts +44 -0
  145. package/lib/crystal3d/viewer/camera.d.ts.map +1 -0
  146. package/lib/crystal3d/viewer/camera.js +103 -0
  147. package/lib/crystal3d/viewer/camera.js.map +1 -0
  148. package/lib/crystal3d/viewer/index.d.ts +13 -0
  149. package/lib/crystal3d/viewer/index.d.ts.map +1 -0
  150. package/lib/crystal3d/viewer/index.js +8 -0
  151. package/lib/crystal3d/viewer/index.js.map +1 -0
  152. package/lib/crystal3d/viewer/layerRegistry.d.ts +24 -0
  153. package/lib/crystal3d/viewer/layerRegistry.d.ts.map +1 -0
  154. package/lib/crystal3d/viewer/layerRegistry.js +39 -0
  155. package/lib/crystal3d/viewer/layerRegistry.js.map +1 -0
  156. package/lib/crystal3d/viewer/meshPrimitives.d.ts +13 -0
  157. package/lib/crystal3d/viewer/meshPrimitives.d.ts.map +1 -0
  158. package/lib/crystal3d/viewer/meshPrimitives.js +76 -0
  159. package/lib/crystal3d/viewer/meshPrimitives.js.map +1 -0
  160. package/lib/crystal3d/viewer/plugin.d.ts +133 -0
  161. package/lib/crystal3d/viewer/plugin.d.ts.map +1 -0
  162. package/lib/crystal3d/viewer/plugin.js +181 -0
  163. package/lib/crystal3d/viewer/plugin.js.map +1 -0
  164. package/lib/crystal3d/viewer/renderCell.d.ts +43 -0
  165. package/lib/crystal3d/viewer/renderCell.d.ts.map +1 -0
  166. package/lib/crystal3d/viewer/renderCell.js +53 -0
  167. package/lib/crystal3d/viewer/renderCell.js.map +1 -0
  168. package/lib/crystal3d/viewer/renderElements.d.ts +54 -0
  169. package/lib/crystal3d/viewer/renderElements.d.ts.map +1 -0
  170. package/lib/crystal3d/viewer/renderElements.js +77 -0
  171. package/lib/crystal3d/viewer/renderElements.js.map +1 -0
  172. package/lib/crystal3d/viewer/renderStructure.d.ts +55 -0
  173. package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -0
  174. package/lib/crystal3d/viewer/renderStructure.js +103 -0
  175. package/lib/crystal3d/viewer/renderStructure.js.map +1 -0
  176. package/lib/crystal3d/viewer/sceneParts.d.ts +32 -0
  177. package/lib/crystal3d/viewer/sceneParts.d.ts.map +1 -0
  178. package/lib/crystal3d/viewer/sceneParts.js +77 -0
  179. package/lib/crystal3d/viewer/sceneParts.js.map +1 -0
  180. package/lib/crystal3d/viewer/shapeLayer.d.ts +41 -0
  181. package/lib/crystal3d/viewer/shapeLayer.d.ts.map +1 -0
  182. package/lib/crystal3d/viewer/shapeLayer.js +57 -0
  183. package/lib/crystal3d/viewer/shapeLayer.js.map +1 -0
  184. package/lib/crystal3d/viewer/textLayer.d.ts +21 -0
  185. package/lib/crystal3d/viewer/textLayer.d.ts.map +1 -0
  186. package/lib/crystal3d/viewer/textLayer.js +59 -0
  187. package/lib/crystal3d/viewer/textLayer.js.map +1 -0
  188. package/lib/crystal3d/viewer/viewer.d.ts +110 -0
  189. package/lib/crystal3d/viewer/viewer.d.ts.map +1 -0
  190. package/lib/crystal3d/viewer/viewer.js +157 -0
  191. package/lib/crystal3d/viewer/viewer.js.map +1 -0
  192. package/lib/crystal3d.d.ts +12 -0
  193. package/lib/crystal3d.d.ts.map +1 -0
  194. package/lib/crystal3d.js +12 -0
  195. package/lib/crystal3d.js.map +1 -0
  196. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  197. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  198. package/lib/locales/de.json +19 -1
  199. package/lib/locales/en.json +19 -1
  200. package/lib/locales/es.json +19 -1
  201. package/lib/locales/fr.json +19 -1
  202. package/lib/locales/it.json +19 -1
  203. package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
  204. package/lib/molecule3d/ui/MoleculeCanvas3D.js +16 -27
  205. package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
  206. package/lib/molstar/bonds/bondRule.d.ts +16 -0
  207. package/lib/molstar/bonds/bondRule.d.ts.map +1 -0
  208. package/lib/molstar/bonds/bondRule.js +23 -0
  209. package/lib/molstar/bonds/bondRule.js.map +1 -0
  210. package/lib/molstar/bonds/index.d.ts +9 -0
  211. package/lib/molstar/bonds/index.d.ts.map +1 -0
  212. package/lib/molstar/bonds/index.js +9 -0
  213. package/lib/molstar/bonds/index.js.map +1 -0
  214. package/lib/molstar/ui/MolstarToolbar.d.ts +47 -0
  215. package/lib/molstar/ui/MolstarToolbar.d.ts.map +1 -0
  216. package/lib/molstar/ui/MolstarToolbar.js +28 -0
  217. package/lib/molstar/ui/MolstarToolbar.js.map +1 -0
  218. package/lib/molstar/ui/index.d.ts +10 -0
  219. package/lib/molstar/ui/index.d.ts.map +1 -0
  220. package/lib/molstar/ui/index.js +8 -0
  221. package/lib/molstar/ui/index.js.map +1 -0
  222. package/lib/molstar/ui/useMolstarTools.d.ts +63 -0
  223. package/lib/molstar/ui/useMolstarTools.d.ts.map +1 -0
  224. package/lib/molstar/ui/useMolstarTools.js +36 -0
  225. package/lib/molstar/ui/useMolstarTools.js.map +1 -0
  226. package/package.json +2 -1
  227. package/src/crystal/core/cellAtoms.ts +106 -0
  228. package/src/crystal/core/index.ts +2 -0
  229. package/src/crystal/core/molecules.ts +7 -44
  230. package/src/crystal3d/core/cellClip.ts +229 -0
  231. package/src/crystal3d/core/cellGeometry.ts +193 -0
  232. package/src/crystal3d/core/cellStack.ts +87 -0
  233. package/src/crystal3d/core/crystalView.ts +114 -0
  234. package/src/crystal3d/core/drawingSet.ts +71 -0
  235. package/src/crystal3d/core/elementDrawing.ts +147 -0
  236. package/src/crystal3d/core/elementExtent.ts +81 -0
  237. package/src/crystal3d/core/elementLabels.ts +130 -0
  238. package/src/crystal3d/core/elementShapes.ts +141 -0
  239. package/src/crystal3d/core/frame.ts +56 -0
  240. package/src/crystal3d/core/framing.ts +101 -0
  241. package/src/crystal3d/core/index.ts +132 -0
  242. package/src/crystal3d/core/labelText.ts +44 -0
  243. package/src/crystal3d/core/latticeBasis.ts +110 -0
  244. package/src/crystal3d/core/mat3.ts +163 -0
  245. package/src/crystal3d/core/operationMatrix.ts +255 -0
  246. package/src/crystal3d/core/orientation.ts +229 -0
  247. package/src/crystal3d/core/palette.ts +43 -0
  248. package/src/crystal3d/core/primitives.ts +183 -0
  249. package/src/crystal3d/core/structureText.ts +43 -0
  250. package/src/crystal3d/core/supercell.ts +40 -0
  251. package/src/crystal3d/core/types.ts +186 -0
  252. package/src/crystal3d/core/vec3.ts +127 -0
  253. package/src/crystal3d/ui/CrystalCanvas3D.tsx +384 -0
  254. package/src/crystal3d/ui/CrystalStructureView.tsx +148 -0
  255. package/src/crystal3d/ui/CrystalStructureViewer.tsx +39 -0
  256. package/src/crystal3d/ui/CrystalViewControls.tsx +100 -0
  257. package/src/crystal3d/ui/CrystalViewer3D.tsx +183 -0
  258. package/src/crystal3d/ui/crystalScene.ts +100 -0
  259. package/src/crystal3d/ui/crystalStructureViewerProps.ts +54 -0
  260. package/src/crystal3d/ui/index.ts +20 -0
  261. package/src/crystal3d/ui/useCrystalCaption.ts +38 -0
  262. package/src/crystal3d/viewer/animate.ts +113 -0
  263. package/src/crystal3d/viewer/camera.ts +139 -0
  264. package/src/crystal3d/viewer/index.ts +13 -0
  265. package/src/crystal3d/viewer/layerRegistry.ts +47 -0
  266. package/src/crystal3d/viewer/meshPrimitives.ts +102 -0
  267. package/src/crystal3d/viewer/plugin.ts +258 -0
  268. package/src/crystal3d/viewer/renderCell.ts +98 -0
  269. package/src/crystal3d/viewer/renderElements.ts +121 -0
  270. package/src/crystal3d/viewer/renderStructure.ts +144 -0
  271. package/src/crystal3d/viewer/sceneParts.ts +119 -0
  272. package/src/crystal3d/viewer/shapeLayer.ts +108 -0
  273. package/src/crystal3d/viewer/textLayer.ts +85 -0
  274. package/src/crystal3d/viewer/viewer.ts +207 -0
  275. package/src/crystal3d.ts +12 -0
  276. package/src/locales/de.json +19 -1
  277. package/src/locales/en.json +19 -1
  278. package/src/locales/es.json +19 -1
  279. package/src/locales/fr.json +19 -1
  280. package/src/locales/it.json +19 -1
  281. package/src/molecule3d/ui/MoleculeCanvas3D.tsx +45 -71
  282. package/src/molstar/bonds/bondRule.ts +34 -0
  283. package/src/molstar/bonds/index.ts +9 -0
  284. package/src/molstar/ui/MolstarToolbar.tsx +103 -0
  285. package/src/molstar/ui/index.ts +14 -0
  286. package/src/molstar/ui/useMolstarTools.ts +98 -0
  287. package/styles/chrome.css +90 -0
@@ -0,0 +1,100 @@
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
+ import { spacedLabels } from "./elementLabels.js";
17
+ import { arrow, planeFace, rodEnds } from "./elementShapes.js";
18
+ import { perpendicularTo } from "./frame.js";
19
+ import { plainName } from "./labelText.js";
20
+ import { drawingColour } from "./palette.js";
21
+ import { resolveElementStyle } from "./primitives.js";
22
+ import { addVectors, normalizeVector, scaleVector, vectorNorm, } from "./vec3.js";
23
+ /**
24
+ * Turn the drawings into groups, in the order they were given.
25
+ * @param drawings - The elements to draw.
26
+ * @param options - Sizes, and whether the labels are drawn.
27
+ * @param options.style - Sizes of the shapes, over the defaults.
28
+ * @param options.labels - Whether the labels are drawn; true by default.
29
+ * @returns One group per drawing.
30
+ */
31
+ export function elementGroups(drawings, options = {}) {
32
+ const style = resolveElementStyle(options.style);
33
+ const withLabels = options.labels ?? true;
34
+ const groups = [];
35
+ const taken = [];
36
+ for (const drawing of drawings) {
37
+ groups.push({
38
+ id: drawing.id,
39
+ label: plainName(drawing.label),
40
+ colour: drawingColour(drawing.kind, drawing.colour),
41
+ primitives: drawingPrimitives(drawing, style),
42
+ labels: withLabels ? spacedLabels(drawing, style, taken) : [],
43
+ });
44
+ }
45
+ return groups;
46
+ }
47
+ /**
48
+ * The shapes one element is drawn as.
49
+ * @param drawing - The element.
50
+ * @param style - Sizes; the defaults are used for anything left out.
51
+ * @returns Its shapes, in drawing order.
52
+ */
53
+ export function drawingPrimitives(drawing, style = {}) {
54
+ const sizes = resolveElementStyle(style);
55
+ switch (drawing.kind) {
56
+ case 'inversion': {
57
+ return [
58
+ { shape: 'sphere', centre: drawing.point, radius: sizes.centreRadius },
59
+ ];
60
+ }
61
+ case 'mirror': {
62
+ return planeFace(drawing, sizes);
63
+ }
64
+ case 'glide': {
65
+ const length = vectorNorm(drawing.glide);
66
+ return [
67
+ ...planeFace(drawing, sizes),
68
+ ...arrow(drawing.point, drawing.glide, length, sizes),
69
+ ];
70
+ }
71
+ case 'rotoinversion': {
72
+ const [start, end] = rodEnds(drawing.point, drawing.direction, drawing.length);
73
+ return [
74
+ {
75
+ shape: 'dashes',
76
+ start,
77
+ end,
78
+ radius: sizes.axisRadius,
79
+ segments: sizes.dashSegments,
80
+ },
81
+ { shape: 'sphere', centre: drawing.point, radius: sizes.centreRadius },
82
+ ];
83
+ }
84
+ case 'screw': {
85
+ const [start, end] = rodEnds(drawing.point, drawing.direction, drawing.length);
86
+ const unit = normalizeVector(drawing.direction);
87
+ const beside = addVectors(drawing.point, scaleVector(perpendicularTo(unit), sizes.arrowOffset * sizes.axisRadius));
88
+ return [
89
+ { shape: 'rod', start, end, radius: sizes.axisRadius },
90
+ ...arrow(beside, unit, drawing.pitch, sizes),
91
+ ];
92
+ }
93
+ case 'rotation': {
94
+ const [start, end] = rodEnds(drawing.point, drawing.direction, drawing.length);
95
+ return [{ shape: 'rod', start, end, radius: sizes.axisRadius }];
96
+ }
97
+ // no default
98
+ }
99
+ }
100
+ //# sourceMappingURL=elementDrawing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementDrawing.js","sourceRoot":"","sources":["../../../src/crystal3d/core/elementDrawing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACL,UAAU,EACV,eAAe,EACf,WAAW,EACX,UAAU,GACX,MAAM,WAAW,CAAC;AAgBnB;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAoC,EACpC,UAAsD,EAAE;IAExD,MAAM,KAAK,GAAG,mBAAmB,CAAC,OAAO,CA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U,CAAC,CAAC,CAAC;YAChB,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,OAAO,CAC1B,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,MAAM,CACf,CAAC;YACF,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;QAClE,CAAC;QACD,aAAa;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
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
+ import type { Lattice } from '../../crystal/core/symmetry/lattice.ts';
11
+ import type { Point3 } from './types.ts';
12
+ /** Where an axis rod starts, which way it runs and how long it is. */
13
+ export interface AxisRod {
14
+ readonly point: Point3;
15
+ readonly direction: Point3;
16
+ readonly length: number;
17
+ }
18
+ /**
19
+ * The rod an axis is drawn as: the piece inside the cell when the caller asked
20
+ * for that, and a rod of `length` centred on the element's own point when it
21
+ * did not, or when the axis misses the box.
22
+ * @param lattice - The cell it is cut against.
23
+ * @param point - A point of the axis, Cartesian ångström.
24
+ * @param direction - Its direction, Cartesian.
25
+ * @param length - The rod to draw when it is not clipped, ångström.
26
+ * @param clip - Whether to cut it off at the cell.
27
+ * @returns The rod, centred on its own middle.
28
+ */
29
+ export declare function axisRod(lattice: Lattice, point: Point3, direction: Point3, length: number, clip: boolean): AxisRod;
30
+ /**
31
+ * The polygon a plane cuts out of the cell, when the caller asked for it.
32
+ * @param lattice - The cell it is cut against.
33
+ * @param point - A point of the plane, Cartesian ångström.
34
+ * @param normal - Its normal, Cartesian.
35
+ * @param clip - Whether to cut it to the cell.
36
+ * @returns An `outline` to draw the plane between, or nothing, which leaves the
37
+ * plane its square.
38
+ */
39
+ export declare function faceOf(lattice: Lattice, point: Point3, normal: Point3, clip: boolean): {
40
+ outline?: readonly Point3[];
41
+ };
42
+ //# sourceMappingURL=elementExtent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementExtent.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/core/elementExtent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAGtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAQzC,sEAAsE;AACtE,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACrB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GACZ,OAAO,CAYT;AAED;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CACpB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GACZ;IAAE,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAIjC"}
@@ -0,0 +1,56 @@
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
+ import { cellSection, clipLineToCell } from "./cellClip.js";
11
+ import { addVectors, scaleVector, subtractVectors, vectorNorm, } from "./vec3.js";
12
+ /**
13
+ * The rod an axis is drawn as: the piece inside the cell when the caller asked
14
+ * for that, and a rod of `length` centred on the element's own point when it
15
+ * did not, or when the axis misses the box.
16
+ * @param lattice - The cell it is cut against.
17
+ * @param point - A point of the axis, Cartesian ångström.
18
+ * @param direction - Its direction, Cartesian.
19
+ * @param length - The rod to draw when it is not clipped, ångström.
20
+ * @param clip - Whether to cut it off at the cell.
21
+ * @returns The rod, centred on its own middle.
22
+ */
23
+ export function axisRod(lattice, point, direction, length, clip) {
24
+ if (!clip)
25
+ return { point, direction, length };
26
+ const segment = clipLineToCell(lattice, point, direction);
27
+ if (segment === null)
28
+ return { point, direction, length };
29
+ const span = subtractVectors(segment.end, segment.start);
30
+ const reach = vectorNorm(span);
31
+ if (reach < MINIMUM_ROD)
32
+ return { point, direction, length };
33
+ return {
34
+ point: addVectors(segment.start, scaleVector(span, 0.5)),
35
+ direction,
36
+ length: reach,
37
+ };
38
+ }
39
+ /**
40
+ * The polygon a plane cuts out of the cell, when the caller asked for it.
41
+ * @param lattice - The cell it is cut against.
42
+ * @param point - A point of the plane, Cartesian ångström.
43
+ * @param normal - Its normal, Cartesian.
44
+ * @param clip - Whether to cut it to the cell.
45
+ * @returns An `outline` to draw the plane between, or nothing, which leaves the
46
+ * plane its square.
47
+ */
48
+ export function faceOf(lattice, point, normal, clip) {
49
+ if (!clip)
50
+ return {};
51
+ const outline = cellSection(lattice, point, normal);
52
+ return outline.length < 3 ? {} : { outline };
53
+ }
54
+ /** Below this, ångström, a line only grazes a corner of the cell. */
55
+ const MINIMUM_ROD = 1e-6;
56
+ //# sourceMappingURL=elementExtent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementExtent.js","sourceRoot":"","sources":["../../../src/crystal3d/core/elementExtent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,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AI,CAAC"}
@@ -0,0 +1,31 @@
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
+ import type { ElementStyle, ResolvedElementStyle, TextItem } from './primitives.ts';
10
+ import type { Point3, SymmetryDrawing } from './types.ts';
11
+ /**
12
+ * Where one element's text floats, and what it reads.
13
+ * @param drawing - The element.
14
+ * @param style - Sizes; the defaults are used for anything left out.
15
+ * @returns One line of text, or none when the element carries no label.
16
+ */
17
+ export declare function drawingLabels(drawing: SymmetryDrawing, style?: ElementStyle): TextItem[];
18
+ /**
19
+ * The element's name, unless another name already sits where it would go.
20
+ *
21
+ * Symmetry puts elements on top of each other — nine mirror planes of a cubic
22
+ * cell meet at the same eight corners — and two names in one place are not two
23
+ * names, they are a smudge. The one drawn first keeps the spot; the rest are
24
+ * still on the pointer and in the list beside the view.
25
+ * @param drawing - The element.
26
+ * @param style - Resolved sizes.
27
+ * @param taken - Where names already sit; the kept one is added to it.
28
+ * @returns Its text, or none when the spot is taken.
29
+ */
30
+ export declare function spacedLabels(drawing: SymmetryDrawing, style: ResolvedElementStyle, taken: Point3[]): TextItem[];
31
+ //# sourceMappingURL=elementLabels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementLabels.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/core/elementLabels.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,QAAQ,EACT,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAGV,MAAM,EACN,eAAe,EAChB,MAAM,YAAY,CAAC;AAUpB;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,eAAe,EACxB,KAAK,GAAE,YAAiB,GACvB,QAAQ,EAAE,CAqBZ;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,oBAAoB,EAC3B,KAAK,EAAE,MAAM,EAAE,GACd,QAAQ,EAAE,CAeZ"}
@@ -0,0 +1,99 @@
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
+ import { faceCorners } from "./elementShapes.js";
10
+ import { plainName } from "./labelText.js";
11
+ import { resolveElementStyle } from "./primitives.js";
12
+ import { addVectors, normalizeVector, scaleVector, subtractVectors, vectorNorm, } from "./vec3.js";
13
+ /**
14
+ * Where one element's text floats, and what it reads.
15
+ * @param drawing - The element.
16
+ * @param style - Sizes; the defaults are used for anything left out.
17
+ * @returns One line of text, or none when the element carries no label.
18
+ */
19
+ export function drawingLabels(drawing, style = {}) {
20
+ const text = plainName(drawing.badge ?? drawing.label);
21
+ if (text === '')
22
+ return [];
23
+ const sizes = resolveElementStyle(style);
24
+ const size = sizes.labelSize;
25
+ if (drawing.kind === 'inversion') {
26
+ const offset = scaleVector(LABEL_UP, sizes.centreRadius + sizes.labelGap);
27
+ return [{ text, position: addVectors(drawing.point, offset), size }];
28
+ }
29
+ if (drawing.kind === 'mirror' || drawing.kind === 'glide') {
30
+ return [{ text, position: planeLabelPoint(drawing, sizes), size }];
31
+ }
32
+ const unit = normalizeVector(drawing.direction);
33
+ const reach = drawing.length / 2 + sizes.labelGap;
34
+ return [
35
+ {
36
+ text,
37
+ position: addVectors(drawing.point, scaleVector(unit, reach)),
38
+ size,
39
+ },
40
+ ];
41
+ }
42
+ /**
43
+ * The element's name, unless another name already sits where it would go.
44
+ *
45
+ * Symmetry puts elements on top of each other — nine mirror planes of a cubic
46
+ * cell meet at the same eight corners — and two names in one place are not two
47
+ * names, they are a smudge. The one drawn first keeps the spot; the rest are
48
+ * still on the pointer and in the list beside the view.
49
+ * @param drawing - The element.
50
+ * @param style - Resolved sizes.
51
+ * @param taken - Where names already sit; the kept one is added to it.
52
+ * @returns Its text, or none when the spot is taken.
53
+ */
54
+ export function spacedLabels(drawing, style, taken) {
55
+ const kept = [];
56
+ for (const item of drawingLabels(drawing, style)) {
57
+ let clear = true;
58
+ for (const other of taken) {
59
+ if (vectorNorm(subtractVectors(item.position, other)) < style.labelSize) {
60
+ clear = false;
61
+ break;
62
+ }
63
+ }
64
+ if (!clear)
65
+ continue;
66
+ taken.push(item.position);
67
+ kept.push(item);
68
+ }
69
+ return kept;
70
+ }
71
+ /**
72
+ * Where a plane's name sits: a corner of the drawn face, pushed out of it.
73
+ *
74
+ * A corner is as far from the structure as the element gets, so the names of
75
+ * ten planes through one cell end up spread round its edges rather than piled
76
+ * on the atoms in the middle.
77
+ * @param drawing - The mirror or glide plane.
78
+ * @param sizes - The resolved sizes, for the gap off the face.
79
+ * @returns The label's position, Cartesian ångström.
80
+ */
81
+ function planeLabelPoint(drawing, sizes) {
82
+ const corners = faceCorners(drawing);
83
+ const first = corners[0];
84
+ if (first === undefined)
85
+ return drawing.point;
86
+ let centre = [0, 0, 0];
87
+ for (const corner of corners)
88
+ centre = addVectors(centre, corner);
89
+ centre = scaleVector(centre, 1 / corners.length);
90
+ const outward = subtractVectors(first, centre);
91
+ if (vectorNorm(outward) < FLAT)
92
+ return first;
93
+ return addVectors(first, scaleVector(normalizeVector(outward), sizes.labelGap));
94
+ }
95
+ /** Which way an inversion centre's label sits, having no direction of its own. */
96
+ const LABEL_UP = [0, 0, 1];
97
+ /** Below this, ångström, a corner is the centre and has no outward direction. */
98
+ const FLAT = 1e-9;
99
+ //# sourceMappingURL=elementLabels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementLabels.js","sourceRoot":"","sources":["../../../src/crystal3d/core/elementLabels.ts"],"names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AAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC/C,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,UAAU,CACf,KAAK,EACL,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CACtD,CAAC;AACJ,CAAC;AAED,kFAAkF;AAClF,MAAM,QAAQ,GAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjC,iFAAiF;AACjF,MAAM,IAAI,GAAG,IAAI,CAAC"}
@@ -0,0 +1,43 @@
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
+ import type { MeshPrimitive, ResolvedElementStyle } from './primitives.ts';
10
+ import type { GlideDrawing, MirrorDrawing, Point3 } from './types.ts';
11
+ /**
12
+ * The two ends of a rod of `length` centred on `point`.
13
+ * @param point - Its middle.
14
+ * @param direction - Which way it runs; need not be normalised.
15
+ * @param length - Its total length, ångström.
16
+ * @returns The two ends, the one against `direction` first.
17
+ */
18
+ export declare function rodEnds(point: Point3, direction: Point3, length: number): [Point3, Point3];
19
+ /**
20
+ * A shaft and a head, pointing along `direction` for `length` ångström.
21
+ * @param base - Where the arrow starts.
22
+ * @param direction - Which way it points; need not be normalised.
23
+ * @param length - How far it reaches. A negative length points the other way,
24
+ * which is how a left-handed screw is told from a right-handed one.
25
+ * @param sizes - Resolved sizes.
26
+ * @returns The shaft, when there is room for one, and the head.
27
+ */
28
+ export declare function arrow(base: Point3, direction: Point3, length: number, sizes: ResolvedElementStyle): MeshPrimitive[];
29
+ /**
30
+ * A plane as a face and the rim round it, so a stack of them stays readable.
31
+ * @param drawing - The mirror or glide plane.
32
+ * @param sizes - Resolved sizes.
33
+ * @returns The face and one rod per edge, or the square when the plane was
34
+ * given no outline to be cut to.
35
+ */
36
+ export declare function planeFace(drawing: GlideDrawing | MirrorDrawing, sizes: ResolvedElementStyle): MeshPrimitive[];
37
+ /**
38
+ * The face a plane is drawn as: the outline it was given, or a square.
39
+ * @param drawing - The mirror or glide plane.
40
+ * @returns Its corners, in order around the plane.
41
+ */
42
+ export declare function faceCorners(drawing: GlideDrawing | MirrorDrawing): Point3[];
43
+ //# sourceMappingURL=elementShapes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementShapes.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/core/elementShapes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGtE;;;;;;GAMG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,CAAC,MAAM,EAAE,MAAM,CAAC,CAGlB;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,oBAAoB,GAC1B,aAAa,EAAE,CAuBjB;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,YAAY,GAAG,aAAa,EACrC,KAAK,EAAE,oBAAoB,GAC1B,aAAa,EAAE,CAajB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,EAAE,CAkB3E"}
@@ -0,0 +1,115 @@
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
+ import { planeFrame } from "./frame.js";
10
+ import { addVectors, normalizeVector, scaleVector } from "./vec3.js";
11
+ /**
12
+ * The two ends of a rod of `length` centred on `point`.
13
+ * @param point - Its middle.
14
+ * @param direction - Which way it runs; need not be normalised.
15
+ * @param length - Its total length, ångström.
16
+ * @returns The two ends, the one against `direction` first.
17
+ */
18
+ export function rodEnds(point, direction, length) {
19
+ const half = scaleVector(normalizeVector(direction), length / 2);
20
+ return [addVectors(point, scaleVector(half, -1)), addVectors(point, half)];
21
+ }
22
+ /**
23
+ * A shaft and a head, pointing along `direction` for `length` ångström.
24
+ * @param base - Where the arrow starts.
25
+ * @param direction - Which way it points; need not be normalised.
26
+ * @param length - How far it reaches. A negative length points the other way,
27
+ * which is how a left-handed screw is told from a right-handed one.
28
+ * @param sizes - Resolved sizes.
29
+ * @returns The shaft, when there is room for one, and the head.
30
+ */
31
+ export function arrow(base, direction, length, sizes) {
32
+ const reach = Math.abs(length);
33
+ if (reach < MINIMUM_ARROW)
34
+ return [];
35
+ const unit = scaleVector(normalizeVector(direction), Math.sign(length));
36
+ const head = Math.min(sizes.arrowLength, reach);
37
+ const shaftEnd = addVectors(base, scaleVector(unit, reach - head));
38
+ const tip = addVectors(base, scaleVector(unit, reach));
39
+ const primitives = [];
40
+ if (reach > head) {
41
+ primitives.push({
42
+ shape: 'rod',
43
+ start: base,
44
+ end: shaftEnd,
45
+ radius: sizes.axisRadius,
46
+ });
47
+ }
48
+ primitives.push({
49
+ shape: 'cone',
50
+ base: shaftEnd,
51
+ tip,
52
+ radius: sizes.arrowRadius,
53
+ });
54
+ return primitives;
55
+ }
56
+ /**
57
+ * A plane as a face and the rim round it, so a stack of them stays readable.
58
+ * @param drawing - The mirror or glide plane.
59
+ * @param sizes - Resolved sizes.
60
+ * @returns The face and one rod per edge, or the square when the plane was
61
+ * given no outline to be cut to.
62
+ */
63
+ export function planeFace(drawing, sizes) {
64
+ const outline = drawing.outline;
65
+ if (outline === undefined || outline.length < 3) {
66
+ return [plate(drawing.point, drawing.normal, drawing.size)];
67
+ }
68
+ const primitives = [{ shape: 'face', points: outline }];
69
+ for (let index = 0; index < outline.length; index++) {
70
+ const start = outline[index];
71
+ const end = outline[(index + 1) % outline.length];
72
+ if (start === undefined || end === undefined)
73
+ continue;
74
+ primitives.push({ shape: 'rod', start, end, radius: sizes.rimRadius });
75
+ }
76
+ return primitives;
77
+ }
78
+ /**
79
+ * The face a plane is drawn as: the outline it was given, or a square.
80
+ * @param drawing - The mirror or glide plane.
81
+ * @returns Its corners, in order around the plane.
82
+ */
83
+ export function faceCorners(drawing) {
84
+ const outline = drawing.outline;
85
+ if (outline !== undefined && outline.length >= 3)
86
+ return [...outline];
87
+ const { major, minor } = planeFrame(drawing.normal);
88
+ const half = drawing.size / 2;
89
+ const corners = [];
90
+ for (const [along, across] of SQUARE) {
91
+ corners.push(addVectors(drawing.point, addVectors(scaleVector(major, along * half), scaleVector(minor, across * half))));
92
+ }
93
+ return corners;
94
+ }
95
+ /**
96
+ * The square a mirror or a glide plane is drawn as.
97
+ * @param point - Its centre, Cartesian ångström.
98
+ * @param normal - The plane's normal, Cartesian.
99
+ * @param size - The side of the square, ångström.
100
+ * @returns The plate primitive.
101
+ */
102
+ function plate(point, normal, size) {
103
+ const { major, minor } = planeFrame(normal);
104
+ return { shape: 'plate', centre: point, major, minor, size };
105
+ }
106
+ /** The four corners of a square, as multiples of its half-side. */
107
+ const SQUARE = [
108
+ [-1, -1],
109
+ [1, -1],
110
+ [1, 1],
111
+ [-1, 1],
112
+ ];
113
+ /** Below this, ångström, an arrow is a blob and is left out. */
114
+ const MINIMUM_ARROW = 1e-6;
115
+ //# sourceMappingURL=elementShapes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementShapes.js","sourceRoot":"","sources":["../../../src/crystal3d/core/elementShapes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,KAAa,EACb,SAAiB,EACjB,MAAc;IAEd,MAAM,IAAI,GAAG,WAAW,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CACnB,IAAY,EACZ,SAAiB,EACjB,MAAc,EACd,KAA2B;IAE3B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,KAAK,GAAG,aAAa;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,WAAW,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACxE,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;IACnE,MAAM,GAAG,GAAG,UAAU,CAAC,IA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,CAAC;IACR,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,EAAE,CAAC,CAAC;IACN,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CACR,CAAC;AAEF,gEAAgE;AAChE,MAAM,aAAa,GAAG,IAAI,CAAC"}
@@ -0,0 +1,36 @@
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
+ import type { Vec3 } from './vec3.ts';
10
+ /** An orthonormal pair spanning a plane, with the normal that produced it. */
11
+ export interface PlaneFrame {
12
+ /** The unit normal. */
13
+ readonly normal: Vec3;
14
+ /** First in-plane direction. */
15
+ readonly major: Vec3;
16
+ /** Second in-plane direction, `normal × major`. */
17
+ readonly minor: Vec3;
18
+ }
19
+ /**
20
+ * The frame of the plane with this normal.
21
+ * @param normal - The plane normal; need not be normalised.
22
+ * @returns The unit normal and two unit directions in the plane.
23
+ * @throws {RangeError} When the normal is too short to have a direction.
24
+ */
25
+ export declare function planeFrame(normal: Vec3): PlaneFrame;
26
+ /**
27
+ * A unit vector at right angles to `direction`.
28
+ *
29
+ * The seed is `x̂` unless the direction is already close to it, which is the
30
+ * one case where projecting out the direction would leave nothing to normalise.
31
+ * @param direction - Any non-zero vector; need not be normalised.
32
+ * @returns A unit vector orthogonal to it.
33
+ * @throws {RangeError} When the direction is too short to have one.
34
+ */
35
+ export declare function perpendicularTo(direction: Vec3): Vec3;
36
+ //# sourceMappingURL=frame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/core/frame.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAStC,8EAA8E;AAC9E,MAAM,WAAW,UAAU;IACzB,uBAAuB;IACvB,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,GAAG,UAAU,CAInD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,IAAI,GAAG,IAAI,CAMrD"}
@@ -0,0 +1,35 @@
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
+ import { crossProduct, dotProduct, normalizeVector, scaleVector, subtractVectors, } from "./vec3.js";
10
+ /**
11
+ * The frame of the plane with this normal.
12
+ * @param normal - The plane normal; need not be normalised.
13
+ * @returns The unit normal and two unit directions in the plane.
14
+ * @throws {RangeError} When the normal is too short to have a direction.
15
+ */
16
+ export function planeFrame(normal) {
17
+ const unit = normalizeVector(normal);
18
+ const major = perpendicularTo(unit);
19
+ return { normal: unit, major, minor: crossProduct(unit, major) };
20
+ }
21
+ /**
22
+ * A unit vector at right angles to `direction`.
23
+ *
24
+ * The seed is `x̂` unless the direction is already close to it, which is the
25
+ * one case where projecting out the direction would leave nothing to normalise.
26
+ * @param direction - Any non-zero vector; need not be normalised.
27
+ * @returns A unit vector orthogonal to it.
28
+ * @throws {RangeError} When the direction is too short to have one.
29
+ */
30
+ export function perpendicularTo(direction) {
31
+ const unit = normalizeVector(direction);
32
+ const seed = Math.abs(unit[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0];
33
+ return normalizeVector(subtractVectors(seed, scaleVector(unit, dotProduct(seed, unit))));
34
+ }
35
+ //# sourceMappingURL=frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame.js","sourceRoot":"","sources":["../../../src/crystal3d/core/frame.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,YAAY,EACZ,UAAU,EACV,eAAe,EACf,WAAW,EACX,eAAe,GAChB,MAAM,WAAW,CAAC;AAYnB;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,MAAY;IACrC,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;AACnE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,SAAe;IAC7C,MAAM,IAAI,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,IAAI,GAAS,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnE,OAAO,eAAe,CACpB,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CACjE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
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
+ import type { MeshPrimitive } from './primitives.ts';
11
+ import type { Point3 } from './types.ts';
12
+ /** A ball holding everything on screen. */
13
+ export interface SceneSphere {
14
+ /** Its centre, Cartesian ångström. */
15
+ readonly centre: Point3;
16
+ /** Its radius, ångström; zero for a single point. */
17
+ readonly radius: number;
18
+ }
19
+ /**
20
+ * The smallest ball about the centroid that holds every point.
21
+ * @param points - What has to fit; an empty list gives a point at the origin.
22
+ * @param padding - Extra radius, ångström, for whatever is drawn around them.
23
+ * @returns The ball.
24
+ */
25
+ export declare function boundingSphereOf(points: readonly Point3[], padding?: number): SceneSphere;
26
+ /**
27
+ * One ball holding several — the atoms, the cell and the drawn elements at once.
28
+ * @param spheres - What has to fit; an empty list gives a point at the origin.
29
+ * @returns A ball containing every one of them. It is not the smallest such
30
+ * ball, which is a harder problem than framing a scene deserves, but it never
31
+ * leaves anything outside.
32
+ */
33
+ export declare function unionSpheres(spheres: readonly SceneSphere[]): SceneSphere;
34
+ /**
35
+ * How far a set of drawn shapes reaches.
36
+ * @param primitives - The shapes.
37
+ * @param padding - Extra radius, ångström.
38
+ * @returns A ball holding them all.
39
+ */
40
+ export declare function primitivesExtent(primitives: readonly MeshPrimitive[], padding?: number): SceneSphere;
41
+ //# sourceMappingURL=framing.d.ts.map