@automovie/human 0.0.0 → 0.2.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 (233) hide show
  1. package/README.md +29 -16
  2. package/lib/generation/AutoMovieHumanDigitJoints.d.ts +8 -26
  3. package/lib/generation/AutoMovieHumanDigitJoints.js +9 -37
  4. package/lib/generation/AutoMovieHumanDigitJoints.js.map +1 -1
  5. package/lib/generation/{AutoMovieHumanLegSection.d.ts → AutoMovieHumanLegSectionProportion.d.ts} +1 -1
  6. package/lib/generation/{AutoMovieHumanLegSection.js → AutoMovieHumanLegSectionProportion.js} +17 -14
  7. package/lib/generation/AutoMovieHumanLegSectionProportion.js.map +1 -0
  8. package/lib/generation/arm/AutoMovieHumanArmFrame.js +2 -2
  9. package/lib/generation/arm/AutoMovieHumanArmFrame.js.map +1 -1
  10. package/lib/generation/arm/index.d.ts +28 -0
  11. package/lib/generation/arm/index.js +45 -0
  12. package/lib/generation/arm/index.js.map +1 -0
  13. package/lib/generation/conic/AutoMovieHumanConicLoft.d.ts +154 -0
  14. package/lib/generation/conic/AutoMovieHumanConicLoft.js +430 -0
  15. package/lib/generation/conic/AutoMovieHumanConicLoft.js.map +1 -0
  16. package/lib/generation/conic/AutoMovieHumanConicPose.d.ts +92 -0
  17. package/lib/generation/conic/AutoMovieHumanConicPose.js +202 -0
  18. package/lib/generation/conic/AutoMovieHumanConicPose.js.map +1 -0
  19. package/lib/generation/conic/AutoMovieHumanConicRelief.d.ts +52 -0
  20. package/lib/generation/conic/AutoMovieHumanConicRelief.js +88 -0
  21. package/lib/generation/conic/AutoMovieHumanConicRelief.js.map +1 -0
  22. package/lib/generation/conic/AutoMovieHumanConicSection.d.ts +252 -0
  23. package/lib/generation/conic/AutoMovieHumanConicSection.js +567 -0
  24. package/lib/generation/conic/AutoMovieHumanConicSection.js.map +1 -0
  25. package/lib/generation/f1/AutoMovieHumanF1.d.ts +265 -0
  26. package/lib/generation/f1/AutoMovieHumanF1.js +1254 -0
  27. package/lib/generation/f1/AutoMovieHumanF1.js.map +1 -0
  28. package/lib/generation/f1/AutoMovieHumanF1Antihelix.d.ts +23 -0
  29. package/lib/generation/f1/AutoMovieHumanF1Antihelix.js +65 -0
  30. package/lib/generation/f1/AutoMovieHumanF1Antihelix.js.map +1 -0
  31. package/lib/generation/f1/AutoMovieHumanF1Arm.d.ts +18 -0
  32. package/lib/generation/f1/AutoMovieHumanF1Arm.js +82 -0
  33. package/lib/generation/f1/AutoMovieHumanF1Arm.js.map +1 -0
  34. package/lib/generation/f1/AutoMovieHumanF1Axilla.d.ts +18 -0
  35. package/lib/generation/f1/AutoMovieHumanF1Axilla.js +91 -0
  36. package/lib/generation/f1/AutoMovieHumanF1Axilla.js.map +1 -0
  37. package/lib/generation/f1/AutoMovieHumanF1Breast.d.ts +18 -0
  38. package/lib/generation/f1/AutoMovieHumanF1Breast.js +75 -0
  39. package/lib/generation/f1/AutoMovieHumanF1Breast.js.map +1 -0
  40. package/lib/generation/f1/AutoMovieHumanF1Concha.d.ts +40 -0
  41. package/lib/generation/f1/AutoMovieHumanF1Concha.js +81 -0
  42. package/lib/generation/f1/AutoMovieHumanF1Concha.js.map +1 -0
  43. package/lib/generation/f1/AutoMovieHumanF1FingerIndex.d.ts +18 -0
  44. package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js +59 -0
  45. package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js.map +1 -0
  46. package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.d.ts +18 -0
  47. package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js +59 -0
  48. package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js.map +1 -0
  49. package/lib/generation/f1/AutoMovieHumanF1FingerPinky.d.ts +18 -0
  50. package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js +75 -0
  51. package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js.map +1 -0
  52. package/lib/generation/f1/AutoMovieHumanF1FingerRing.d.ts +18 -0
  53. package/lib/generation/f1/AutoMovieHumanF1FingerRing.js +75 -0
  54. package/lib/generation/f1/AutoMovieHumanF1FingerRing.js.map +1 -0
  55. package/lib/generation/f1/AutoMovieHumanF1FingerThumb.d.ts +18 -0
  56. package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js +59 -0
  57. package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js.map +1 -0
  58. package/lib/generation/f1/AutoMovieHumanF1Frames.d.ts +97 -0
  59. package/lib/generation/f1/AutoMovieHumanF1Frames.js +160 -0
  60. package/lib/generation/f1/AutoMovieHumanF1Frames.js.map +1 -0
  61. package/lib/generation/f1/AutoMovieHumanF1Hand.d.ts +18 -0
  62. package/lib/generation/f1/AutoMovieHumanF1Hand.js +81 -0
  63. package/lib/generation/f1/AutoMovieHumanF1Hand.js.map +1 -0
  64. package/lib/generation/f1/AutoMovieHumanF1Helix.d.ts +20 -0
  65. package/lib/generation/f1/AutoMovieHumanF1Helix.js +64 -0
  66. package/lib/generation/f1/AutoMovieHumanF1Helix.js.map +1 -0
  67. package/lib/generation/f1/AutoMovieHumanF1Joints.d.ts +231 -0
  68. package/lib/generation/f1/AutoMovieHumanF1Joints.js +249 -0
  69. package/lib/generation/f1/AutoMovieHumanF1Joints.js.map +1 -0
  70. package/lib/generation/f1/AutoMovieHumanF1Landmarks.d.ts +86 -0
  71. package/lib/generation/f1/AutoMovieHumanF1Landmarks.js +89 -0
  72. package/lib/generation/f1/AutoMovieHumanF1Landmarks.js.map +1 -0
  73. package/lib/generation/f1/AutoMovieHumanF1Leg.d.ts +18 -0
  74. package/lib/generation/f1/AutoMovieHumanF1Leg.js +82 -0
  75. package/lib/generation/f1/AutoMovieHumanF1Leg.js.map +1 -0
  76. package/lib/generation/f1/AutoMovieHumanF1Nose.d.ts +18 -0
  77. package/lib/generation/f1/AutoMovieHumanF1Nose.js +82 -0
  78. package/lib/generation/f1/AutoMovieHumanF1Nose.js.map +1 -0
  79. package/lib/generation/f1/AutoMovieHumanF1Nostril.d.ts +18 -0
  80. package/lib/generation/f1/AutoMovieHumanF1Nostril.js +59 -0
  81. package/lib/generation/f1/AutoMovieHumanF1Nostril.js.map +1 -0
  82. package/lib/generation/f1/AutoMovieHumanF1Placement.d.ts +75 -0
  83. package/lib/generation/f1/AutoMovieHumanF1Placement.js +151 -0
  84. package/lib/generation/f1/AutoMovieHumanF1Placement.js.map +1 -0
  85. package/lib/generation/f1/AutoMovieHumanF1Placing.d.ts +45 -0
  86. package/lib/generation/f1/AutoMovieHumanF1Placing.js +301 -0
  87. package/lib/generation/f1/AutoMovieHumanF1Placing.js.map +1 -0
  88. package/lib/generation/f1/AutoMovieHumanF1Plate.d.ts +18 -0
  89. package/lib/generation/f1/AutoMovieHumanF1Plate.js +59 -0
  90. package/lib/generation/f1/AutoMovieHumanF1Plate.js.map +1 -0
  91. package/lib/generation/f1/AutoMovieHumanF1ToeBig.d.ts +18 -0
  92. package/lib/generation/f1/AutoMovieHumanF1ToeBig.js +59 -0
  93. package/lib/generation/f1/AutoMovieHumanF1ToeBig.js.map +1 -0
  94. package/lib/generation/f1/AutoMovieHumanF1ToeIndex.d.ts +18 -0
  95. package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js +59 -0
  96. package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js.map +1 -0
  97. package/lib/generation/f1/AutoMovieHumanF1ToeLittle.d.ts +18 -0
  98. package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js +75 -0
  99. package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js.map +1 -0
  100. package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.d.ts +18 -0
  101. package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js +75 -0
  102. package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js.map +1 -0
  103. package/lib/generation/f1/AutoMovieHumanF1ToeRing.d.ts +18 -0
  104. package/lib/generation/f1/AutoMovieHumanF1ToeRing.js +75 -0
  105. package/lib/generation/f1/AutoMovieHumanF1ToeRing.js.map +1 -0
  106. package/lib/generation/f1/AutoMovieHumanF1Trunk.d.ts +18 -0
  107. package/lib/generation/f1/AutoMovieHumanF1Trunk.js +79 -0
  108. package/lib/generation/f1/AutoMovieHumanF1Trunk.js.map +1 -0
  109. package/lib/generation/f1/AutoMovieHumanF1Vault.d.ts +18 -0
  110. package/lib/generation/f1/AutoMovieHumanF1Vault.js +75 -0
  111. package/lib/generation/f1/AutoMovieHumanF1Vault.js.map +1 -0
  112. package/lib/generation/foot/index.d.ts +51 -0
  113. package/lib/generation/foot/index.js +68 -0
  114. package/lib/generation/foot/index.js.map +1 -0
  115. package/lib/generation/frame/AutoMovieHumanSegmentFrame.d.ts +149 -0
  116. package/lib/generation/frame/AutoMovieHumanSegmentFrame.js +290 -0
  117. package/lib/generation/frame/AutoMovieHumanSegmentFrame.js.map +1 -0
  118. package/lib/generation/hand/index.d.ts +53 -0
  119. package/lib/generation/hand/index.js +70 -0
  120. package/lib/generation/hand/index.js.map +1 -0
  121. package/lib/generation/head/index.d.ts +37 -0
  122. package/lib/generation/head/index.js +54 -0
  123. package/lib/generation/head/index.js.map +1 -0
  124. package/lib/generation/index.d.ts +176 -0
  125. package/lib/generation/index.js +193 -0
  126. package/lib/generation/index.js.map +1 -0
  127. package/lib/generation/leg/AutoMovieHumanLegLaws.d.ts +1 -1
  128. package/lib/generation/leg/AutoMovieHumanLegLaws.js +23 -11
  129. package/lib/generation/leg/AutoMovieHumanLegLaws.js.map +1 -1
  130. package/lib/generation/leg/index.d.ts +34 -0
  131. package/lib/generation/leg/index.js +51 -0
  132. package/lib/generation/leg/index.js.map +1 -0
  133. package/lib/generation/limb/{AutoMovieHumanJointTurn.d.ts → AutoMovieHumanBendArc.d.ts} +1 -1
  134. package/lib/generation/limb/{AutoMovieHumanJointTurn.js → AutoMovieHumanBendArc.js} +12 -8
  135. package/lib/generation/limb/AutoMovieHumanBendArc.js.map +1 -0
  136. package/lib/generation/limb/AutoMovieHumanDigitWalk.js +2 -2
  137. package/lib/generation/limb/AutoMovieHumanDigitWalk.js.map +1 -1
  138. package/lib/generation/limb/AutoMovieHumanWalkPart.js +72 -17
  139. package/lib/generation/limb/AutoMovieHumanWalkPart.js.map +1 -1
  140. package/lib/generation/limb/index.d.ts +12 -0
  141. package/lib/generation/limb/index.js +29 -0
  142. package/lib/generation/limb/index.js.map +1 -0
  143. package/lib/generation/trunk/index.d.ts +17 -0
  144. package/lib/generation/trunk/index.js +34 -0
  145. package/lib/generation/trunk/index.js.map +1 -0
  146. package/lib/generation/web/index.d.ts +14 -0
  147. package/lib/generation/web/index.js +31 -0
  148. package/lib/generation/web/index.js.map +1 -0
  149. package/lib/index.d.ts +14 -4
  150. package/lib/index.js +14 -9
  151. package/lib/index.js.map +1 -1
  152. package/lib/lofting/index.d.ts +14 -0
  153. package/lib/lofting/index.js +31 -0
  154. package/lib/lofting/index.js.map +1 -0
  155. package/lib/skeleton/AutoMovieHumanCanonicalBody.d.ts +7 -3
  156. package/lib/skeleton/AutoMovieHumanCanonicalBody.js +31 -3
  157. package/lib/skeleton/AutoMovieHumanCanonicalBody.js.map +1 -1
  158. package/lib/skeleton/AutoMovieHumanCanonicalProfile.d.ts +22 -31
  159. package/lib/skeleton/AutoMovieHumanCanonicalProfile.js +112 -172
  160. package/lib/skeleton/AutoMovieHumanCanonicalProfile.js.map +1 -1
  161. package/lib/skeleton/AutoMovieHumanCanonicalSolids.d.ts +65 -0
  162. package/lib/skeleton/AutoMovieHumanCanonicalSolids.js +105 -0
  163. package/lib/skeleton/AutoMovieHumanCanonicalSolids.js.map +1 -0
  164. package/lib/skeleton/index.d.ts +29 -0
  165. package/lib/skeleton/index.js +46 -0
  166. package/lib/skeleton/index.js.map +1 -0
  167. package/lib/structures/index.d.ts +2 -2
  168. package/lib/structures/index.js +2 -2
  169. package/lib/structures/index.js.map +1 -1
  170. package/lib/typings/index.d.ts +1 -1
  171. package/lib/typings/index.js +1 -1
  172. package/lib/typings/index.js.map +1 -1
  173. package/package.json +21 -13
  174. package/src/generation/AutoMovieHumanDigitJoints.ts +12 -47
  175. package/src/generation/{AutoMovieHumanLegSection.ts → AutoMovieHumanLegSectionProportion.ts} +15 -6
  176. package/src/generation/arm/AutoMovieHumanArmFrame.ts +2 -2
  177. package/src/generation/arm/index.ts +28 -0
  178. package/src/generation/conic/AutoMovieHumanConicLoft.ts +566 -0
  179. package/src/generation/conic/AutoMovieHumanConicPose.ts +213 -0
  180. package/src/generation/conic/AutoMovieHumanConicRelief.ts +94 -0
  181. package/src/generation/conic/AutoMovieHumanConicSection.ts +609 -0
  182. package/src/generation/f1/AutoMovieHumanF1.ts +1448 -0
  183. package/src/generation/f1/AutoMovieHumanF1Antihelix.ts +64 -0
  184. package/src/generation/f1/AutoMovieHumanF1Arm.ts +82 -0
  185. package/src/generation/f1/AutoMovieHumanF1Axilla.ts +90 -0
  186. package/src/generation/f1/AutoMovieHumanF1Breast.ts +74 -0
  187. package/src/generation/f1/AutoMovieHumanF1Concha.ts +80 -0
  188. package/src/generation/f1/AutoMovieHumanF1FingerIndex.ts +58 -0
  189. package/src/generation/f1/AutoMovieHumanF1FingerMiddle.ts +58 -0
  190. package/src/generation/f1/AutoMovieHumanF1FingerPinky.ts +74 -0
  191. package/src/generation/f1/AutoMovieHumanF1FingerRing.ts +74 -0
  192. package/src/generation/f1/AutoMovieHumanF1FingerThumb.ts +58 -0
  193. package/src/generation/f1/AutoMovieHumanF1Frames.ts +191 -0
  194. package/src/generation/f1/AutoMovieHumanF1Hand.ts +81 -0
  195. package/src/generation/f1/AutoMovieHumanF1Helix.ts +63 -0
  196. package/src/generation/f1/AutoMovieHumanF1Joints.ts +319 -0
  197. package/src/generation/f1/AutoMovieHumanF1Landmarks.ts +101 -0
  198. package/src/generation/f1/AutoMovieHumanF1Leg.ts +82 -0
  199. package/src/generation/f1/AutoMovieHumanF1Nose.ts +82 -0
  200. package/src/generation/f1/AutoMovieHumanF1Nostril.ts +58 -0
  201. package/src/generation/f1/AutoMovieHumanF1Placement.ts +148 -0
  202. package/src/generation/f1/AutoMovieHumanF1Placing.ts +313 -0
  203. package/src/generation/f1/AutoMovieHumanF1Plate.ts +59 -0
  204. package/src/generation/f1/AutoMovieHumanF1ToeBig.ts +58 -0
  205. package/src/generation/f1/AutoMovieHumanF1ToeIndex.ts +58 -0
  206. package/src/generation/f1/AutoMovieHumanF1ToeLittle.ts +74 -0
  207. package/src/generation/f1/AutoMovieHumanF1ToeMiddle.ts +74 -0
  208. package/src/generation/f1/AutoMovieHumanF1ToeRing.ts +74 -0
  209. package/src/generation/f1/AutoMovieHumanF1Trunk.ts +79 -0
  210. package/src/generation/f1/AutoMovieHumanF1Vault.ts +74 -0
  211. package/src/generation/foot/index.ts +51 -0
  212. package/src/generation/frame/AutoMovieHumanSegmentFrame.ts +309 -0
  213. package/src/generation/hand/index.ts +53 -0
  214. package/src/generation/head/index.ts +37 -0
  215. package/src/generation/index.ts +176 -0
  216. package/src/generation/leg/AutoMovieHumanLegLaws.ts +80 -25
  217. package/src/generation/leg/index.ts +34 -0
  218. package/src/generation/limb/{AutoMovieHumanJointTurn.ts → AutoMovieHumanBendArc.ts} +39 -11
  219. package/src/generation/limb/AutoMovieHumanDigitWalk.ts +2 -2
  220. package/src/generation/limb/AutoMovieHumanWalkPart.ts +163 -41
  221. package/src/generation/limb/index.ts +12 -0
  222. package/src/generation/trunk/index.ts +17 -0
  223. package/src/generation/web/index.ts +14 -0
  224. package/src/index.ts +14 -4
  225. package/src/lofting/index.ts +14 -0
  226. package/src/skeleton/AutoMovieHumanCanonicalBody.ts +53 -3
  227. package/src/skeleton/AutoMovieHumanCanonicalProfile.ts +153 -358
  228. package/src/skeleton/AutoMovieHumanCanonicalSolids.ts +175 -0
  229. package/src/skeleton/index.ts +29 -0
  230. package/src/structures/index.ts +2 -2
  231. package/src/typings/index.ts +1 -1
  232. package/lib/generation/AutoMovieHumanLegSection.js.map +0 -1
  233. package/lib/generation/limb/AutoMovieHumanJointTurn.js.map +0 -1
@@ -0,0 +1,566 @@
1
+ import { AutoMovieLoftChain, type AutoMovieLoftFrame, AutoMovieNaturalSpline, AutoMovieViewAxis, AutoMovieViewAxisJet, AutoMovieViewLoft, type IAutoMovieLoftRelief, type IAutoMovieViewPart } from "@automovie/engine";
2
+ import type { AutoMovieConstructionOutlineParameter } from "@automovie/interface";
3
+
4
+ import { AutoMovieHumanConicSection } from "./AutoMovieHumanConicSection";
5
+
6
+ /**
7
+ * A conic family as it is authored, and its generation through the engine's
8
+ * view loft.
9
+ *
10
+ * A family is one part's tape wall: along a jointed course every section is
11
+ * an `AutoMovieHumanConicSection` whose fields are natural cubics through
12
+ * their values at a few shared station knots. Reliefs carry what lies inside
13
+ * that wall. Nothing else defines the part's surface.
14
+ */
15
+ export namespace AutoMovieHumanConicLoft {
16
+ /** A point or direction in the figure's absolute frame: millimetres, forward +X, up +Y, left +Z. */
17
+ export type V3 = [number, number, number];
18
+
19
+ /** The complete authored definition of one part. */
20
+ export interface IFamily {
21
+ /** Chain name. */
22
+ name: string;
23
+
24
+ /** Course centres: the first end, the joints and the last end, mm. */
25
+ centres: V3[];
26
+
27
+ /** Half arclength of the turn at each interior centre, mm. */
28
+ halves: number[];
29
+
30
+ /** The chart's `u` direction at the first segment before it is squared to the course. */
31
+ up: V3;
32
+
33
+ /**
34
+ * The chart's roll about the course; absent, none. A part whose sections turn in their planes along the course (a sheet that curls
35
+ * along its length, as the ear's plate does from the lobule up to the helix's top) keeps its long axis on `u` only if the chart turns
36
+ * with it: read in a chart carried by the course alone, its extremes trade places as it turns, and a field that follows one extreme
37
+ * jumps to the next.
38
+ */
39
+ roll?: IRoll;
40
+
41
+ /** The anchors every section is read through. */
42
+ layout: AutoMovieHumanConicSection.ILayout;
43
+
44
+ /** Shared station knots, arclength from the first centre, mm. */
45
+ knots: number[];
46
+
47
+ /** Knot values by section field then knot. */
48
+ values: number[][];
49
+
50
+ /** Reliefs composed onto the wall; absent means none. */
51
+ reliefs?: IAutoMovieLoftRelief[];
52
+
53
+ /** Where the part closes in a point, toward its first knot and toward its last; null leaves that end an open section. */
54
+ tips?: [ITip | null, ITip | null];
55
+
56
+ /**
57
+ * Largest distance between two neighbouring phases at the part's widest section, mm; absent, `PHASE_MM`. A small part whose skin turns
58
+ * within a few millimetres takes a finer pitch: at 4 mm the ear's thin rim was sampled by three phases and its edge drew a row of teeth.
59
+ */
60
+ pitch?: number;
61
+
62
+ /**
63
+ * Largest step between neighbouring phases, radians, beside the finest relief net's columns: the mesh's density round the part held
64
+ * apart from its nets'. f1's trunk took its phases from its finest net, the eyes' at 105 columns (0.016 rad); with that net coarsened to
65
+ * 73 columns for its own sake the whole face's mesh went from about 400 phases round to 270 and read in level bands and blocks.
66
+ */
67
+ phase?: number;
68
+
69
+ /**
70
+ * Largest turn of a ring's tangent between two neighbouring phases, radians; absent, the phases are uniform. With it the phases are
71
+ * spaced by how fast the rings turn as well as by `pitch`: at every phase the density is the most any ring asks there, its length over
72
+ * `pitch` or its turn over this, so a sharp edge that only some sections have (a sole's) takes its phases close together where it
73
+ * stands, and the rest of the part keeps its spacing. f1's leg on uniform phases set by its thigh's girth turned by up to 0.83 rad
74
+ * between two of them round the forefoot's outer edge, which showed as level stripes.
75
+ */
76
+ turn?: number;
77
+ }
78
+
79
+ /**
80
+ * A roll of a part's chart about its course: at each station the chart carried by the course is turned by the angle, from `u` toward
81
+ * `v`, a natural cubic through its values at its own knots (straight past the first and the last), so the frames stay C2.
82
+ */
83
+ export interface IRoll {
84
+ /** Stations of the angle's knots, mm, increasing; at least two. */
85
+ knots: number[];
86
+
87
+ /** The angle at each knot, radians. */
88
+ values: number[];
89
+ }
90
+
91
+ /**
92
+ * One closed end of a part.
93
+ *
94
+ * Between `from` and `tip` the part is its section at `from` shrunk by one factor, with that section's tangent angles and shoulders kept. With
95
+ * `t = d / H`, `d` the distance to the tip and `H` that of `from`, the factor is `g = sqrt(P(t))` for the cubic `P(t) = a t + b t^2 + c t^3`:
96
+ * upright at the tip (`a > 0`, so `g` grows as `sqrt(t)`), 1 at `from`, leaving `from` at the wall's own taper `q = H mu` (`mu` the wall's
97
+ * relative growth per millimetre away from the tip) and bending there as the wall bends (`g'' = k`, the wall's relative second derivative
98
+ * times `H^2`), so the cap continues the wall without a crease in its slope or its curvature. Those three conditions at `t = 1`, `P = 1`,
99
+ * `P' = 2 q` and `P'' = 2 q^2 + 2 k`, give `c = (1 - q)^2 + k`, `b = 2 q - 1 - 2 c` and `a = 1 - b - c = 2 (1 - q) + c`; `c` is held at 0
100
+ * or more, which keeps `P` positive on the cap. With `c = 0` this is the conic `P = 2 (1 - q) t + (2 q - 1) t^2`, which bends by
101
+ * `-(1 - q)^2` at `from`: the earlier law, which met the slope of every wall but not its bend and left a ring round every finger's and toe's
102
+ * tip, where the wall runs on straight.
103
+ */
104
+ export interface ITip {
105
+ /** Station of the last section the fields own, between the first and the last knot, mm. */
106
+ from: number;
107
+
108
+ /** Station of the point, mm. */
109
+ tip: number;
110
+
111
+ /**
112
+ * The end is not the figure's skin: buried inside another part, as a digit's root inside its limb, or under the digits merged onto it,
113
+ * as a hand's or a foot's closed end. It closes as the conic (`c = 0`), the slimmest the law allows, instead of bending on as its wall
114
+ * bends: the fuller cap brought the foot's end 5.9 mm below the sole and moved where the outer digits come out of their limbs' ends.
115
+ */
116
+ covered?: boolean;
117
+
118
+ /**
119
+ * The point of the chart, `[u, v]` mm, the cap's sections gather about while it closes, when the end's top does not stand over the
120
+ * course. A coordinate `x` of the cap is `x g + 2 c g (1 - g)^2` for its centre's coordinate `c`: at `from` it and its slope in `g` are
121
+ * the plain cap's, so the cap leaves the wall as before; it bulges toward the centre over its middle, by `8 c / 27` at most at
122
+ * `g = 1 / 3`; and it still closes on the course, where the pole is, since `x / g` tends to `x + 2 c`, which keeps the course inside
123
+ * every section while `|2 c|` is less than the section's extent on the far side. f1's crown: the course runs 16 mm behind the skull's
124
+ * top (the reference's top contour at 1,699 mm spans x -4 to 40), and the plain cap shrank the last section, 34 mm behind the course
125
+ * and 83 mm in front, toward it, so the back of the crown stood 4 mm proud of the reference at x -20 and the top was a flat lid with a
126
+ * corner behind.
127
+ */
128
+ centre?: [number, number];
129
+
130
+ /**
131
+ * Each coordinate of the cap takes the taper and the bend of its own outline at `from`, instead of the mean extent's. One factor for the
132
+ * whole section met the mean slope but not each side's: f1's crown section narrows 0.95 mm a millimetre in front (on 83 mm) and 1.2 behind
133
+ * (on 34 mm), and the shared factor took 1.9 in front and 0.77 behind, a dip at the crown's front and a corner at its back. A coordinate
134
+ * within `OWN_LEAST` of the section's size of zero keeps the shared factor, since its relative change has no meaning there.
135
+ */
136
+ own?: boolean;
137
+
138
+ /**
139
+ * How many rings the cap is meshed in between its first section and its tip; absent, one at each of its knots (`CAP_KNOTS`). A dome
140
+ * turns its normal through a quarter turn over its rings, and twelve showed as a bullseye of flat bands on a toe's tip.
141
+ */
142
+ rings?: number;
143
+ }
144
+
145
+ /** Share of a cap's first section's size under which a coordinate keeps the shared factor (`ITip.own`). */
146
+ const OWN_LEAST: number = 0.05;
147
+
148
+ /**
149
+ * Knots of a cap between its end section and its tip, besides those two. Where the tube's taper meets the cap's law the outlines' natural
150
+ * cubics ripple, and the ripple falls by about 0.27 per knot; twelve leave 1e-7 of it at the pole, where a section is small enough for any
151
+ * coordinate out of proportion to break its chain.
152
+ */
153
+ const CAP_KNOTS: number = 12;
154
+
155
+ /**
156
+ * Bounds of a cap's taper `q` (`ITip`): below 1 the tip stands upright, and at 0 the cap leaves a wall that still widens toward its tip
157
+ * level instead of widening on. Allowed to widen on (to -0.5), the nose's cap swelled 14 % past its bulb and the nostrils' cuts came out
158
+ * through its sides: a cap that widens on extrapolates past the skin the wall was fitted to.
159
+ */
160
+ const TAPER: { least: number; most: number } = { least: 0, most: 0.95 };
161
+
162
+ /**
163
+ * When a station is added midway between two: the model's section there stands off the mean of the two by more than `length` mm in a point's
164
+ * coordinate or by more than `share` in a tangent's angle, rad, or a shoulder. No interval is cut below `least` mm. At a tenth of these
165
+ * tolerances nearly every interval was cut whatever spacing was asked for, and the body's skin held 580,000 triangles at any setting.
166
+ */
167
+ const REFINE: { length: number; share: number; least: number } = { length: 0.5, share: 0.05, least: 0.25 };
168
+
169
+ /**
170
+ * Largest distance between two neighbouring phases of a part's rings at its widest section, mm; a part has at least 48 phases. With 128
171
+ * phases for every part the trunk's stood 4 mm apart at the head and 9 mm at the hips, wider than its relief nets' 2.5 to 3 mm, which showed
172
+ * as steps, while a finger's stood half a millimetre apart.
173
+ */
174
+ const PHASE_MM: number = 4;
175
+
176
+ /** The part's course as the engine reads it, its chart turned by the part's roll. */
177
+ export function axis(family: Pick<IFamily, "centres" | "halves" | "up" | "roll">): AutoMovieViewAxis.IAxis {
178
+ const made: AutoMovieViewAxis.IAxis | string = AutoMovieViewAxis.jointed(family.centres, family.halves, family.up);
179
+ if (typeof made === "string") throw new Error("course: " + made);
180
+ if (family.roll === undefined) return made;
181
+ const base: AutoMovieViewAxis.IAxis = made;
182
+ const spline: AutoMovieNaturalSpline.ISpline = AutoMovieNaturalSpline.create(family.roll.knots, family.roll.values);
183
+ // With c = cos(a) and s = sin(a): u' = c u + s v and v' = c v - s u, so with the angle's derivatives a' and a'' along the station,
184
+ // u'_1 = c u_1 + s v_1 + a' v', v'_1 = c v_1 - s u_1 - a' u', and
185
+ // u'_2 = c u_2 + s v_2 + 2 a' (c v_1 - s u_1) + a'' v' - a'^2 u', v'_2 = c v_2 - s u_2 - 2 a' (c u_1 + s v_1) - a'' u' - a'^2 v'.
186
+ const turn = (u: readonly number[], v: readonly number[], c: number, s: number): [V3, V3] => [
187
+ [0, 1, 2].map((k: number): number => c * u[k]! + s * v[k]!) as V3,
188
+ [0, 1, 2].map((k: number): number => c * v[k]! - s * u[k]!) as V3,
189
+ ];
190
+ return {
191
+ at: (station: number): AutoMovieLoftFrame.IFrame => {
192
+ const frame: AutoMovieLoftFrame.IFrame = base.at(station);
193
+ const angle: number = AutoMovieNaturalSpline.evaluate(spline, station);
194
+ const [u, v]: [V3, V3] = turn(frame.u, frame.v, Math.cos(angle), Math.sin(angle));
195
+ return { origin: frame.origin, u, v };
196
+ },
197
+ ...(base.jet === undefined
198
+ ? {}
199
+ : {
200
+ jet: (station: number, parameter?: AutoMovieConstructionOutlineParameter): AutoMovieViewAxisJet.IJet | null => {
201
+ const jet: AutoMovieViewAxisJet.IJet | null = base.jet!(station);
202
+ if (jet === null) return null;
203
+ const [a, a1, a2]: [number, number, number] = AutoMovieNaturalSpline.read(spline, station);
204
+ const [c, s]: [number, number] = [Math.cos(a), Math.sin(a)];
205
+ const [u, v]: [V3, V3] = turn(jet.value.u, jet.value.v, c, s);
206
+ const [u1, v1]: [V3, V3] = turn(jet.first.u, jet.first.v, c, s);
207
+ const [u2, v2]: [V3, V3] = turn(jet.second.u, jet.second.v, c, s);
208
+ const rolled: AutoMovieViewAxisJet.IJet = {
209
+ value: { origin: jet.value.origin, u, v },
210
+ first: {
211
+ origin: jet.first.origin,
212
+ u: [0, 1, 2].map((k: number): number => u1[k]! + a1 * v[k]!) as V3,
213
+ v: [0, 1, 2].map((k: number): number => v1[k]! - a1 * u[k]!) as V3,
214
+ },
215
+ second: {
216
+ origin: jet.second.origin,
217
+ u: [0, 1, 2].map((k: number): number => u2[k]! + 2 * a1 * v1[k]! + a2 * v[k]! - a1 * a1 * u[k]!) as V3,
218
+ v: [0, 1, 2].map((k: number): number => v2[k]! - 2 * a1 * u1[k]! - a2 * u[k]! - a1 * a1 * v[k]!) as V3,
219
+ },
220
+ };
221
+ return AutoMovieViewAxisJet.parameter(rolled, parameter, station);
222
+ },
223
+ }),
224
+ };
225
+ }
226
+
227
+ /** The family's field vector at one station. */
228
+ export function reader(family: Pick<IFamily, "knots" | "values">): (s: number) => number[] {
229
+ const splines: AutoMovieNaturalSpline.ISpline[] = family.values.map((field: number[]): AutoMovieNaturalSpline.ISpline => AutoMovieNaturalSpline.create(family.knots, field));
230
+ return (s: number): number[] => splines.map((spline: AutoMovieNaturalSpline.ISpline): number => AutoMovieNaturalSpline.evaluate(spline, s));
231
+ }
232
+
233
+ /**
234
+ * The engine's view part of a family.
235
+ *
236
+ * The engine reads a section as four guides on its box with conic pieces
237
+ * between them. Those guide coordinates, touch offsets, piece points,
238
+ * tangent angles and shoulders are not authored: at every requested
239
+ * station they are resolved from the family's fields through
240
+ * `AutoMovieHumanConicSection.resolve` and handed over as derived outlines
241
+ * with one knot per station.
242
+ *
243
+ * @param family The authored definition.
244
+ * @param stations Stations of the emitted layers and of the derived outlines, mm, increasing.
245
+ */
246
+ export function part(family: IFamily, requested: number[]): IAutoMovieViewPart {
247
+ const read: (s: number) => number[] = reader(family);
248
+ const [bottom, top]: [ITip | null, ITip | null] = family.tips ?? [null, null];
249
+
250
+ // The fields own the stations between the caps; each cap starts on a station of its own.
251
+ const owned: number[] = [
252
+ ...(bottom === null ? [] : [bottom.from]),
253
+ ...requested.filter((s: number): boolean => (bottom === null || s > bottom.from) && (top === null || s < top.from)),
254
+ ...(top === null ? [] : [top.from]),
255
+ ];
256
+
257
+ // The engine reads every derived number between two stations by its own spline, not through the section model, so where the model's
258
+ // section turns faster than that reading follows, the engine's chain loses an arc though the model's never does. Wherever the model's
259
+ // section midway between two stations stands off the mean of their two by more than the tolerances, the midway station is added.
260
+ const resolved: Map<number, AutoMovieHumanConicSection.IChain> = new Map();
261
+ const at = (s: number): AutoMovieHumanConicSection.IChain => {
262
+ let chain: AutoMovieHumanConicSection.IChain | undefined = resolved.get(s);
263
+ if (chain === undefined) resolved.set(s, (chain = AutoMovieHumanConicSection.resolve(read(s), family.layout)));
264
+ return chain;
265
+ };
266
+ const between = (a: number, b: number): number[] => {
267
+ if (b - a <= 2 * REFINE.least) return [];
268
+ const middle: number = (a + b) / 2;
269
+ const [low, mid, high]: AutoMovieHumanConicSection.IChain[] = [at(a), at(middle), at(b)];
270
+ const off: boolean = mid!.input.points.some((p: AutoMovieHumanConicSection.P, k: number): boolean => {
271
+ const turn = (t: AutoMovieHumanConicSection.P): number => Math.atan2(t[1], t[0]);
272
+ const swing: number = turn(high!.input.tangents[k]!) - turn(low!.input.tangents[k]!);
273
+ const lean: number = turn(mid!.input.tangents[k]!) - turn(low!.input.tangents[k]!) - (swing - 2 * Math.PI * Math.round(swing / (2 * Math.PI))) / 2;
274
+ return (
275
+ Math.abs(p[0] - (low!.input.points[k]![0] + high!.input.points[k]![0]) / 2) > REFINE.length ||
276
+ Math.abs(p[1] - (low!.input.points[k]![1] + high!.input.points[k]![1]) / 2) > REFINE.length ||
277
+ Math.abs(lean - 2 * Math.PI * Math.round(lean / (2 * Math.PI))) > REFINE.share ||
278
+ Math.abs(mid!.input.shoulders[k]! - (low!.input.shoulders[k]! + high!.input.shoulders[k]!) / 2) > REFINE.share
279
+ );
280
+ });
281
+ return off ? [...between(a, middle), middle, ...between(middle, b)] : [];
282
+ };
283
+ const stations: number[] = owned.flatMap((s: number, i: number): number[] => (i === 0 ? [s] : [...between(owned[i - 1]!, s), s]));
284
+ const chains: AutoMovieHumanConicSection.IChain[] = stations.map(at);
285
+ const count: number = chains[0]!.input.points.length;
286
+ const guides: number[] = chains[0]!.guides;
287
+ if (guides.length !== 4) throw new Error("the layout names " + guides.length + " engine guides instead of four");
288
+
289
+ // The wall's taper at a cap's first section: the relative growth of the mean of its four extents over a millimetre away from the tip,
290
+ // times the cap's length, held to [TAPER.least, TAPER.most].
291
+ const size = (s: number): number => {
292
+ const chain: AutoMovieHumanConicSection.IChain = AutoMovieHumanConicSection.resolve(read(s), family.layout);
293
+ return chain.guides.reduce((sum: number, g: number, q: number): number => sum + Math.abs(chain.input.points[g]![q % 2]), 0);
294
+ };
295
+ const taper = (end: ITip): number => {
296
+ const inward: number = Math.sign(end.from - end.tip);
297
+ return Math.min(TAPER.most, Math.max(TAPER.least, (size(end.from + inward) / size(end.from) - 1) * Math.abs(end.from - end.tip)));
298
+ };
299
+
300
+ // The wall's bend at a cap's first section in the cap's own measure: the second difference of the mean extent over millimetres away from
301
+ // the tip, relative to the extent, times the square of the cap's length.
302
+ const bend = (end: ITip): number => {
303
+ const inward: number = Math.sign(end.from - end.tip);
304
+ const [s0, s1, s2]: number[] = [0, 1, 2].map((k: number): number => size(end.from + k * inward));
305
+ return ((s2! - 2 * s1! + s0!) / s0!) * (end.from - end.tip) ** 2;
306
+ };
307
+
308
+ // The cap's knots and its rings both stand at equal steps of the root of the distance to the tip, the engine's pole parameter.
309
+ const capShares: number[] = Array.from({ length: CAP_KNOTS + 1 }, (_: unknown, k: number): number => k / (CAP_KNOTS + 1));
310
+
311
+ // A coordinate is zero at a tip; an angle or a shoulder keeps the cap's first section's value there. Each cap knot is that section scaled
312
+ // by the tip's factor (`ITip`).
313
+ // A coordinate along chart axis `along` gathers about the end's `centre` while it shrinks (`ITip.centre`).
314
+ // With `own`, a coordinate that stands clear of its centre takes the taper and the bend of its own outline (`ITip.own`), from its values
315
+ // one and two millimetres away from the tip.
316
+ const cap = (end: ITip, value: number, along: 0 | 1 | null, site: string, pick?: (chain: AutoMovieHumanConicSection.IChain) => number): IAutoMovieViewPart.IKnot[] => {
317
+ const middle: number = along === null ? 0 : (end.centre?.[along] ?? 0);
318
+ const inward: number = Math.sign(end.from - end.tip);
319
+ const length: number = Math.abs(end.from - end.tip);
320
+ const [x1, x2]: number[] = end.own === true && along !== null && pick !== undefined ? [1, 2].map((k: number): number => pick(AutoMovieHumanConicSection.resolve(read(end.from + k * inward), family.layout))) : [NaN, NaN];
321
+ const x0: number = value;
322
+ const own: boolean = Number.isFinite(x1) && Math.abs(x0) > OWN_LEAST * size(end.from);
323
+ const q: number = own ? Math.min(TAPER.most, Math.max(TAPER.least, (x1! / x0 - 1) * length)) : taper(end);
324
+ const c: number = end.covered === true ? 0 : Math.max(0, (1 - q) ** 2 + (own ? ((x2! - 2 * x1! + x0) / x0) * length ** 2 : bend(end)));
325
+ const b: number = 2 * q - 1 - 2 * c;
326
+ const a: number = 1 - b - c;
327
+ return capShares.map((x: number, k: number): IAutoMovieViewPart.IKnot => {
328
+ const t: number = x * x;
329
+ const g: number = Math.sqrt(t * (a + t * (b + t * c)));
330
+ return { site: site + "." + k, station: end.tip + (end.from - end.tip) * t, value: along === null ? value : value * g + 2 * middle * g * (1 - g) ** 2 };
331
+ });
332
+ };
333
+
334
+ // The cap's rings: without them the engine meshed a cap from its first section straight to its pole, a cone ending in a flat disc.
335
+ const rings = (end: ITip): number[] =>
336
+ (end.rings === undefined ? capShares : Array.from({ length: end.rings + 1 }, (_: unknown, k: number): number => k / (end.rings! + 1))).slice(1).map((x: number): number => end.tip + (end.from - end.tip) * x * x);
337
+ const closing = (pick: (chain: AutoMovieHumanConicSection.IChain) => number, along: 0 | 1 | null): IAutoMovieViewPart.IOutline => ({
338
+ knots: [
339
+ ...(bottom === null ? [] : cap(bottom, pick(chains[0]!), along, "tip.bottom", pick)),
340
+ ...stations.map((station: number, i: number): IAutoMovieViewPart.IKnot => ({ site: "s" + i, station, value: pick(chains[i]!) })),
341
+ ...(top === null ? [] : cap(top, pick(chains.at(-1)!), along, "tip.top", pick).reverse()),
342
+ ],
343
+ });
344
+ const outline = (pick: (chain: AutoMovieHumanConicSection.IChain) => number, along: 0 | 1): IAutoMovieViewPart.IOutline => closing(pick, along);
345
+ const share = (pick: (chain: AutoMovieHumanConicSection.IChain) => number): IAutoMovieViewPart.IOutline => closing(pick, null);
346
+ const quarters = <X>(make: (q: number) => X): IAutoMovieViewPart.IQuarters<X> => [make(0), make(1), make(2), make(3)];
347
+
348
+ // A tangent angle is kept on one branch along the station so its outline never jumps by a turn.
349
+ const angle = (at: number): IAutoMovieViewPart.IOutline => {
350
+ let previous: number = NaN;
351
+ return share((chain: AutoMovieHumanConicSection.IChain): number => {
352
+ let value: number = Math.atan2(chain.input.tangents[at]![1], chain.input.tangents[at]![0]);
353
+ if (Number.isFinite(previous)) value += 2 * Math.PI * Math.round((previous - value) / (2 * Math.PI));
354
+ previous = value;
355
+ return value;
356
+ });
357
+ };
358
+ const pieces = (q: number): IAutoMovieViewPart.ISplit[] => {
359
+ const out: IAutoMovieViewPart.ISplit[] = [];
360
+ for (let at: number = (guides[q]! + 1) % count; at !== guides[(q + 1) % 4]!; at = (at + 1) % count) {
361
+ const index: number = at;
362
+ out.push({ u: outline((chain: AutoMovieHumanConicSection.IChain): number => chain.input.points[index]![0], 0), v: outline((chain: AutoMovieHumanConicSection.IChain): number => chain.input.points[index]![1], 1), angle: angle(index), shoulder: share((chain: AutoMovieHumanConicSection.IChain): number => chain.input.shoulders[index]!) });
363
+ }
364
+ return out;
365
+ };
366
+ const coordinate = (q: number, axisIndex: 0 | 1): IAutoMovieViewPart.IOutline => outline((chain: AutoMovieHumanConicSection.IChain): number => chain.input.points[guides[q]!]![axisIndex], axisIndex);
367
+
368
+ // Phases round the part: its widest section's girth, as the ellipse on its half extents (Ramanujan's perimeter), at `PHASE_MM` apart.
369
+ const girth: number = Math.max(
370
+ ...chains.map((chain: AutoMovieHumanConicSection.IChain): number => {
371
+ const [a, b]: number[] = [0, 1].map((c: number): number => (Math.max(...chain.input.points.map((p: AutoMovieHumanConicSection.P): number => p[c]!)) - Math.min(...chain.input.points.map((p: AutoMovieHumanConicSection.P): number => p[c]!))) / 2);
372
+ return Math.PI * (3 * (a! + b!) - Math.sqrt((3 * a! + b!) * (a! + 3 * b!)));
373
+ }),
374
+ );
375
+
376
+ // And no farther apart than the finest relief net's columns, as the layers are cut to its rows: a net shows only what the rings sample.
377
+ const finest: number = Math.min(family.phase ?? Infinity, ...(family.reliefs ?? []).map((relief: IAutoMovieLoftRelief): number => (relief.phases[1] - relief.phases[0]) / (relief.columns - 3)));
378
+ const made: IAutoMovieViewPart = {
379
+ name: family.name,
380
+ axis: axis(family),
381
+ stations: [...(bottom === null ? [] : [bottom.tip, ...rings(bottom)]), ...stations, ...(top === null ? [] : [...rings(top).reverse(), top.tip])],
382
+ ...(bottom === null && top === null ? {} : { pole: bottom === null ? ("top" as const) : top === null ? ("bottom" as const) : ("both" as const) }),
383
+ front: { positive: coordinate(0, 0), negative: coordinate(2, 0) },
384
+ side: { positive: coordinate(1, 1), negative: coordinate(3, 1) },
385
+ fullness: { kind: "top", shoulders: quarters((q: number): IAutoMovieViewPart.IOutline => share((chain: AutoMovieHumanConicSection.IChain): number => chain.input.shoulders[guides[q]!]!)), touch: quarters((q: number): IAutoMovieViewPart.IOutline => coordinate(q, q % 2 === 0 ? 1 : 0)), pieces: quarters(pieces) },
386
+ order: 32,
387
+ samples: Math.max(48, 8 * Math.ceil(Math.max(girth / (family.pitch ?? PHASE_MM), (2 * Math.PI) / finest) / 8)),
388
+ ...(family.reliefs === undefined || family.reliefs.length === 0 ? {} : { reliefs: family.reliefs }),
389
+ };
390
+ if (family.turn === undefined) return made;
391
+
392
+ // Phases spaced by turn: read on the part's own lofted chain, whose phase is its sections' B-spline parameter, not their conics' polar
393
+ // angle. Read on the conics, the phases of a flat section 40 by 5 mm clustered where its conics turn and its rings still turned by
394
+ // 0.46 rad between two of them, against 0.1 asked.
395
+ const loft: AutoMovieViewLoft.IResult = AutoMovieViewLoft.create(made);
396
+ if (loft.chain === null) return made;
397
+ const phases: number[] = spaced(loft.chain, stations, family.pitch ?? PHASE_MM, family.turn, finest);
398
+ return { ...made, samples: phases.length, phases };
399
+ }
400
+
401
+ /** Phases round a ring that `spaced` reads its length and turn on. */
402
+ const SPACING_SAMPLES: number = 1024;
403
+
404
+ /**
405
+ * A part's ring phases spaced by its rings' length and turn (`IFamily.turn`).
406
+ *
407
+ * Every station's ring of the lofted chain is read at `SPACING_SAMPLES` phases. Over each step between two of them the density is the
408
+ * largest any ring asks for: its chord over `pitch`, its turn there over `turn`, or the step over `finest`, the finest relief net's
409
+ * column. The phases stand at equal shares of that density's integral from phase 0, a multiple of 8 of them and at least 48, as the
410
+ * uniform rule's count is.
411
+ *
412
+ * @param chain The part lofted on uniform phases.
413
+ * @param stations The stations its fields own, mm.
414
+ * @param pitch Largest distance between neighbouring phases, mm.
415
+ * @param turn Largest turn between neighbouring phases, radians.
416
+ * @param finest Finest relief net's column, radians.
417
+ */
418
+ function spaced(chain: NonNullable<AutoMovieViewLoft.IResult["chain"]>, stations: readonly number[], pitch: number, turn: number, finest: number): number[] {
419
+ const M: number = SPACING_SAMPLES;
420
+ const step: number = (2 * Math.PI) / M;
421
+ const density: number[] = new Array<number>(M).fill(step / finest);
422
+ const unit = (a: readonly number[], b: readonly number[]): number[] => {
423
+ const d: number[] = [b[0]! - a[0]!, b[1]! - a[1]!, b[2]! - a[2]!];
424
+ const l: number = Math.hypot(d[0]!, d[1]!, d[2]!);
425
+ return d.map((x: number): number => x / l);
426
+ };
427
+ for (const s of stations) {
428
+ const ring: number[][] = Array.from({ length: M }, (_: unknown, j: number): number[] => AutoMovieLoftChain.point(chain, s, j * step));
429
+ if (ring.some((p: number[]): boolean => !p.every(Number.isFinite))) continue;
430
+ // Over the step from sample j to j + 1: its chord, and the larger of the turns at its two ends.
431
+ const turns: number[] = ring.map((b: number[], j: number): number => {
432
+ const [u, w]: number[][] = [unit(ring[(j + M - 1) % M]!, b), unit(b, ring[(j + 1) % M]!)];
433
+ return Math.acos(Math.max(-1, Math.min(1, u[0]! * w[0]! + u[1]! * w[1]! + u[2]! * w[2]!)));
434
+ });
435
+ for (let j: number = 0; j < M; ++j) {
436
+ const [b, c]: number[][] = [ring[j]!, ring[(j + 1) % M]!];
437
+ const chord: number = Math.hypot(c[0]! - b[0]!, c[1]! - b[1]!, c[2]! - b[2]!);
438
+ density[j] = Math.max(density[j]!, chord / pitch, Math.max(turns[j]!, turns[(j + 1) % M]!) / turn);
439
+ }
440
+ }
441
+ const total: number = density.reduce((sum: number, x: number): number => sum + x, 0);
442
+ const count: number = Math.max(48, 8 * Math.ceil(total / 8));
443
+ const phases: number[] = [];
444
+ let below: number = 0;
445
+ for (let j: number = 0, k: number = 0; j < M && k < count; ++j) {
446
+ // The phases whose share of the integral falls in this step, read linearly within it.
447
+ while (k < count && (total * k) / count <= below + density[j]! + 1e-12) {
448
+ phases.push((j + ((total * k) / count - below) / density[j]!) * step);
449
+ ++k;
450
+ }
451
+ below += density[j]!;
452
+ }
453
+ return phases;
454
+ }
455
+
456
+ /**
457
+ * The family's twin across the median plane `z = 0`, as a family of its own.
458
+ *
459
+ * The course and the chart seed are reflected, and the roll negated. A course's chart is `v = u x t`, so the reflected course charts the
460
+ * reflected section with `v` negated, which also reverses its travel: the twin's anchors are the original's in reverse
461
+ * order from the first, each extreme with its `v` negated, and the arc after the twin's anchor `j` is the original's arc
462
+ * before its anchor `K - j`. A feature point is read again on the twin's frame from the reflected section at every knot. An inflection's neighbours swap, so its share is `1 - t` and its turn `-d`, and the twin's
463
+ * dependent anchors keep the original's order of resolution. A relief keeps its stations and heights and takes the
464
+ * negated phase window, the reflected axis and its columns in reverse.
465
+ *
466
+ * @param family A family whose layout is not itself a mirror layout.
467
+ * @param name The twin's chain name.
468
+ */
469
+ export function mirror(family: IFamily, name: string): IFamily {
470
+ const anchors: AutoMovieHumanConicSection.IAnchor[] = family.layout.anchors;
471
+ const K: number = anchors.length;
472
+ if (family.layout.mirror) throw new Error("mirror: the layout of " + family.name + " cannot be reflected");
473
+ const { at, shoulders }: { at: number[]; shoulders: number } = AutoMovieHumanConicSection.offsets(family.layout);
474
+
475
+ // Dependent anchors of one level are resolved in index order, each on the nearest anchors already resolved, so a groove's second
476
+ // inflection stands on its first one's chord. Reversed, the twin would resolve them the other way round; it keeps the original's order
477
+ // by a tie-break under one level.
478
+ const order: number[] = AutoMovieHumanConicSection.dependents(family.layout);
479
+ const resolved = (anchor: AutoMovieHumanConicSection.IAnchor, k: number): AutoMovieHumanConicSection.IAnchor =>
480
+ anchor.kind === "m" || anchor.kind === "i" ? { ...anchor, level: (anchor.level ?? 1) + order.indexOf(k) / (2 * order.length) } : anchor;
481
+ const values: number[][] = [];
482
+ for (let j: number = 0; j < K; ++j) {
483
+ const k: number = (K - j) % K;
484
+ const anchor: AutoMovieHumanConicSection.IAnchor = anchors[k]!;
485
+ // An inflection stands on its neighbours' chord, and the reversed order swaps its neighbours: its share is read from the other end
486
+ // (`1 - t`), and its turn from the chord, reflected and travelled the other way, changes sign.
487
+ if (anchor.kind === "i") {
488
+ values.push(family.values[at[k]!]!.map((t: number): number => 1 - t), family.values[at[k]! + 1]!.map((d: number): number => -d));
489
+ continue;
490
+ }
491
+ // A feature point stands on its frame's chord (`AutoMovieHumanConicSection.frame`), and reversed, a run's features stand on other
492
+ // frames (the last one first, on the chord to the next extreme): its numbers are read again below, knot by knot, on the twin's frames.
493
+ if (anchor.kind === "f") {
494
+ values.push(family.values[at[k]!]!.map((): number => 0), family.values[at[k]! + 1]!.map((): number => 0), family.values[at[k]! + 2]!.map((): number => 0));
495
+ continue;
496
+ }
497
+ values.push([...family.values[at[k]!]!]);
498
+ if (anchor.kind !== "m" && anchor.mid !== true) values.push(family.values[at[k]! + 1]!.map((v: number): number => -v));
499
+ }
500
+ for (let j: number = 0; j < K; ++j) values.push([...family.values[shoulders + (K - j - 1)]!]);
501
+ // Each feature's numbers on the twin: at every knot the original section is resolved, its points reflected (`v` negated) and its
502
+ // tangents reflected and travelled the other way, and each feature is read on its twin frame's chord (`unplace`): the reflected point
503
+ // and direction, so the twin's section at every knot is the original's reflection.
504
+ const twinLayout: AutoMovieHumanConicSection.ILayout = { mirror: false, anchors: anchors.map((_: AutoMovieHumanConicSection.IAnchor, j: number): AutoMovieHumanConicSection.IAnchor => anchors[(K - j) % K]!) };
505
+ const twinAt: number[] = AutoMovieHumanConicSection.offsets(twinLayout).at;
506
+ if (anchors.some((anchor: AutoMovieHumanConicSection.IAnchor): boolean => anchor.kind === "f"))
507
+ family.knots.forEach((_: number, m: number): void => {
508
+ const input = AutoMovieHumanConicSection.resolve(family.values.map((field: number[]): number => field[m]!), family.layout).input;
509
+ const points: AutoMovieHumanConicSection.P[] = Array.from({ length: K }, (__: unknown, j: number): AutoMovieHumanConicSection.P => {
510
+ const p = input.points[(K - j) % K]!;
511
+ return [p[0], -p[1]];
512
+ });
513
+ let previous: number = 0;
514
+ for (let j: number = 0; j < K; ++j) {
515
+ if (anchors[(K - j) % K]!.kind !== "f") continue;
516
+ if (j === 0 || anchors[(K - j + 1) % K]!.kind !== "f") previous = 0;
517
+ const t = input.tangents[(K - j) % K]!;
518
+ const [before, after]: [number, number] = AutoMovieHumanConicSection.frame(j, twinLayout);
519
+ const read: { values: [number, number, number]; t: number } = AutoMovieHumanConicSection.unplace(points[before]!, points[after]!, points[j]!, Math.atan2(t[1], -t[0]), previous);
520
+ previous = read.t;
521
+ values[twinAt[j]!]![m] = read.values[0];
522
+ values[twinAt[j]! + 1]![m] = read.values[1];
523
+ values[twinAt[j]! + 2]![m] = read.values[2];
524
+ }
525
+ });
526
+ const flip = (v: V3): V3 => [v[0], v[1], -v[2]];
527
+ return {
528
+ name,
529
+ centres: family.centres.map(flip),
530
+ halves: [...family.halves],
531
+ up: flip(family.up),
532
+ // The reflected chart's `v` is the reflection's negated, so a turn from `u` toward `v` is the reflected turn negated.
533
+ ...(family.roll === undefined ? {} : { roll: { knots: [...family.roll.knots], values: family.roll.values.map((angle: number): number => -angle) } }),
534
+ // The twin's anchor `j` is the original's `(K - j) % K`, so its arc `j`, from anchor `j` to `j + 1`, is the original's arc `K - 1 - j`
535
+ // run backwards, and a least per arc is read in that order.
536
+ layout: {
537
+ mirror: false,
538
+ anchors: anchors.map((_: AutoMovieHumanConicSection.IAnchor, j: number): AutoMovieHumanConicSection.IAnchor => resolved(anchors[(K - j) % K]!, (K - j) % K)),
539
+ ...(family.layout.least === undefined ? {} : { least: typeof family.layout.least === "number" ? family.layout.least : anchors.map((_: AutoMovieHumanConicSection.IAnchor, j: number): number => AutoMovieHumanConicSection.leastOf(family.layout, K - 1 - j)!) }),
540
+ },
541
+ knots: [...family.knots],
542
+ values,
543
+ // A cap's centre lies in the chart, whose `v` the twin negates.
544
+ ...(family.tips === undefined ? {} : { tips: family.tips.map((tip: ITip | null): ITip | null => (tip === null || tip.centre === undefined ? tip : { ...tip, centre: [tip.centre[0], -tip.centre[1]] })) as [ITip | null, ITip | null] }),
545
+ ...(family.pitch === undefined ? {} : { pitch: family.pitch }),
546
+ ...(family.turn === undefined ? {} : { turn: family.turn }),
547
+ ...(family.reliefs === undefined
548
+ ? {}
549
+ : {
550
+ reliefs: family.reliefs.map((relief: IAutoMovieLoftRelief): IAutoMovieLoftRelief => {
551
+ const turn: number = relief.phases[1] > 0 ? 2 * Math.PI : 0;
552
+ const reverse = (net: number[]): number[] => net.map((_: number, i: number): number => net[i - (i % relief.columns) + relief.columns - 1 - (i % relief.columns)]!);
553
+ return { ...relief, name: relief.name + ".mirror", phases: [turn - relief.phases[1], turn - relief.phases[0]], axis: flip(relief.axis), heights: reverse(relief.heights), ...(relief.shift === undefined ? {} : { shift: reverse(relief.shift) }),
554
+ // The twin's phases run the other way, so its turning direction is the reflected one negated.
555
+ ...(relief.turn === undefined ? {} : { turn: flip(relief.turn).map((x: number): number => -x) as [number, number, number] }),
556
+ };
557
+ }),
558
+ }),
559
+ };
560
+ }
561
+
562
+ /** Loft a family through the engine. */
563
+ export function create(family: IFamily, stations: number[]): AutoMovieViewLoft.IResult {
564
+ return AutoMovieViewLoft.create(part(family, stations));
565
+ }
566
+ }