@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.
- package/README.md +29 -16
- package/lib/generation/AutoMovieHumanDigitJoints.d.ts +8 -26
- package/lib/generation/AutoMovieHumanDigitJoints.js +9 -37
- package/lib/generation/AutoMovieHumanDigitJoints.js.map +1 -1
- package/lib/generation/{AutoMovieHumanLegSection.d.ts → AutoMovieHumanLegSectionProportion.d.ts} +1 -1
- package/lib/generation/{AutoMovieHumanLegSection.js → AutoMovieHumanLegSectionProportion.js} +17 -14
- package/lib/generation/AutoMovieHumanLegSectionProportion.js.map +1 -0
- package/lib/generation/arm/AutoMovieHumanArmFrame.js +2 -2
- package/lib/generation/arm/AutoMovieHumanArmFrame.js.map +1 -1
- package/lib/generation/arm/index.d.ts +28 -0
- package/lib/generation/arm/index.js +45 -0
- package/lib/generation/arm/index.js.map +1 -0
- package/lib/generation/conic/AutoMovieHumanConicLoft.d.ts +154 -0
- package/lib/generation/conic/AutoMovieHumanConicLoft.js +430 -0
- package/lib/generation/conic/AutoMovieHumanConicLoft.js.map +1 -0
- package/lib/generation/conic/AutoMovieHumanConicPose.d.ts +92 -0
- package/lib/generation/conic/AutoMovieHumanConicPose.js +202 -0
- package/lib/generation/conic/AutoMovieHumanConicPose.js.map +1 -0
- package/lib/generation/conic/AutoMovieHumanConicRelief.d.ts +52 -0
- package/lib/generation/conic/AutoMovieHumanConicRelief.js +88 -0
- package/lib/generation/conic/AutoMovieHumanConicRelief.js.map +1 -0
- package/lib/generation/conic/AutoMovieHumanConicSection.d.ts +252 -0
- package/lib/generation/conic/AutoMovieHumanConicSection.js +567 -0
- package/lib/generation/conic/AutoMovieHumanConicSection.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1.d.ts +265 -0
- package/lib/generation/f1/AutoMovieHumanF1.js +1254 -0
- package/lib/generation/f1/AutoMovieHumanF1.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Antihelix.d.ts +23 -0
- package/lib/generation/f1/AutoMovieHumanF1Antihelix.js +65 -0
- package/lib/generation/f1/AutoMovieHumanF1Antihelix.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Arm.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Arm.js +82 -0
- package/lib/generation/f1/AutoMovieHumanF1Arm.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Axilla.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Axilla.js +91 -0
- package/lib/generation/f1/AutoMovieHumanF1Axilla.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Breast.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Breast.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1Breast.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Concha.d.ts +40 -0
- package/lib/generation/f1/AutoMovieHumanF1Concha.js +81 -0
- package/lib/generation/f1/AutoMovieHumanF1Concha.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerIndex.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerIndex.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerMiddle.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerPinky.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerPinky.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerRing.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerRing.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerRing.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerThumb.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1FingerThumb.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Frames.d.ts +97 -0
- package/lib/generation/f1/AutoMovieHumanF1Frames.js +160 -0
- package/lib/generation/f1/AutoMovieHumanF1Frames.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Hand.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Hand.js +81 -0
- package/lib/generation/f1/AutoMovieHumanF1Hand.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Helix.d.ts +20 -0
- package/lib/generation/f1/AutoMovieHumanF1Helix.js +64 -0
- package/lib/generation/f1/AutoMovieHumanF1Helix.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Joints.d.ts +231 -0
- package/lib/generation/f1/AutoMovieHumanF1Joints.js +249 -0
- package/lib/generation/f1/AutoMovieHumanF1Joints.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Landmarks.d.ts +86 -0
- package/lib/generation/f1/AutoMovieHumanF1Landmarks.js +89 -0
- package/lib/generation/f1/AutoMovieHumanF1Landmarks.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Leg.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Leg.js +82 -0
- package/lib/generation/f1/AutoMovieHumanF1Leg.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Nose.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Nose.js +82 -0
- package/lib/generation/f1/AutoMovieHumanF1Nose.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Nostril.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Nostril.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1Nostril.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Placement.d.ts +75 -0
- package/lib/generation/f1/AutoMovieHumanF1Placement.js +151 -0
- package/lib/generation/f1/AutoMovieHumanF1Placement.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Placing.d.ts +45 -0
- package/lib/generation/f1/AutoMovieHumanF1Placing.js +301 -0
- package/lib/generation/f1/AutoMovieHumanF1Placing.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Plate.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Plate.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1Plate.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeBig.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeBig.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeBig.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeIndex.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js +59 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeIndex.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeLittle.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeLittle.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeMiddle.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeRing.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeRing.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1ToeRing.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Trunk.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Trunk.js +79 -0
- package/lib/generation/f1/AutoMovieHumanF1Trunk.js.map +1 -0
- package/lib/generation/f1/AutoMovieHumanF1Vault.d.ts +18 -0
- package/lib/generation/f1/AutoMovieHumanF1Vault.js +75 -0
- package/lib/generation/f1/AutoMovieHumanF1Vault.js.map +1 -0
- package/lib/generation/foot/index.d.ts +51 -0
- package/lib/generation/foot/index.js +68 -0
- package/lib/generation/foot/index.js.map +1 -0
- package/lib/generation/frame/AutoMovieHumanSegmentFrame.d.ts +149 -0
- package/lib/generation/frame/AutoMovieHumanSegmentFrame.js +290 -0
- package/lib/generation/frame/AutoMovieHumanSegmentFrame.js.map +1 -0
- package/lib/generation/hand/index.d.ts +53 -0
- package/lib/generation/hand/index.js +70 -0
- package/lib/generation/hand/index.js.map +1 -0
- package/lib/generation/head/index.d.ts +37 -0
- package/lib/generation/head/index.js +54 -0
- package/lib/generation/head/index.js.map +1 -0
- package/lib/generation/index.d.ts +176 -0
- package/lib/generation/index.js +193 -0
- package/lib/generation/index.js.map +1 -0
- package/lib/generation/leg/AutoMovieHumanLegLaws.d.ts +1 -1
- package/lib/generation/leg/AutoMovieHumanLegLaws.js +23 -11
- package/lib/generation/leg/AutoMovieHumanLegLaws.js.map +1 -1
- package/lib/generation/leg/index.d.ts +34 -0
- package/lib/generation/leg/index.js +51 -0
- package/lib/generation/leg/index.js.map +1 -0
- package/lib/generation/limb/{AutoMovieHumanJointTurn.d.ts → AutoMovieHumanBendArc.d.ts} +1 -1
- package/lib/generation/limb/{AutoMovieHumanJointTurn.js → AutoMovieHumanBendArc.js} +12 -8
- package/lib/generation/limb/AutoMovieHumanBendArc.js.map +1 -0
- package/lib/generation/limb/AutoMovieHumanDigitWalk.js +2 -2
- package/lib/generation/limb/AutoMovieHumanDigitWalk.js.map +1 -1
- package/lib/generation/limb/AutoMovieHumanWalkPart.js +72 -17
- package/lib/generation/limb/AutoMovieHumanWalkPart.js.map +1 -1
- package/lib/generation/limb/index.d.ts +12 -0
- package/lib/generation/limb/index.js +29 -0
- package/lib/generation/limb/index.js.map +1 -0
- package/lib/generation/trunk/index.d.ts +17 -0
- package/lib/generation/trunk/index.js +34 -0
- package/lib/generation/trunk/index.js.map +1 -0
- package/lib/generation/web/index.d.ts +14 -0
- package/lib/generation/web/index.js +31 -0
- package/lib/generation/web/index.js.map +1 -0
- package/lib/index.d.ts +14 -4
- package/lib/index.js +14 -9
- package/lib/index.js.map +1 -1
- package/lib/lofting/index.d.ts +14 -0
- package/lib/lofting/index.js +31 -0
- package/lib/lofting/index.js.map +1 -0
- package/lib/skeleton/AutoMovieHumanCanonicalBody.d.ts +7 -3
- package/lib/skeleton/AutoMovieHumanCanonicalBody.js +31 -3
- package/lib/skeleton/AutoMovieHumanCanonicalBody.js.map +1 -1
- package/lib/skeleton/AutoMovieHumanCanonicalProfile.d.ts +22 -31
- package/lib/skeleton/AutoMovieHumanCanonicalProfile.js +112 -172
- package/lib/skeleton/AutoMovieHumanCanonicalProfile.js.map +1 -1
- package/lib/skeleton/AutoMovieHumanCanonicalSolids.d.ts +65 -0
- package/lib/skeleton/AutoMovieHumanCanonicalSolids.js +105 -0
- package/lib/skeleton/AutoMovieHumanCanonicalSolids.js.map +1 -0
- package/lib/skeleton/index.d.ts +29 -0
- package/lib/skeleton/index.js +46 -0
- package/lib/skeleton/index.js.map +1 -0
- package/lib/structures/index.d.ts +2 -2
- package/lib/structures/index.js +2 -2
- package/lib/structures/index.js.map +1 -1
- package/lib/typings/index.d.ts +1 -1
- package/lib/typings/index.js +1 -1
- package/lib/typings/index.js.map +1 -1
- package/package.json +21 -13
- package/src/generation/AutoMovieHumanDigitJoints.ts +12 -47
- package/src/generation/{AutoMovieHumanLegSection.ts → AutoMovieHumanLegSectionProportion.ts} +15 -6
- package/src/generation/arm/AutoMovieHumanArmFrame.ts +2 -2
- package/src/generation/arm/index.ts +28 -0
- package/src/generation/conic/AutoMovieHumanConicLoft.ts +566 -0
- package/src/generation/conic/AutoMovieHumanConicPose.ts +213 -0
- package/src/generation/conic/AutoMovieHumanConicRelief.ts +94 -0
- package/src/generation/conic/AutoMovieHumanConicSection.ts +609 -0
- package/src/generation/f1/AutoMovieHumanF1.ts +1448 -0
- package/src/generation/f1/AutoMovieHumanF1Antihelix.ts +64 -0
- package/src/generation/f1/AutoMovieHumanF1Arm.ts +82 -0
- package/src/generation/f1/AutoMovieHumanF1Axilla.ts +90 -0
- package/src/generation/f1/AutoMovieHumanF1Breast.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1Concha.ts +80 -0
- package/src/generation/f1/AutoMovieHumanF1FingerIndex.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1FingerMiddle.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1FingerPinky.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1FingerRing.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1FingerThumb.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1Frames.ts +191 -0
- package/src/generation/f1/AutoMovieHumanF1Hand.ts +81 -0
- package/src/generation/f1/AutoMovieHumanF1Helix.ts +63 -0
- package/src/generation/f1/AutoMovieHumanF1Joints.ts +319 -0
- package/src/generation/f1/AutoMovieHumanF1Landmarks.ts +101 -0
- package/src/generation/f1/AutoMovieHumanF1Leg.ts +82 -0
- package/src/generation/f1/AutoMovieHumanF1Nose.ts +82 -0
- package/src/generation/f1/AutoMovieHumanF1Nostril.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1Placement.ts +148 -0
- package/src/generation/f1/AutoMovieHumanF1Placing.ts +313 -0
- package/src/generation/f1/AutoMovieHumanF1Plate.ts +59 -0
- package/src/generation/f1/AutoMovieHumanF1ToeBig.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1ToeIndex.ts +58 -0
- package/src/generation/f1/AutoMovieHumanF1ToeLittle.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1ToeMiddle.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1ToeRing.ts +74 -0
- package/src/generation/f1/AutoMovieHumanF1Trunk.ts +79 -0
- package/src/generation/f1/AutoMovieHumanF1Vault.ts +74 -0
- package/src/generation/foot/index.ts +51 -0
- package/src/generation/frame/AutoMovieHumanSegmentFrame.ts +309 -0
- package/src/generation/hand/index.ts +53 -0
- package/src/generation/head/index.ts +37 -0
- package/src/generation/index.ts +176 -0
- package/src/generation/leg/AutoMovieHumanLegLaws.ts +80 -25
- package/src/generation/leg/index.ts +34 -0
- package/src/generation/limb/{AutoMovieHumanJointTurn.ts → AutoMovieHumanBendArc.ts} +39 -11
- package/src/generation/limb/AutoMovieHumanDigitWalk.ts +2 -2
- package/src/generation/limb/AutoMovieHumanWalkPart.ts +163 -41
- package/src/generation/limb/index.ts +12 -0
- package/src/generation/trunk/index.ts +17 -0
- package/src/generation/web/index.ts +14 -0
- package/src/index.ts +14 -4
- package/src/lofting/index.ts +14 -0
- package/src/skeleton/AutoMovieHumanCanonicalBody.ts +53 -3
- package/src/skeleton/AutoMovieHumanCanonicalProfile.ts +153 -358
- package/src/skeleton/AutoMovieHumanCanonicalSolids.ts +175 -0
- package/src/skeleton/index.ts +29 -0
- package/src/structures/index.ts +2 -2
- package/src/typings/index.ts +1 -1
- package/lib/generation/AutoMovieHumanLegSection.js.map +0 -1
- package/lib/generation/limb/AutoMovieHumanJointTurn.js.map +0 -1
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import { AutoMovieViewChain } from "@automovie/engine";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One section of a conic family as a short vector of named shape numbers,
|
|
5
|
+
* read through a layout of anchors.
|
|
6
|
+
*
|
|
7
|
+
* A section is a closed chain of conic arcs through its anchors in
|
|
8
|
+
* increasing phase. Every anchor is a point whose tangent the layout fixes
|
|
9
|
+
* by rule, so no number is spent on a direction that anatomy already gives:
|
|
10
|
+
*
|
|
11
|
+
* - `u`: a point where the section runs parallel to the chart's `v` axis: a
|
|
12
|
+
* front or back extreme. Its numbers are its `u` and `v`; a `mid` anchor
|
|
13
|
+
* stands on the median line `v = 0` and has only `u`.
|
|
14
|
+
* - `v`: a point where the section runs parallel to the `u` axis: a side
|
|
15
|
+
* extreme. Its numbers are its `u` and `v`.
|
|
16
|
+
* - `m`: the median point of the conic triangle its two neighbours span:
|
|
17
|
+
* `S = M + f (A - M)` on the segment from the chord midpoint `M` to the
|
|
18
|
+
* meeting `A` of the neighbours' tangent lines, with the tangent parallel to
|
|
19
|
+
* the chord, as every conic has at its own median point. Its number is `f`.
|
|
20
|
+
* Its neighbours are the nearest anchors of a lower `level`, so medians
|
|
21
|
+
* nest: a level 2 median halves an arc a level 1 median already made.
|
|
22
|
+
* - `i`: an inflection between two neighbours whose tangents are parallel.
|
|
23
|
+
* An S-shaped stretch crosses its own chord once, at the inflection, so
|
|
24
|
+
* the point is `P0 + t (P2 - P0)` and its tangent is the chord's direction
|
|
25
|
+
* turned by `d`. Its numbers are `t` and `d`.
|
|
26
|
+
* - `f`: a point on one of the part's feature lines (a tip's ridge, a wing's
|
|
27
|
+
* top, a groove's floor or the inflection beside it), its tangent free. Each
|
|
28
|
+
* number is a field along the stations like every other, so the feature line
|
|
29
|
+
* is a smooth longitudinal control curve, the way an aircraft's lines are
|
|
30
|
+
* drawn, and a feature that fades away leaves its anchor on a smooth stretch.
|
|
31
|
+
* Every feature of a run stands on one chord, its frame's (`frame`: the
|
|
32
|
+
* extremes either side of the run), so the features keep their order round
|
|
33
|
+
* the section wherever they fade, as an `i` anchor keeps it. Its numbers are
|
|
34
|
+
* its share of what is left of that chord past the feature before it
|
|
35
|
+
* (`along`), its offset `o` square to the chord in millimetres outward, and
|
|
36
|
+
* its tangent's turn `h` from the chord's direction, radians (`place`). Read
|
|
37
|
+
* as free chart coordinates, f1's nose's six feature lines left that order
|
|
38
|
+
* at 146 of 157 stations where its alar crease and wing fade; each on the
|
|
39
|
+
* chord from the feature before it, a tenth of a millimetre at one feature
|
|
40
|
+
* turned the next one's chord past its arc's own turn and the fit stood
|
|
41
|
+
* against those walls in both directions.
|
|
42
|
+
*
|
|
43
|
+
* After the anchors come the shoulders, one per arc between consecutive
|
|
44
|
+
* anchors: the conic shoulder `rho = |M S| / |M A|` of the engine's native
|
|
45
|
+
* chain (`AutoMovieViewChain`). A `mirror` layout lists the anchors of the
|
|
46
|
+
* half `v >= 0` from the front median anchor to the back median anchor and
|
|
47
|
+
* reflects them, so a bilateral section spends its numbers once.
|
|
48
|
+
*
|
|
49
|
+
* Shares (`f`, `t`, shoulders) are confined to `[EDGE, 1 - EDGE]` inside the
|
|
50
|
+
* model itself, and shoulders to at most `FAIR`, so an offline fit, the
|
|
51
|
+
* authored numbers and the generated surface read one curve.
|
|
52
|
+
*/
|
|
53
|
+
export namespace AutoMovieHumanConicSection {
|
|
54
|
+
/** A planar chart point, millimetres. */
|
|
55
|
+
export type P = [number, number];
|
|
56
|
+
|
|
57
|
+
/** One anchor of a layout. */
|
|
58
|
+
export interface IAnchor {
|
|
59
|
+
/** The tangent rule, as the namespace describes. */
|
|
60
|
+
kind: "u" | "v" | "m" | "i" | "f";
|
|
61
|
+
|
|
62
|
+
/** A `u` anchor on the median line `v = 0`. */
|
|
63
|
+
mid?: boolean;
|
|
64
|
+
|
|
65
|
+
/** One of the four anchors the engine takes as its `+u`, `+v`, `-u`, `-v` guides, in that order along the chain. */
|
|
66
|
+
guide?: boolean;
|
|
67
|
+
|
|
68
|
+
/** Nesting level of an `m` or `i` anchor, 1 when absent: its neighbours are the nearest anchors of a lower level. */
|
|
69
|
+
level?: number;
|
|
70
|
+
|
|
71
|
+
/** The feature line an `f` anchor stands on, for its seed and its record; generation does not read it. */
|
|
72
|
+
feature?: "convex" | "concave" | "inflection";
|
|
73
|
+
|
|
74
|
+
/** Phase window in radians where an observation of this `u`, `v` or `f` anchor is sought; generation does not read it. */
|
|
75
|
+
window?: [number, number];
|
|
76
|
+
|
|
77
|
+
/** Whether an observation takes the window's largest or smallest coordinate; generation does not read it. */
|
|
78
|
+
pick?: "max" | "min";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The anchors of a section family. */
|
|
82
|
+
export interface ILayout {
|
|
83
|
+
/** Anchors in increasing phase; for a mirror layout the half from phase 0 to pi inclusive. */
|
|
84
|
+
anchors: IAnchor[];
|
|
85
|
+
|
|
86
|
+
/** Reflect the listed half in the median line `v = 0`. */
|
|
87
|
+
mirror: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Least shoulder an arc of this family takes; absent, only the model's edge bound holds. An arc whose shoulder lies far under the
|
|
91
|
+
* ellipse's `sqrt(2) - 1` hugs its chord and turns at its ends, and where two such arcs meet at an extreme the wall turns within a few
|
|
92
|
+
* millimetres: f1's trunk held 0.22 to 0.36 either side of its side extreme over the hips, turned 1.06 degrees a half millimetre there
|
|
93
|
+
* against 0.2 elsewhere, and drew an upright line down each hip. It is a family's own number, not the model's, because other walls
|
|
94
|
+
* (the face's, the leg's) were fitted with lower shoulders where their skin wants them.
|
|
95
|
+
*
|
|
96
|
+
* A list holds one least per arc, in the order of the shoulders (`leastOf`). The bound belongs to the arcs that need it, not to the
|
|
97
|
+
* whole section: f1's foot end was fitted under 0.3 for the two arcs at its top, whose corner drew a slot at the big toe's root, and
|
|
98
|
+
* the same bound held the sole's arc at 0.3 from 896 to 960 mm, where the skin wants a flatter arc, so the wall stood 1.0 to 1.7 mm
|
|
99
|
+
* under the sole and each section fitted alone without it came within 0.4 to 0.85 mm.
|
|
100
|
+
*/
|
|
101
|
+
least?: number | readonly number[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** What a field measures: millimetres, a share in (0, 1), or an angle in radians. */
|
|
105
|
+
export type Unit = "mm" | "share" | "angle";
|
|
106
|
+
|
|
107
|
+
/** The closed chain of a field vector with the positions of the engine's four guides in it. */
|
|
108
|
+
export interface IChain {
|
|
109
|
+
/** The native chain input: points, tangents and shoulders in increasing phase. */
|
|
110
|
+
input: AutoMovieViewChain.IInput;
|
|
111
|
+
|
|
112
|
+
/** Indices of the `+u`, `+v`, `-u`, `-v` guides in the chain. */
|
|
113
|
+
guides: number[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Bound of every share inside the model: a share at 0 or 1 is a degenerate conic the engine refuses. */
|
|
117
|
+
const EDGE: number = 0.03;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Largest shoulder an arc takes. A shoulder near 1 hugs its two tangent lines and turns at their meeting within a millimetre: f1's trunk
|
|
121
|
+
* fitted the tape's straight run between the thighs with shoulders of 0.91 to 0.96, and those arcs drew a crease up the front of each thigh
|
|
122
|
+
* that no net over the wall could take out. Held at this the wall stays fair, and what it leaves the net carries.
|
|
123
|
+
*/
|
|
124
|
+
const FAIR: number = 0.85;
|
|
125
|
+
|
|
126
|
+
/** Largest share of the way to a box corner that a guide's touch offset may take. */
|
|
127
|
+
const CORNER: number = 0.92;
|
|
128
|
+
|
|
129
|
+
/** The limb layout: four extremes, each quarter halved `depth` times by nested medians (4, 8 or 16 conics). */
|
|
130
|
+
export function limb(depth: number): ILayout {
|
|
131
|
+
let layout: ILayout = { mirror: false, anchors: (["max", "max", "min", "min"] as const).map((pick: "max" | "min", q: number): IAnchor => ({ kind: q % 2 === 0 ? "u" : "v", guide: true, pick })) };
|
|
132
|
+
for (let level: number = 1; level <= depth; ++level) layout = { mirror: false, anchors: layout.anchors.flatMap((anchor: IAnchor): IAnchor[] => [anchor, { kind: "m", level }]) };
|
|
133
|
+
return layout;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The lens layout: a long thin section with its length along the chart's `v`, its two faces' extremes on the median line `v = 0` and
|
|
138
|
+
* its two ends' extremes free, each quarter halved `depth` times by nested medians. A flat face has no one extreme: a free face extreme
|
|
139
|
+
* of a lens 30 mm long and 5 thick wandered from one end of its face to the other between neighbouring stations (the ear's plate), and
|
|
140
|
+
* the engine's chain between such stations was refused. On the median line each face's extreme stands where the course crosses the
|
|
141
|
+
* lens, at one number each, and the lens's two ends, where it turns, carry the free extremes.
|
|
142
|
+
*/
|
|
143
|
+
export function lens(depth: number): ILayout {
|
|
144
|
+
let layout: ILayout = {
|
|
145
|
+
mirror: false,
|
|
146
|
+
anchors: [
|
|
147
|
+
{ kind: "u", mid: true, guide: true, window: [-Math.PI / 2, Math.PI / 2] },
|
|
148
|
+
{ kind: "v", guide: true, pick: "max" },
|
|
149
|
+
{ kind: "u", mid: true, guide: true, window: [Math.PI / 2, (3 * Math.PI) / 2] },
|
|
150
|
+
{ kind: "v", guide: true, pick: "min" },
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
for (let level: number = 1; level <= depth; ++level) layout = { mirror: false, anchors: layout.anchors.flatMap((anchor: IAnchor): IAnchor[] => [anchor, { kind: "m", level }]) };
|
|
154
|
+
return layout;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The bilateral layout: the front and back extremes on the median line and one side extreme between them, each arc halved `depth` times
|
|
159
|
+
* by nested medians, the half reflected in the median line (4, 8 or 16 conics). A section symmetric about the median plane has its
|
|
160
|
+
* front and back extremes on that plane with their tangents square to it, so those extremes cost one number each and the half the rest;
|
|
161
|
+
* fitted as a limb, such a section spends twice the numbers and its front and back anchors wander off the median line wherever the
|
|
162
|
+
* front is flat, each drawing the crease where two conics meet along the skin.
|
|
163
|
+
*/
|
|
164
|
+
export function bilateral(depth: number): ILayout {
|
|
165
|
+
let anchors: IAnchor[] = [
|
|
166
|
+
{ kind: "u", mid: true, guide: true, window: [-Math.PI / 2, Math.PI / 2] },
|
|
167
|
+
{ kind: "v", guide: true, pick: "max" },
|
|
168
|
+
{ kind: "u", mid: true, guide: true, window: [Math.PI / 2, (3 * Math.PI) / 2] },
|
|
169
|
+
];
|
|
170
|
+
for (let level: number = 1; level <= depth; ++level) anchors = anchors.flatMap((anchor: IAnchor, k: number): IAnchor[] => (k < anchors.length - 1 ? [anchor, { kind: "m", level }] : [anchor]));
|
|
171
|
+
return { mirror: true, anchors };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The limb layout of the given median depth with a groove after each listed anchor: two inflections and the groove's own median between
|
|
176
|
+
* them, `[i, m, i]`, the inflections a level deeper than every median and the groove's median a level deeper again, so each inflection
|
|
177
|
+
* stands on the chord of the anchors round it and the groove's floor on the triangle of its two inflections. Across a family the
|
|
178
|
+
* inflections' shares and turns are fields like every other, so each groove's two inflection lines run along the stations as smooth
|
|
179
|
+
* curves, the way conic lofting draws a concavity with one more control line. On `limb(1)` a groove seeds an admissible chain only after
|
|
180
|
+
* a `u` extreme (anchors 0 and 4).
|
|
181
|
+
*
|
|
182
|
+
* @param depth The limb's median depth.
|
|
183
|
+
* @param after Indices into `limb(depth).anchors` after which a groove stands, each at most once.
|
|
184
|
+
*/
|
|
185
|
+
export function inflected(depth: number, after: readonly number[]): ILayout {
|
|
186
|
+
return {
|
|
187
|
+
mirror: false,
|
|
188
|
+
anchors: limb(depth).anchors.flatMap((anchor: IAnchor, k: number): IAnchor[] =>
|
|
189
|
+
after.includes(k) ? [anchor, { kind: "i", level: depth + 1 }, { kind: "m", level: depth + 2 }, { kind: "i", level: depth + 1 }] : [anchor],
|
|
190
|
+
),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** One run of feature anchors inserted after an anchor of a base layout (`featured`). */
|
|
195
|
+
export interface IFeatureRun {
|
|
196
|
+
/** Index in the base layout's anchors after which the run stands. */
|
|
197
|
+
after: number;
|
|
198
|
+
|
|
199
|
+
/** The feature anchors (`f`), in increasing phase. */
|
|
200
|
+
anchors: IAnchor[];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A base layout with feature runs inserted after given anchors, and the listed median anchors (`m`) of the base turned into feature
|
|
205
|
+
* anchors (`f`) at the same place in the order. Only the model's own anchor kinds are used.
|
|
206
|
+
*
|
|
207
|
+
* A median stands on the triangle of the nearest anchors already resolved when it is (`neighbours`), which are the feature anchors
|
|
208
|
+
* once any stand in its run, since features resolve before every median (`resolve`); its tangent is then parallel to a different
|
|
209
|
+
* chord (`resolve`: a median's tangent is its neighbours' chord). So a feature inserted beside a median moves that median, and no field
|
|
210
|
+
* vector of the featured layout reproduces the stored section there. Turned into a feature anchor, the old median keeps its own point
|
|
211
|
+
* and tangent, and a stored wall of the base layout converts exactly (`convert`): each inserted feature splits a stored conic arc at
|
|
212
|
+
* an interior point into two conic arcs, which de Casteljau's construction on the rational quadratic's homogeneous controls gives
|
|
213
|
+
* exactly (Farin, Curves and Surfaces for CAGD, rational quadratic Bezier curves).
|
|
214
|
+
*
|
|
215
|
+
* @param base The layout the features go into.
|
|
216
|
+
* @param runs After which anchor of `base` each run of feature anchors stands.
|
|
217
|
+
* @param freed Indices in `base` of median anchors (`m`) turned into feature anchors.
|
|
218
|
+
*/
|
|
219
|
+
export function featured(base: ILayout, runs: readonly IFeatureRun[], freed: readonly number[] = []): ILayout {
|
|
220
|
+
// A least per arc names the base's arcs, which the inserted features split; it has no reading on the featured layout.
|
|
221
|
+
if (typeof base.least === "object") throw new Error("featured: a least per arc does not carry over to inserted features");
|
|
222
|
+
for (const k of freed) if (base.anchors[k]?.kind !== "m") throw new Error(`featured: anchor ${k} of the base is not a median`);
|
|
223
|
+
return {
|
|
224
|
+
mirror: base.mirror,
|
|
225
|
+
...(base.least === undefined ? {} : { least: base.least }),
|
|
226
|
+
anchors: base.anchors.flatMap((anchor: IAnchor, k: number): IAnchor[] => [
|
|
227
|
+
freed.includes(k) ? { kind: "f", feature: "convex" } : anchor,
|
|
228
|
+
...runs.filter((r: IFeatureRun): boolean => r.after === k).flatMap((r: IFeatureRun): IAnchor[] => r.anchors),
|
|
229
|
+
]),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The field vector of `featured(base, runs, freed)` that draws the same closed chain as `values` on `base`: every base anchor where it
|
|
235
|
+
* was (a freed median as a feature at its own point and tangent), each run's features on the base arc that follows the anchor they
|
|
236
|
+
* stand after, at equal steps of their projection on their frame's chord between the arc's two ends (so a feature's share along the
|
|
237
|
+
* chord, the number a featured layout stores, is a smooth function of the base's fields), and every shoulder that of its piece of the
|
|
238
|
+
* base arc.
|
|
239
|
+
* A piece `[a, b]` of the rational quadratic with homogeneous controls `(P0, 1), (w P1, w), (P2, 1)` has the blossom controls
|
|
240
|
+
* `B(a, a)`, `B(a, b)`, `B(b, b)`, so its middle weight normalised by its end weights is `W1 / sqrt(W0 W2)` and its shoulder
|
|
241
|
+
* `w / (1 + w)` (the shoulder `rho = |M S| / |M A|` of a conic of middle weight `w`).
|
|
242
|
+
*
|
|
243
|
+
* @param values A section's field vector on `base`.
|
|
244
|
+
* @param base Its layout.
|
|
245
|
+
* @param runs The inserted feature runs (`featured`); a run after anchor `k` lies on the base arc from anchor `k` to `k + 1`.
|
|
246
|
+
* @param freed The base medians turned into features.
|
|
247
|
+
* @returns The field vector on `featured(base, runs, freed)`.
|
|
248
|
+
*/
|
|
249
|
+
export function convert(values: readonly number[], base: ILayout, runs: readonly IFeatureRun[], freed: readonly number[] = []): number[] {
|
|
250
|
+
const target: ILayout = featured(base, runs, freed);
|
|
251
|
+
const chain: AutoMovieViewChain.IInput = resolve(values, base).input;
|
|
252
|
+
const K: number = base.anchors.length;
|
|
253
|
+
const arcs: number = base.mirror ? K - 1 : K;
|
|
254
|
+
// The base arc `k` as homogeneous controls: its ends, and the meeting of their tangents weighted by the arc's middle weight.
|
|
255
|
+
const controls = (k: number): { p: [P, P, P]; w: number } => {
|
|
256
|
+
const p0: P = chain.points[k] as P;
|
|
257
|
+
const p2: P = chain.points[(k + 1) % chain.points.length] as P;
|
|
258
|
+
const rho: number = chain.shoulders[k]!;
|
|
259
|
+
return { p: [p0, meet(p0, chain.tangents[k] as P, p2, chain.tangents[(k + 1) % chain.points.length] as P), p2], w: rho / (1 - rho) };
|
|
260
|
+
};
|
|
261
|
+
// The blossom of the arc's homogeneous quadratic at (s, t): a weighted point.
|
|
262
|
+
const blossom = (k: number, s: number, t: number): { x: P; weight: number } => {
|
|
263
|
+
const { p, w } = controls(k);
|
|
264
|
+
const b0: number = (1 - s) * (1 - t), b1: number = ((1 - s) * t + s * (1 - t)) * w, b2: number = s * t;
|
|
265
|
+
const weight: number = b0 + b1 + b2;
|
|
266
|
+
return { x: [(b0 * p[0][0] + b1 * p[1][0] + b2 * p[2][0]) / weight, (b0 * p[0][1] + b1 * p[1][1] + b2 * p[2][1]) / weight], weight };
|
|
267
|
+
};
|
|
268
|
+
// The point and the heading of travel on arc `k` at `t`.
|
|
269
|
+
const at = (k: number, t: number): { point: P; heading: number } => {
|
|
270
|
+
const { p, w } = controls(k);
|
|
271
|
+
const point: P = blossom(k, t, t).x;
|
|
272
|
+
// The derivative of the rational curve: (N' D - N D') / D^2, whose direction is that of N' D - N D'.
|
|
273
|
+
const D: number = (1 - t) ** 2 + 2 * t * (1 - t) * w + t * t;
|
|
274
|
+
const dD: number = -2 * (1 - t) + 2 * (1 - 2 * t) * w + 2 * t;
|
|
275
|
+
const N: P = [(1 - t) ** 2 * p[0][0] + 2 * t * (1 - t) * w * p[1][0] + t * t * p[2][0], (1 - t) ** 2 * p[0][1] + 2 * t * (1 - t) * w * p[1][1] + t * t * p[2][1]];
|
|
276
|
+
const dN: P = [-2 * (1 - t) * p[0][0] + 2 * (1 - 2 * t) * w * p[1][0] + 2 * t * p[2][0], -2 * (1 - t) * p[0][1] + 2 * (1 - 2 * t) * w * p[1][1] + 2 * t * p[2][1]];
|
|
277
|
+
const d: P = [dN[0] * D - N[0] * dD, dN[1] * D - N[1] * dD];
|
|
278
|
+
return { point, heading: Math.atan2(d[1], d[0]) };
|
|
279
|
+
};
|
|
280
|
+
// Each target anchor as a base arc and a rational parameter on it (an end of an arc for a base anchor).
|
|
281
|
+
const placed: { arc: number; t: number }[] = [];
|
|
282
|
+
// The frame chord of a run inserted on base arc `k`: the extremes either side of it in the base (`frame` on the base layout).
|
|
283
|
+
const chordOf = (k: number): [P, P] => {
|
|
284
|
+
const extreme = (j: number): boolean => ["u", "v"].includes(base.anchors[(j + K) % K]!.kind);
|
|
285
|
+
let before: number = k;
|
|
286
|
+
while (!extreme(before)) before = (before + K - 1) % K;
|
|
287
|
+
let after: number = (k + 1) % K;
|
|
288
|
+
while (!extreme(after)) after = (after + 1) % K;
|
|
289
|
+
return [chain.points[before] as P, chain.points[after] as P];
|
|
290
|
+
};
|
|
291
|
+
base.anchors.forEach((_: IAnchor, k: number): void => {
|
|
292
|
+
placed.push({ arc: Math.min(k, arcs - 1), t: k < arcs ? 0 : 1 });
|
|
293
|
+
const n: number = runs.filter((r: IFeatureRun): boolean => r.after === k).reduce((sum: number, r: IFeatureRun): number => sum + r.anchors.length, 0);
|
|
294
|
+
if (n === 0) return;
|
|
295
|
+
const [c0, c1]: [P, P] = chordOf(k);
|
|
296
|
+
const d: P = [c1[0] - c0[0], c1[1] - c0[1]];
|
|
297
|
+
const project = (t: number): number => {
|
|
298
|
+
const q: P = blossom(k, t, t).x;
|
|
299
|
+
return ((q[0] - c0[0]) * d[0] + (q[1] - c0[1]) * d[1]) / (d[0] * d[0] + d[1] * d[1] || 1);
|
|
300
|
+
};
|
|
301
|
+
const [s0, s1]: [number, number] = [project(0), project(1)];
|
|
302
|
+
for (let j: number = 1; j <= n; ++j) {
|
|
303
|
+
const target: number = s0 + ((s1 - s0) * j) / (n + 1);
|
|
304
|
+
let lo: number = 0, hi: number = 1;
|
|
305
|
+
for (let i: number = 0; i < 60; ++i) {
|
|
306
|
+
const mid: number = (lo + hi) / 2;
|
|
307
|
+
if ((project(mid) - target) * Math.sign(s1 - s0) < 0) lo = mid;
|
|
308
|
+
else hi = mid;
|
|
309
|
+
}
|
|
310
|
+
placed.push({ arc: k, t: (lo + hi) / 2 });
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
const { at: offset, shoulders }: { at: number[]; shoulders: number } = offsets(target);
|
|
314
|
+
const out: number[] = new Array<number>(units(target).length).fill(0);
|
|
315
|
+
// Points of the target anchors, and each anchor's values.
|
|
316
|
+
const points: P[] = placed.map((q: { arc: number; t: number }): P => at(q.arc, q.t).point);
|
|
317
|
+
let previous: number = 0;
|
|
318
|
+
target.anchors.forEach((anchor: IAnchor, k: number): void => {
|
|
319
|
+
const o: number = offset[k]!;
|
|
320
|
+
if (anchor.kind === "u" || anchor.kind === "v") {
|
|
321
|
+
out[o] = points[k]![0];
|
|
322
|
+
if (anchor.mid !== true) out[o + 1] = points[k]![1];
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (anchor.kind === "m") {
|
|
326
|
+
// A median the conversion keeps: its share on its neighbours' triangle, read as `resolve` places it.
|
|
327
|
+
const [before, after]: [number, number] = [k - 1, k + 1];
|
|
328
|
+
const p0: P = points[before]!, p2: P = points[after]!;
|
|
329
|
+
const corner: P = meet(p0, [Math.cos(at(placed[before]!.arc, placed[before]!.t).heading), Math.sin(at(placed[before]!.arc, placed[before]!.t).heading)], p2, [Math.cos(at(placed[after]!.arc, placed[after]!.t).heading), Math.sin(at(placed[after]!.arc, placed[after]!.t).heading)]);
|
|
330
|
+
const middle: P = [(p0[0] + p2[0]) / 2, (p0[1] + p2[1]) / 2];
|
|
331
|
+
const span: number = Math.hypot(corner[0] - middle[0], corner[1] - middle[1]) || 1;
|
|
332
|
+
out[o] = ((points[k]![0] - middle[0]) * (corner[0] - middle[0]) + (points[k]![1] - middle[1]) * (corner[1] - middle[1])) / span ** 2;
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (anchor.kind !== "f") throw new Error(`convert: anchor kind ${anchor.kind} is not converted`);
|
|
336
|
+
if (k === 0 || target.anchors[k - 1]!.kind !== "f") previous = 0;
|
|
337
|
+
const [before, after]: [number, number] = frame(k, target);
|
|
338
|
+
const read: { values: [number, number, number]; t: number } = unplace(points[before]!, points[after]!, points[k]!, at(placed[k]!.arc, placed[k]!.t).heading, previous);
|
|
339
|
+
out[o] = read.values[0];
|
|
340
|
+
out[o + 1] = read.values[1];
|
|
341
|
+
out[o + 2] = read.values[2];
|
|
342
|
+
previous = read.t;
|
|
343
|
+
});
|
|
344
|
+
// Each target arc is the piece of its base arc between its two ends' parameters.
|
|
345
|
+
const pieces: number = target.mirror ? target.anchors.length - 1 : target.anchors.length;
|
|
346
|
+
for (let j: number = 0; j < pieces; ++j) {
|
|
347
|
+
const a: { arc: number; t: number } = placed[j]!;
|
|
348
|
+
const b: { arc: number; t: number } = placed[(j + 1) % placed.length]!;
|
|
349
|
+
const k: number = a.arc;
|
|
350
|
+
const tb: number = b.arc === k ? b.t : 1;
|
|
351
|
+
const W0: number = blossom(k, a.t, a.t).weight, W1: number = blossom(k, a.t, tb).weight, W2: number = blossom(k, tb, tb).weight;
|
|
352
|
+
const w: number = W1 / Math.sqrt(W0 * W2);
|
|
353
|
+
out[shoulders + j] = w / (1 + w);
|
|
354
|
+
}
|
|
355
|
+
return out;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Unit of every field of a layout, in field order: each anchor's numbers, then one shoulder per arc. */
|
|
359
|
+
export function units(layout: ILayout): Unit[] {
|
|
360
|
+
const out: Unit[] = [];
|
|
361
|
+
for (const anchor of layout.anchors) {
|
|
362
|
+
if (anchor.kind === "m") out.push("share");
|
|
363
|
+
else if (anchor.kind === "i") out.push("share", "angle");
|
|
364
|
+
else if (anchor.kind === "f") out.push("share", "mm", "angle");
|
|
365
|
+
else if (anchor.mid === true) out.push("mm");
|
|
366
|
+
else out.push("mm", "mm");
|
|
367
|
+
}
|
|
368
|
+
const arcs: number = layout.mirror ? layout.anchors.length - 1 : layout.anchors.length;
|
|
369
|
+
for (let k: number = 0; k < arcs; ++k) out.push("share");
|
|
370
|
+
return out;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** Offsets of every anchor's first field, and the offset of the first shoulder. */
|
|
374
|
+
export function offsets(layout: ILayout): { at: number[]; shoulders: number } {
|
|
375
|
+
const at: number[] = [];
|
|
376
|
+
let cursor: number = 0;
|
|
377
|
+
for (const anchor of layout.anchors) {
|
|
378
|
+
at.push(cursor);
|
|
379
|
+
cursor += anchor.kind === "m" || anchor.mid === true ? 1 : anchor.kind === "f" ? 3 : 2;
|
|
380
|
+
}
|
|
381
|
+
return { at, shoulders: cursor };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Dependent anchors (`m`, `i`) by increasing level, the order they are resolved in. */
|
|
385
|
+
export function dependents(layout: ILayout): number[] {
|
|
386
|
+
return layout.anchors
|
|
387
|
+
.map((_: IAnchor, k: number): number => k)
|
|
388
|
+
.filter((k: number): boolean => layout.anchors[k]!.kind === "m" || layout.anchors[k]!.kind === "i")
|
|
389
|
+
.sort((a: number, b: number): number => (layout.anchors[a]!.level ?? 1) - (layout.anchors[b]!.level ?? 1));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* The two extremes a feature anchor `k` stands between: the nearest `u` or `v` anchor before it and the nearest after it, in the
|
|
394
|
+
* layout's order (round the end of the list for a closed layout). Every feature of a run shares this frame and its chord.
|
|
395
|
+
*/
|
|
396
|
+
export function frame(k: number, layout: ILayout): [number, number] {
|
|
397
|
+
const K: number = layout.anchors.length;
|
|
398
|
+
const extreme = (j: number): boolean => ["u", "v"].includes(layout.anchors[j]!.kind);
|
|
399
|
+
let before: number = (k + K - 1) % K;
|
|
400
|
+
while (!extreme(before)) before = (before + K - 1) % K;
|
|
401
|
+
let after: number = (k + 1) % K;
|
|
402
|
+
while (!extreme(after)) after = (after + 1) % K;
|
|
403
|
+
return [before, after];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Where along its frame's chord a feature anchor stands: the feature before it in the run at `previous` (0 at the run's first), its
|
|
408
|
+
* own share `share` of what is left of the chord after that. Each feature then stands past the one before it by construction.
|
|
409
|
+
*/
|
|
410
|
+
export function along(previous: number, share: number): number {
|
|
411
|
+
return previous + (1 - previous) * clamp(share);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* A feature point on the chord from `p0` to `p2`: at `t` of the way along it, the offset `o` square to it, millimetres outward (to the
|
|
416
|
+
* right of travel, which is outward on a counter-clockwise section), and its tangent the chord's direction turned by `h` radians.
|
|
417
|
+
*/
|
|
418
|
+
export function place(p0: P, p2: P, t: number, o: number, h: number): { point: P; tangent: P } {
|
|
419
|
+
const d: P = [p2[0] - p0[0], p2[1] - p0[1]];
|
|
420
|
+
const length: number = Math.hypot(d[0], d[1]) || 1;
|
|
421
|
+
const angle: number = Math.atan2(d[1], d[0]) + h;
|
|
422
|
+
return { point: [p0[0] + t * d[0] + (o * d[1]) / length, p0[1] + t * d[1] - (o * d[0]) / length], tangent: [Math.cos(angle), Math.sin(angle)] };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* The numbers `[share, o, h]` of a feature point `p` with the tangent heading `heading` on the chord from `p0` to `p2`, the feature
|
|
427
|
+
* before it in the run at `previous` of the way along (`along`, `place`), and how far along the chord `p` itself stands.
|
|
428
|
+
*/
|
|
429
|
+
export function unplace(p0: P, p2: P, p: P, heading: number, previous: number): { values: [number, number, number]; t: number } {
|
|
430
|
+
const d: P = [p2[0] - p0[0], p2[1] - p0[1]];
|
|
431
|
+
const square: number = d[0] * d[0] + d[1] * d[1] || 1;
|
|
432
|
+
const q: P = [p[0] - p0[0], p[1] - p0[1]];
|
|
433
|
+
const h: number = heading - Math.atan2(d[1], d[0]);
|
|
434
|
+
const t: number = (q[0] * d[0] + q[1] * d[1]) / square;
|
|
435
|
+
return { values: [(t - previous) / Math.max(1e-9, 1 - previous), (q[0] * d[1] - q[1] * d[0]) / Math.sqrt(square), Math.atan2(Math.sin(h), Math.cos(h))], t };
|
|
436
|
+
}
|
|
437
|
+
/** The nearest resolved anchors before and after anchor `k`. */
|
|
438
|
+
export function neighbours(k: number, done: readonly (P | null)[]): [number, number] {
|
|
439
|
+
const K: number = done.length;
|
|
440
|
+
let before: number = (k + K - 1) % K;
|
|
441
|
+
while (done[before] === null) before = (before + K - 1) % K;
|
|
442
|
+
let after: number = (k + 1) % K;
|
|
443
|
+
while (done[after] === null) after = (after + 1) % K;
|
|
444
|
+
return [before, after];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* A stored shoulder as the model reads it: inside `[EDGE, FAIR]`, and at least the layout's `least`. A fit may store a shoulder past those
|
|
449
|
+
* bounds where it changes nothing at the fitted sections; between the knots the field's natural cubic then crosses a bound and the arc
|
|
450
|
+
* holds still there while its neighbours move, which draws a level line across the wall.
|
|
451
|
+
*
|
|
452
|
+
* @param value The stored shoulder.
|
|
453
|
+
* @param layout The layout it belongs to.
|
|
454
|
+
* @param arc The arc's index among the shoulders, which selects its least when the layout lists one per arc.
|
|
455
|
+
*/
|
|
456
|
+
export function shoulder(value: number, layout: ILayout, arc: number = 0): number {
|
|
457
|
+
return Math.min(FAIR, Math.max(leastOf(layout, arc) ?? 0, clamp(value)));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The least shoulder of one arc of a layout (`ILayout.least`): the layout's one number, or that arc's entry of its list; undefined
|
|
462
|
+
* where the layout sets none.
|
|
463
|
+
*
|
|
464
|
+
* @param layout The layout.
|
|
465
|
+
* @param arc The arc's index among the shoulders.
|
|
466
|
+
*/
|
|
467
|
+
export function leastOf(layout: ILayout, arc: number): number | undefined {
|
|
468
|
+
if (layout.least === undefined || typeof layout.least === "number") return layout.least;
|
|
469
|
+
const own: number | undefined = layout.least[arc];
|
|
470
|
+
if (own === undefined) throw new Error(`leastOf: the layout lists ${layout.least.length} least shoulders and has no arc ${arc}`);
|
|
471
|
+
return own;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** Confine a share to the model's bounds. */
|
|
475
|
+
export function clamp(share: number): number {
|
|
476
|
+
return Math.min(1 - EDGE, Math.max(EDGE, share));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Meeting point of two tangent lines; the chord midpoint when they are parallel. */
|
|
480
|
+
export function meet(p0: P, t0: P, p2: P, t2: P): P {
|
|
481
|
+
const den: number = t0[0] * t2[1] - t0[1] * t2[0];
|
|
482
|
+
if (den === 0) return [(p0[0] + p2[0]) / 2, (p0[1] + p2[1]) / 2];
|
|
483
|
+
const a: number = ((p2[0] - p0[0]) * t2[1] - (p2[1] - p0[1]) * t2[0]) / den;
|
|
484
|
+
return [p0[0] + a * t0[0], p0[1] + a * t0[1]];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** Resolve a field vector into its closed chain. */
|
|
488
|
+
export function resolve(values: readonly number[], layout: ILayout): IChain {
|
|
489
|
+
const K: number = layout.anchors.length;
|
|
490
|
+
const points: (P | null)[] = new Array<P | null>(K).fill(null);
|
|
491
|
+
const tangents: (P | null)[] = new Array<P | null>(K).fill(null);
|
|
492
|
+
const { at, shoulders }: { at: number[]; shoulders: number } = offsets(layout);
|
|
493
|
+
|
|
494
|
+
// Extremes first: an extreme's tangent follows the counter-clockwise travel of the chain.
|
|
495
|
+
layout.anchors.forEach((anchor: IAnchor, k: number): void => {
|
|
496
|
+
if (anchor.kind !== "u" && anchor.kind !== "v") return;
|
|
497
|
+
const p: P = anchor.mid === true ? [values[at[k]!]!, 0] : [values[at[k]!]!, values[at[k]! + 1]!];
|
|
498
|
+
points[k] = p;
|
|
499
|
+
tangents[k] = anchor.kind === "u" ? [0, p[0] > 0 ? 1 : -1] : [p[1] > 0 ? -1 : 1, 0];
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// A guide that reaches its box's corner leaves its arc no first leg. Where one point of a section is both its forward
|
|
503
|
+
// and its side extreme (a section standing like a diamond in its chart) the touch offset would do exactly that, so each
|
|
504
|
+
// guide is held inside the share CORNER of the way to the corners its two neighbouring guides set.
|
|
505
|
+
const boxed: number[] = layout.anchors.map((_: IAnchor, k: number): number => k).filter((k: number): boolean => layout.anchors[k]!.guide === true);
|
|
506
|
+
if (!layout.mirror && boxed.length === 4)
|
|
507
|
+
boxed.forEach((k: number, q: number): void => {
|
|
508
|
+
const across: 0 | 1 = q % 2 === 0 ? 1 : 0;
|
|
509
|
+
const a: number = points[boxed[(q + 1) % 4]!]![across];
|
|
510
|
+
const b: number = points[boxed[(q + 3) % 4]!]![across];
|
|
511
|
+
const p: P = points[k]!;
|
|
512
|
+
p[across] = Math.min(CORNER * Math.max(a, b), Math.max(CORNER * Math.min(a, b), p[across]));
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
// Then the feature points in order, each on the chord of its frame (`frame`: the extremes either side of its run), past the feature
|
|
516
|
+
// before it in the run (`along`).
|
|
517
|
+
let previous: number = 0;
|
|
518
|
+
layout.anchors.forEach((anchor: IAnchor, k: number): void => {
|
|
519
|
+
if (anchor.kind !== "f") return;
|
|
520
|
+
if (k === 0 || layout.anchors[k - 1]!.kind !== "f") previous = 0;
|
|
521
|
+
const [before, after]: [number, number] = frame(k, layout);
|
|
522
|
+
previous = along(previous, values[at[k]!]!);
|
|
523
|
+
const placed: { point: P; tangent: P } = place(points[before]!, points[after]!, previous, values[at[k]! + 1]!, values[at[k]! + 2]!);
|
|
524
|
+
points[k] = placed.point;
|
|
525
|
+
tangents[k] = placed.tangent;
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// Then the anchors that stand on their neighbours' triangle or chord, lower levels first.
|
|
529
|
+
for (const k of dependents(layout)) {
|
|
530
|
+
const [before, after]: [number, number] = neighbours(k, points);
|
|
531
|
+
const p0: P = points[before]!;
|
|
532
|
+
const p2: P = points[after]!;
|
|
533
|
+
const share: number = clamp(values[at[k]!]!);
|
|
534
|
+
if (layout.anchors[k]!.kind === "i") {
|
|
535
|
+
const angle: number = Math.atan2(p2[1] - p0[1], p2[0] - p0[0]) + values[at[k]! + 1]!;
|
|
536
|
+
points[k] = [p0[0] + share * (p2[0] - p0[0]), p0[1] + share * (p2[1] - p0[1])];
|
|
537
|
+
tangents[k] = [Math.cos(angle), Math.sin(angle)];
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
const corner: P = meet(p0, tangents[before]!, p2, tangents[after]!);
|
|
541
|
+
const middle: P = [(p0[0] + p2[0]) / 2, (p0[1] + p2[1]) / 2];
|
|
542
|
+
points[k] = [middle[0] + share * (corner[0] - middle[0]), middle[1] + share * (corner[1] - middle[1])];
|
|
543
|
+
tangents[k] = [p2[0] - p0[0], p2[1] - p0[1]];
|
|
544
|
+
}
|
|
545
|
+
const input: AutoMovieViewChain.IInput = { points: [], tangents: [], shoulders: [] };
|
|
546
|
+
const guides: number[] = [];
|
|
547
|
+
const rho = (arc: number): number => shoulder(values[shoulders + arc]!, layout, arc);
|
|
548
|
+
for (let k: number = 0; k < K; ++k) {
|
|
549
|
+
if (layout.anchors[k]!.guide === true) guides.push(input.points.length);
|
|
550
|
+
input.points.push(points[k]!);
|
|
551
|
+
input.tangents.push(tangents[k]!);
|
|
552
|
+
input.shoulders.push(rho(layout.mirror && k === K - 1 ? K - 2 : k));
|
|
553
|
+
}
|
|
554
|
+
if (layout.mirror)
|
|
555
|
+
for (let k: number = K - 2; k >= 1; --k) {
|
|
556
|
+
if (layout.anchors[k]!.kind === "v" && layout.anchors[k]!.guide === true) guides.push(input.points.length);
|
|
557
|
+
input.points.push([points[k]![0], -points[k]![1]]);
|
|
558
|
+
input.tangents.push([-tangents[k]![0], tangents[k]![1]]);
|
|
559
|
+
input.shoulders.push(rho(k - 1));
|
|
560
|
+
}
|
|
561
|
+
return { input, guides };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* The field vector with the shoulders of the two arcs that meet at anchor `k` set so the section's curvature is continuous there, each
|
|
566
|
+
* arc keeping its triangle (its two end points and the meeting of their tangents).
|
|
567
|
+
*
|
|
568
|
+
* Two conics that meet at an anchor share its tangent but not its curvature, and where one arc ends nearly flat and the next starts sharply
|
|
569
|
+
* bent the wall turns within a few millimetres along the anchor's whole station line: f1's trunk over the hips met at its first median with
|
|
570
|
+
* curvatures of 1.2 and 308 per metre and drew an upright line down each hip. For a rational quadratic with end weights 1 and middle
|
|
571
|
+
* weight `w = rho / (1 - rho)` the curvature at an end is `|(P1 - P0) x (P2 - P1)| / (w^2 |leg|^3)`, the leg the side of the triangle at
|
|
572
|
+
* that end (Farin, rational quadratic Bezier curves; Pottmann, curvature continuous conic splines). Both curvatures are brought to their
|
|
573
|
+
* geometric mean, so each arc's weight moves by the same factor; the shoulders stay within the model's bounds, where the joint is as near
|
|
574
|
+
* G2 as they allow. Merged into one conic instead (both halves of one arc split at its shoulder), the hip's shape moved further.
|
|
575
|
+
*
|
|
576
|
+
* @param values The section's field vector.
|
|
577
|
+
* @param layout Its layout, not a mirror's last anchor: `k` must have an arc on either side in the listed anchors.
|
|
578
|
+
* @param k The anchor.
|
|
579
|
+
*/
|
|
580
|
+
export function continuous(values: readonly number[], layout: ILayout, k: number): number[] {
|
|
581
|
+
const chain: AutoMovieViewChain.IInput = resolve(values, layout).input;
|
|
582
|
+
const triangle = (a: number): [P, P, P] => {
|
|
583
|
+
const p0: P = chain.points[a] as P;
|
|
584
|
+
const p2: P = chain.points[a + 1] as P;
|
|
585
|
+
return [p0, meet(p0, chain.tangents[a] as P, p2, chain.tangents[a + 1] as P), p2];
|
|
586
|
+
};
|
|
587
|
+
const turn = ([p0, p1, p2]: [P, P, P], leg: number): number => Math.abs((p1[0] - p0[0]) * (p2[1] - p1[1]) - (p1[1] - p0[1]) * (p2[0] - p1[0])) / leg ** 3;
|
|
588
|
+
const [b0, b1, b2]: [P, P, P] = triangle(k - 1);
|
|
589
|
+
const [a0, a1, a2]: [P, P, P] = triangle(k);
|
|
590
|
+
const before: number = turn([b0, b1, b2], Math.hypot(b2[0] - b1[0], b2[1] - b1[1]));
|
|
591
|
+
const after: number = turn([a0, a1, a2], Math.hypot(a1[0] - a0[0], a1[1] - a0[1]));
|
|
592
|
+
const weight = (rho: number): number => rho / (1 - rho);
|
|
593
|
+
const target: number = Math.sqrt((before / weight(chain.shoulders[k - 1]!) ** 2) * (after / weight(chain.shoulders[k]!) ** 2));
|
|
594
|
+
const shoulder = (factor: number, arc: number): number => {
|
|
595
|
+
const w: number = Math.sqrt(factor / target);
|
|
596
|
+
return Math.min(FAIR, Math.max(leastOf(layout, arc) ?? EDGE, w / (1 + w)));
|
|
597
|
+
};
|
|
598
|
+
const out: number[] = [...values];
|
|
599
|
+
const { shoulders }: { shoulders: number } = offsets(layout);
|
|
600
|
+
out[shoulders + k - 1] = shoulder(before, k - 1);
|
|
601
|
+
out[shoulders + k] = shoulder(after, k);
|
|
602
|
+
return out;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** Build the engine's native conic chain from a field vector. */
|
|
606
|
+
export function chain(values: readonly number[], layout: ILayout): AutoMovieViewChain.ISection {
|
|
607
|
+
return AutoMovieViewChain.of(resolve(values, layout).input);
|
|
608
|
+
}
|
|
609
|
+
}
|