figureone 0.15.10 → 1.0.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 (159) hide show
  1. package/figureone.min.js +1 -1
  2. package/index.js +79167 -0
  3. package/package.json +15 -1
  4. package/types/index.d.ts +132 -0
  5. package/types/js/figure/Animation/Animation.d.ts +36 -0
  6. package/types/js/figure/Animation/AnimationBuilder.d.ts +173 -0
  7. package/types/js/figure/Animation/AnimationManager.d.ts +392 -0
  8. package/types/js/figure/Animation/AnimationStep/CustomStep.d.ts +99 -0
  9. package/types/js/figure/Animation/AnimationStep/DelayStep.d.ts +24 -0
  10. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ColorAnimationStep.d.ts +203 -0
  11. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/OpacityAnimationStep.d.ts +220 -0
  12. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PositionAnimationStep.d.ts +124 -0
  13. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseAnimationStep.d.ts +137 -0
  14. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseTransformAnimationStep.d.ts +52 -0
  15. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/RotationAnimationStep.d.ts +119 -0
  16. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScaleAnimationStep.d.ts +93 -0
  17. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScenarioAnimationStep.d.ts +204 -0
  18. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/TransformAnimationStep.d.ts +163 -0
  19. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep.d.ts +56 -0
  20. package/types/js/figure/Animation/AnimationStep/ParallelAnimationStep.d.ts +70 -0
  21. package/types/js/figure/Animation/AnimationStep/SerialAnimationStep.d.ts +84 -0
  22. package/types/js/figure/Animation/AnimationStep/TriggerStep.d.ts +106 -0
  23. package/types/js/figure/Animation/AnimationStep.d.ts +110 -0
  24. package/types/js/figure/DrawContext2D.d.ts +9 -0
  25. package/types/js/figure/DrawingObjects/DrawingObject.d.ts +45 -0
  26. package/types/js/figure/DrawingObjects/GLObject/GLObject.d.ts +146 -0
  27. package/types/js/figure/DrawingObjects/HTMLObject/HTMLObject.d.ts +29 -0
  28. package/types/js/figure/DrawingObjects/TextObject/TextObject.d.ts +94 -0
  29. package/types/js/figure/DrawingObjects/TextObject/glyphMeasures.d.ts +7 -0
  30. package/types/js/figure/DrawingObjects/VertexObject/VertexGeneric.d.ts +21 -0
  31. package/types/js/figure/DrawingObjects/VertexObject/VertexObject.d.ts +0 -0
  32. package/types/js/figure/DrawingObjects/VertexObject/VertexText.d.ts +34 -0
  33. package/types/js/figure/Element.d.ts +1212 -0
  34. package/types/js/figure/Equation/Elements/BaseAnnotationFunction.d.ts +118 -0
  35. package/types/js/figure/Equation/Elements/BaseEquationFunction.d.ts +20 -0
  36. package/types/js/figure/Equation/Elements/Bounds.d.ts +49 -0
  37. package/types/js/figure/Equation/Elements/Color.d.ts +7 -0
  38. package/types/js/figure/Equation/Elements/Container.d.ts +5 -0
  39. package/types/js/figure/Equation/Elements/Element.d.ts +95 -0
  40. package/types/js/figure/Equation/Elements/Fraction.d.ts +5 -0
  41. package/types/js/figure/Equation/Elements/Lines.d.ts +5 -0
  42. package/types/js/figure/Equation/Elements/Matrix.d.ts +5 -0
  43. package/types/js/figure/Equation/Elements/Offset.d.ts +5 -0
  44. package/types/js/figure/Equation/Elements/Scale.d.ts +5 -0
  45. package/types/js/figure/Equation/Equation.d.ts +984 -0
  46. package/types/js/figure/Equation/EquationForm.d.ts +139 -0
  47. package/types/js/figure/Equation/EquationFunctions.d.ts +3367 -0
  48. package/types/js/figure/Equation/EquationSymbols.d.ts +1646 -0
  49. package/types/js/figure/Equation/HTMLEquation.d.ts +56 -0
  50. package/types/js/figure/Equation/Symbols/AngleBracket.d.ts +6 -0
  51. package/types/js/figure/Equation/Symbols/Arrow.d.ts +17 -0
  52. package/types/js/figure/Equation/Symbols/Bar.d.ts +6 -0
  53. package/types/js/figure/Equation/Symbols/Box.d.ts +11 -0
  54. package/types/js/figure/Equation/Symbols/Brace.d.ts +6 -0
  55. package/types/js/figure/Equation/Symbols/Bracket.d.ts +8 -0
  56. package/types/js/figure/Equation/Symbols/Division.d.ts +8 -0
  57. package/types/js/figure/Equation/Symbols/Integral.d.ts +7 -0
  58. package/types/js/figure/Equation/Symbols/Line.d.ts +5 -0
  59. package/types/js/figure/Equation/Symbols/Product.d.ts +6 -0
  60. package/types/js/figure/Equation/Symbols/Radical.d.ts +9 -0
  61. package/types/js/figure/Equation/Symbols/SquareBracket.d.ts +6 -0
  62. package/types/js/figure/Equation/Symbols/Strike.d.ts +8 -0
  63. package/types/js/figure/Equation/Symbols/Sum.d.ts +6 -0
  64. package/types/js/figure/Equation/Symbols/SymbolNew.d.ts +15 -0
  65. package/types/js/figure/Equation/Symbols/Vinculum.d.ts +6 -0
  66. package/types/js/figure/Figure.d.ts +711 -0
  67. package/types/js/figure/FigureCollections/Angle.d.ts +766 -0
  68. package/types/js/figure/FigureCollections/Axis.d.ts +517 -0
  69. package/types/js/figure/FigureCollections/Axis3.d.ts +118 -0
  70. package/types/js/figure/FigureCollections/Button.d.ts +195 -0
  71. package/types/js/figure/FigureCollections/EquationLabel.d.ts +77 -0
  72. package/types/js/figure/FigureCollections/FigureCollections.d.ts +122 -0
  73. package/types/js/figure/FigureCollections/Legend.d.ts +270 -0
  74. package/types/js/figure/FigureCollections/Line.d.ts +587 -0
  75. package/types/js/figure/FigureCollections/Plot.d.ts +558 -0
  76. package/types/js/figure/FigureCollections/PolyLine.d.ts +487 -0
  77. package/types/js/figure/FigureCollections/Rectangle.d.ts +235 -0
  78. package/types/js/figure/FigureCollections/SlideNavigator.d.ts +255 -0
  79. package/types/js/figure/FigureCollections/Slider.d.ts +155 -0
  80. package/types/js/figure/FigureCollections/Text.d.ts +307 -0
  81. package/types/js/figure/FigureCollections/Toggle.d.ts +185 -0
  82. package/types/js/figure/FigureCollections/Trace.d.ts +237 -0
  83. package/types/js/figure/FigurePrimitives/FigureElementPrimitive2DText.d.ts +119 -0
  84. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGLText.d.ts +94 -0
  85. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGesture.d.ts +536 -0
  86. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveMorph.d.ts +175 -0
  87. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes.d.ts +788 -0
  88. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes2D.d.ts +1324 -0
  89. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes3D.d.ts +1105 -0
  90. package/types/js/figure/FigurePrimitives/FigurePrimitives.d.ts +173 -0
  91. package/types/js/figure/FigurePrimitives/Generic.d.ts +5 -0
  92. package/types/js/figure/FigurePrimitives/Text.d.ts +17 -0
  93. package/types/js/figure/FontManager.d.ts +113 -0
  94. package/types/js/figure/Gesture.d.ts +39 -0
  95. package/types/js/figure/Recorder/Recorder.d.ts +291 -0
  96. package/types/js/figure/Recorder/parseState.d.ts +3 -0
  97. package/types/js/figure/Recorder/recorder.worker.d.ts +1 -0
  98. package/types/js/figure/Recorder/state.d.ts +7 -0
  99. package/types/js/figure/SlideNavigator.d.ts +606 -0
  100. package/types/js/figure/TimeKeeper.d.ts +174 -0
  101. package/types/js/figure/geometries/arc.d.ts +18 -0
  102. package/types/js/figure/geometries/arrow.d.ts +215 -0
  103. package/types/js/figure/geometries/buffer.d.ts +4 -0
  104. package/types/js/figure/geometries/copy/copy.d.ts +178 -0
  105. package/types/js/figure/geometries/ellipse.d.ts +17 -0
  106. package/types/js/figure/geometries/line.d.ts +13 -0
  107. package/types/js/figure/geometries/lines/corners.d.ts +7 -0
  108. package/types/js/figure/geometries/lines/dashes.d.ts +23 -0
  109. package/types/js/figure/geometries/lines/lines.d.ts +31 -0
  110. package/types/js/figure/geometries/polygon/polygon.d.ts +12 -0
  111. package/types/js/figure/geometries/rectangle.d.ts +19 -0
  112. package/types/js/figure/geometries/triangle.d.ts +27 -0
  113. package/types/js/figure/webgl/Atlas.d.ts +42 -0
  114. package/types/js/figure/webgl/shaders.d.ts +143 -0
  115. package/types/js/figure/webgl/target.d.ts +9 -0
  116. package/types/js/figure/webgl/webgl.d.ts +54 -0
  117. package/types/js/tools/FunctionMap.d.ts +69 -0
  118. package/types/js/tools/color.d.ts +11 -0
  119. package/types/js/tools/colorNames.d.ts +2 -0
  120. package/types/js/tools/d2/polygon.d.ts +60 -0
  121. package/types/js/tools/d2/triangles.d.ts +0 -0
  122. package/types/js/tools/d3/cone.d.ts +57 -0
  123. package/types/js/tools/d3/cube.d.ts +26 -0
  124. package/types/js/tools/d3/cylinder.d.ts +45 -0
  125. package/types/js/tools/d3/line3.d.ts +55 -0
  126. package/types/js/tools/d3/prism.d.ts +49 -0
  127. package/types/js/tools/d3/revolve.d.ts +87 -0
  128. package/types/js/tools/d3/sphere.d.ts +33 -0
  129. package/types/js/tools/d3/surface.d.ts +47 -0
  130. package/types/js/tools/g2.d.ts +242 -0
  131. package/types/js/tools/geometry/Bounds.d.ts +446 -0
  132. package/types/js/tools/geometry/Line.d.ts +314 -0
  133. package/types/js/tools/geometry/Path.d.ts +67 -0
  134. package/types/js/tools/geometry/Plane.d.ts +201 -0
  135. package/types/js/tools/geometry/Point.d.ts +359 -0
  136. package/types/js/tools/geometry/Rect.d.ts +115 -0
  137. package/types/js/tools/geometry/Transform.d.ts +623 -0
  138. package/types/js/tools/geometry/angle.d.ts +105 -0
  139. package/types/js/tools/geometry/common.d.ts +9 -0
  140. package/types/js/tools/geometry/coordinates.d.ts +30 -0
  141. package/types/js/tools/geometry/deceleration.d.ts +13 -0
  142. package/types/js/tools/geometry/polygon.d.ts +4 -0
  143. package/types/js/tools/geometry/quaternion.d.ts +15 -0
  144. package/types/js/tools/geometry/scene.d.ts +282 -0
  145. package/types/js/tools/geometry/tools.d.ts +8 -0
  146. package/types/js/tools/geometry/types.d.ts +2 -0
  147. package/types/js/tools/getCssColors.d.ts +1 -0
  148. package/types/js/tools/getCssVariables.d.ts +4 -0
  149. package/types/js/tools/getImageData.d.ts +1 -0
  150. package/types/js/tools/getScssColors.d.ts +2 -0
  151. package/types/js/tools/htmlGenerator.d.ts +85 -0
  152. package/types/js/tools/m2.d.ts +24 -0
  153. package/types/js/tools/m3.d.ts +71 -0
  154. package/types/js/tools/math.d.ts +112 -0
  155. package/types/js/tools/morph.d.ts +651 -0
  156. package/types/js/tools/styleSheets.d.ts +3 -0
  157. package/types/js/tools/tools.d.ts +281 -0
  158. package/types/js/tools/types.d.ts +305 -0
  159. package/figureone.worker.js +0 -1
@@ -0,0 +1,174 @@
1
+ /**
2
+ * `'nextFrame'` | `'prevFrame'` | `'syncNow'` | `'now'`
3
+ *
4
+ *
5
+ * `'syncNow'` is a synchronized 'now' time. The
6
+ * first time 'syncNow' is used, the current time will be stored and used
7
+ * for all subsequent calls to 'syncNow'. 'syncNow' is reset every
8
+ * time a new animation frame is drawn, or 100ms after a first syncNow call
9
+ * has been made after a reset.
10
+ *
11
+ * 'now' is the instantaneous time
12
+ *
13
+ * `'nextFrame'` will be the time of the next animation frame
14
+ *
15
+ * `'prevFrame'` is the time of the last animation frame
16
+ * @typedef {'now' | 'nextFrame' | 'prevFrame' | 'syncNow'} TypeWhen
17
+ * @group Misc Animation
18
+ */
19
+ export type TypeWhen = 'now' | 'nextFrame' | 'prevFrame' | 'syncNow';
20
+ /**
21
+ * TimeKeeper keeps time for a figure, where time is the number of
22
+ * milliseconds after the page is loaded.
23
+ *
24
+ * Time can be real time, sped up, slowed down or manually stepped.
25
+ *
26
+ * The current time can be accessed using the `now` method.
27
+ *
28
+ * In it's default form, `now` is the same as the system time
29
+ * `performance.now()` or the animation time sent through on frames requested
30
+ * from `requestAnimationFrame` .
31
+ *
32
+ * However, these system times diverge from `now` when TimeKeeper's time
33
+ * speed is changed, or manual time deltas are enabled.
34
+ *
35
+ * When time speed is n times faster than real time, `now` will report n times
36
+ * more passage of time from the page load than real time. So if the speed is
37
+ * set to 2, then `now` will report time passing twice as fast.
38
+ *
39
+ * If timeouts are needed in a figure's logic, use `figure.timeKeeper.
40
+ * setTimeout` and `figure.timeKeeper.clearTimeout` methods instead of the
41
+ * system equivalents so the timeouts follow figure time.
42
+ *
43
+ * TimeKeeper can also be used to synchronize times (for example, for multiple
44
+ * animations being started where it is desired they all have precisely the
45
+ * same start time). See `getWhen` method for information on how to retrieve a
46
+ * synchronized time
47
+ * @group Misc Figure Element
48
+ */
49
+ declare class TimeKeeper {
50
+ requestNextAnimationFrame: (callback: FrameRequestCallback) => number;
51
+ animationId: number | null;
52
+ static instance: TimeKeeper;
53
+ drawQueue: Array<(time: number) => void>;
54
+ nextDrawQueue: Array<(time: number) => void>;
55
+ lastDrawTime: number | null;
56
+ nowTime: number;
57
+ timeoutId: ReturnType<typeof setTimeout> | null;
58
+ speed: number;
59
+ synchronizedNow: number;
60
+ updateSyncNow: boolean;
61
+ syncNowTimer: number;
62
+ manual: boolean;
63
+ animateOnFrame: boolean;
64
+ lastTime: number;
65
+ idCounter: number;
66
+ syncNowTimeout: number;
67
+ timers: {
68
+ [id: string]: {
69
+ id: ReturnType<typeof setTimeout> | null;
70
+ callback: () => void;
71
+ timeout: number;
72
+ description: string;
73
+ stateTimer: boolean;
74
+ };
75
+ };
76
+ constructor();
77
+ /**
78
+ * Reset TimeKeeper to 0 time.
79
+ *
80
+ * All ongoing timers will be cancelled, and all properties reset.
81
+ */
82
+ reset(): void;
83
+ clearTimeouts(): void;
84
+ /**
85
+ * Current relative time now, of most recent animation frame or of most
86
+ * recent synchronized time.
87
+ *
88
+ */
89
+ getWhen(when: TypeWhen): number | null;
90
+ /**
91
+ * Get synchronized relative now time.
92
+ *
93
+ * Each call of `now` when not using manual frames will result in a
94
+ * progressed time value in ms from the page load.
95
+ *
96
+ * This can be a challenge if you want to start two animations at precisely
97
+ * the same time.
98
+ *
99
+ * When syncNow is first called, the actual now time is returned. Each
100
+ * subsequent call of syncNow will return the same number. syncNow is reset
101
+ * on each animation frame, or after `TimeKeeper.syncNowTimeout` is ellapsed
102
+ * (defaults to 100ms).
103
+ */
104
+ syncNow(): number;
105
+ updateNow(): void;
106
+ /**
107
+ * Current relative time.
108
+ *
109
+ * If speed is 1 and manual frames have not been used, then this will return
110
+ * the time in ms after the page is loaded.
111
+ *
112
+ * If speed is not 1, or manual frames have been or are being used, then this
113
+ * will return the relative time in ms taking into account pauses and frame
114
+ * steps from any manual frames, and any speed changes.
115
+ *
116
+ * @param {number} time in ms from page load
117
+ */
118
+ now(): number;
119
+ /**
120
+ * Set the speed of time. 1 is normal timer, >1 is faster than normal time
121
+ * and <1 is slower than normal time. The speed must be greater than 0.
122
+ *
123
+ * @param {number} speedFactor
124
+ */
125
+ setSpeed(speedFactor?: number): void;
126
+ /**
127
+ * Set manual frames.
128
+ * When set, all animation frames can only be initiated with `frame`.
129
+ */
130
+ setManualFrames(): void;
131
+ /**
132
+ * End manual frames.
133
+ * When ended, animation frames will again be triggered by
134
+ * requestAnimationFrame from the browser.
135
+ */
136
+ endManualFrames(): void;
137
+ /**
138
+ * Step manual frames by a delta time in seconds.
139
+ * @param {number} timeStepInSeconds
140
+ */
141
+ frame(timeStepInSeconds: number): void;
142
+ incrementTimers(targetTime: number): number;
143
+ /**
144
+ * Use like normal setTimeout in javascript.
145
+ *
146
+ * @param {function(): void} callback function to be called after some time
147
+ * @param {number} time in ms
148
+ * @param {string} description timer description useful for debugging but not
149
+ * requied ('')
150
+ * @param {boolean} stateTime internal use only
151
+ *
152
+ * @return {number} unique identifier that can be used to clear timer with
153
+ * `clearTimeout`
154
+ */
155
+ setTimeout(callback: () => void, time: number, description?: string, stateTimer?: boolean): number;
156
+ /**
157
+ * Clear a current timer (the callback will not be called).
158
+ *
159
+ * @param {number | null} id timer identifier return from `setTimeout`. If
160
+ * null, no action occurs.
161
+ */
162
+ clearTimeout(id: number | null): void;
163
+ draw(): void;
164
+ /**
165
+ * Queue function to be called the next time an animation frame is triggered
166
+ *
167
+ * @param {function(number): void} func function that will be passed the
168
+ * current time as an input parameter when it is called
169
+ */
170
+ queueNextFrame(func: (time: number | null) => void): void;
171
+ animateNextFrame(): void;
172
+ _dup(): this;
173
+ }
174
+ export default TimeKeeper;
@@ -0,0 +1,18 @@
1
+ import { Point } from '../../tools/g2';
2
+ import type { OBJ_Generic } from '../FigurePrimitives/FigurePrimitiveTypes2D';
3
+ export type OBJ_Arc_Defined = {
4
+ radius: number;
5
+ sides: number;
6
+ startAngle: number;
7
+ angle: number;
8
+ line?: {
9
+ widthIs: 'inside' | 'outside' | 'positive' | 'negative' | 'mid';
10
+ width: number;
11
+ };
12
+ offset: Point;
13
+ fillCenter: boolean;
14
+ drawBorderBuffer: number | Array<Array<Point>>;
15
+ } & OBJ_Generic;
16
+ declare function getArcBorder(options: OBJ_Arc_Defined): Array<Point>;
17
+ declare function arcBorderToTris(border: Array<Point>): Point[];
18
+ export { getArcBorder, arcBorderToTris, };
@@ -0,0 +1,215 @@
1
+ import { Point } from '../../tools/g2';
2
+ import type { OBJ_Arrow } from '../FigurePrimitives/FigurePrimitiveTypes2D';
3
+ /**
4
+ * Arrow heads
5
+ *
6
+ * `'triangle' | 'circle' | 'line' | 'barb' | 'bar' | 'polygon' | 'rectangle'`
7
+ *
8
+ * @see {@link OBJ_Arrow} for properties related to each arrow head
9
+ */
10
+ export type TypeArrowHead = 'triangle' | 'circle' | 'line' | 'barb' | 'bar' | 'polygon' | 'reverseTriangle' | 'rectangle';
11
+ /**
12
+ * Arrow end for a line or polyline.
13
+ *
14
+ * ![](./apiassets/arrow_line.png)
15
+ *
16
+ * Arrows on the end of lines have many of the same properties as stand
17
+ * alone arrows {@link OBJ_Arrow}.
18
+ *
19
+ * The `align` property descripes where the line stops relative to the arrow.
20
+ * `'start'` will be most useful for pointed arrows. When there is no tail, or
21
+ * a zero length tail, `'mid'` can be useful with '`polygon`', '`circle`' and
22
+ * '`bar`' as then the shapes will be centered on the end of the line. Note
23
+ * that in this case the shape will extend past the line.
24
+ *
25
+ * @property {TypeArrowHead} [head] head style (`'triangle'`)
26
+ * @property {number} [scale] scale the default dimensions of the arrow
27
+ * @property {number} [length] dimension of the arrow head along the line
28
+ * @property {number} [width] dimension of the arrow head along the line width
29
+ * @property {number} [rotation] rotation of the polygon when `head = 'polygon'`
30
+ * @property {number} [sides] number of sides in polygon or circle arrow head
31
+ * @property {number} [radius] radius of polygon or circle arrow head
32
+ * @property {number} [barb] barb length (along the length of the line) of the
33
+ * barb arrow head
34
+ * @property {boolean | number} [tail] `true` includes a tail in the arrow of
35
+ * with `tailWidth`. A `number` gives the tail a length where 0 will not
36
+ * extend the tail beyond the boundaries of the head
37
+ * @property {'start' | 'mid'} [align] define which part of
38
+ * the arrow is aligned at (0, 0) in draw space (`'start'`)
39
+ *
40
+ * @interface
41
+ * @group Misc Shapes
42
+ * @example
43
+ * // Line with triangle arrows on both ends
44
+ * figure.add({
45
+ * name: 'a',
46
+ * make: 'polyline',
47
+ * points: [[0, 0], [1, 0]],
48
+ * width: 0.02,
49
+ * arrow: 'triangle',
50
+ * });
51
+ *
52
+ * @example
53
+ * // Line with customized barb arrow at end only
54
+ * figure.add({
55
+ * name: 'a',
56
+ * make: 'shapes.line',
57
+ * p1: [0, 0],
58
+ * p2: [0, 1],
59
+ * width: 0.02,
60
+ * arrow: {
61
+ * end: {
62
+ * head: 'barb',
63
+ * width: 0.15,
64
+ * length: 0.25,
65
+ * barb: 0.05,
66
+ * scale: 2
67
+ * },
68
+ * },
69
+ * dash: [0.02, 0.02],
70
+ * });
71
+ *
72
+ * @example
73
+ * // Three lines showing the difference between mid align and start align for
74
+ * // circle heads
75
+ * figure.add([
76
+ * {
77
+ * name: 'reference',
78
+ * make: 'polyline',
79
+ * points: [[0, 0.3], [0.5, 0.3]],
80
+ * },
81
+ * {
82
+ * name: 'start',
83
+ * make: 'polyline',
84
+ * points: [[0, 0], [0.5, 0]],
85
+ * arrow: {
86
+ * head: 'circle',
87
+ * radius: 0.1,
88
+ * },
89
+ * },
90
+ * {
91
+ * name: 'mid',
92
+ * make: 'polyline',
93
+ * points: [[0, -0.3], [0.5, -0.3]],
94
+ * arrow: {
95
+ * head: 'circle',
96
+ * radius: 0.1,
97
+ * align: 'mid', // circle mid point is at line end
98
+ * },
99
+ * },
100
+ * ]);
101
+ */
102
+ export type OBJ_LineArrow = {
103
+ head?: TypeArrowHead;
104
+ scale?: number;
105
+ length?: number;
106
+ width?: number;
107
+ rotation?: number;
108
+ sides?: number;
109
+ radius?: number;
110
+ barb?: number;
111
+ tail?: boolean;
112
+ align?: 'start' | 'mid';
113
+ };
114
+ /**
115
+ * Line end's arrow definition options object.
116
+ *
117
+ * `start` and `end` define the properties of the arrows at the start and
118
+ * end of the line. Instead of defining {@link OBJ_LineArrow} objects for the
119
+ * start and end, a string that is the arrow's `head` property can also be
120
+ * used and the size dimensions will be the default.
121
+ *
122
+ * All other properties will be used as the default for the `start` and
123
+ * `end` objects.
124
+ *
125
+ * If any of the default properties are defined, then the line will have
126
+ * both a start and end arrow.
127
+ *
128
+ * If only one end of the line is to have an arrow, then define only the
129
+ * `start` or `end` properties and no others.
130
+ *
131
+ * @property {OBJ_LineArrow | TypeArrowHead} [start] arrow at start of line
132
+ * @property {OBJ_LineArrow | TypeArrowHead} [end] arrow at end of line
133
+ * @property {TypeArrowHead} [head] default head to use for start and end arrow
134
+ * @property {number} [scale] default scale to use for start and end arrow
135
+ * @property {number} [length] default length to use for start and end arrow
136
+ * @property {number} [width] default width to use for start and end arrow
137
+ * @property {number} [rotation] default rotation to use for start and end arrow
138
+ * @property {number} [sides] default sides to use for start and end arrow
139
+ * @property {number} [radius] default radius to use for start and end arrow
140
+ * @property {number} [barb] default barb to use for start and end arrow
141
+ * @property {number} [tailWidth] width of the line that joins the arrow - if
142
+ * defined this will create minimum dimensions for the arrow
143
+ * @property {boolean | number} [tail] `true` includes a tail in the arrow of
144
+ * with `tailWidth`. A `number` gives the tail a length where 0 will not
145
+ * extend the tail beyond the boundaries of the head
146
+ * @property {'start' | 'mid'} [align] define which part of
147
+ * the arrow is aligned at (0, 0) in draw space (`'start'`)
148
+ * @interface
149
+ * @group Misc Shapes
150
+ */
151
+ export type OBJ_LineArrows = {
152
+ start: OBJ_LineArrow | TypeArrowHead;
153
+ end: OBJ_LineArrow | TypeArrowHead;
154
+ head?: TypeArrowHead;
155
+ scale?: number;
156
+ length?: number;
157
+ width?: number;
158
+ rotation?: number;
159
+ sides?: number;
160
+ radius?: number;
161
+ barb?: number;
162
+ tailWidth?: number;
163
+ tail?: boolean | number;
164
+ align?: 'start' | 'mid';
165
+ };
166
+ declare function getTriangleArrow(options: {
167
+ length: number;
168
+ width: number;
169
+ tailWidth: number;
170
+ drawBorderBuffer: number;
171
+ tail: boolean | number;
172
+ lineWidth: number;
173
+ }): Point[][];
174
+ declare function getBarbArrow(options: {
175
+ length: number;
176
+ width: number;
177
+ barb: number;
178
+ drawBorderBuffer: number;
179
+ tailWidth: number;
180
+ tail: boolean | number;
181
+ }): Point[][];
182
+ declare function getArrowLength(options: {
183
+ head: TypeArrowHead;
184
+ length: number;
185
+ tailWidth: number;
186
+ width: number;
187
+ radius: number;
188
+ align: 'mid' | 'start';
189
+ tail: number | boolean;
190
+ barb: number;
191
+ }): number[];
192
+ declare function getArrow(options: {
193
+ head: TypeArrowHead;
194
+ length: number;
195
+ width: number;
196
+ barb: number;
197
+ start: Point;
198
+ end: Point;
199
+ drawBorderBuffer: number;
200
+ tailWidth: number;
201
+ radius: number;
202
+ rotation: number;
203
+ sides: number;
204
+ reverse: boolean;
205
+ tail: number | boolean;
206
+ }): [Point[], Point[][], Point[]];
207
+ declare function getArrowTris(border: Array<Point>, options: {
208
+ head: TypeArrowHead;
209
+ }): Point[];
210
+ declare function defaultArrowOptions(o: Record<string, any>): any;
211
+ declare function simplifyArrowOptions(arrowIn: null | TypeArrowHead | {
212
+ start: OBJ_Arrow | TypeArrowHead;
213
+ end: OBJ_Arrow | TypeArrowHead;
214
+ } & OBJ_Arrow, tailWidth: number | null, includeTailByDefault?: boolean): Record<string, any> | undefined;
215
+ export { getTriangleArrow, getBarbArrow, getArrow, getArrowLength, simplifyArrowOptions, defaultArrowOptions, getArrowTris, };
@@ -0,0 +1,4 @@
1
+ import { Point } from '../../tools/g2';
2
+ declare function getBufferBorder(bordersIn: Array<Array<Point>>, buffer: number, skipConcave?: boolean, bufferOffset?: 'positive' | 'negative'): Point[][];
3
+ export { // eslint-disable-next-line import/prefer-default-export
4
+ getBufferBorder, };
@@ -0,0 +1,178 @@
1
+ import { Point } from '../../../tools/g2';
2
+ import type { TypeParsablePoint, TypeParsableTransform } from '../../../tools/g2';
3
+ /**
4
+ *
5
+ * ![](./apiassets/copy.png)
6
+ *
7
+ * Copy Step options object
8
+ *
9
+ * A copy step defines how to copy existing points.
10
+ *
11
+ * An array of copy steps will cumulatively copy points from an original set of
12
+ * points.
13
+ *
14
+ * So, if there are two copy steps then:
15
+ * - the first step will copy the original points
16
+ * - the second step will copy the original points and the first copy of the
17
+ * points
18
+ *
19
+ * For example, a grid of a shape can be made with two copy steps. The first
20
+ * replicates the shape along the x axis, creating a line of shapes. The second
21
+ * copy step then replicates the line of shapes in the y axis, creating a grid
22
+ * of shapes.
23
+ *
24
+ * Each copy step appends its copied points onto an array of points that
25
+ * started with the original points. By default, copy steps operate on all
26
+ * points created in previous steps. However, the properties `start` and `end`
27
+ * can be used to make the current step only operate on a subset of the points.
28
+ *
29
+ * `start` and `end` refer to the indexes of the copy steps where the original
30
+ * points is at index 0, and the first copy step is at index 1. Copy step
31
+ * arrays can also include *marker strings* which make defining `start` and
32
+ * `end` more convient (see the third example below). These marker strings
33
+ * can be used as `start` and `end` values. Marker strings are included
34
+ * in the copy step indexing.
35
+ *
36
+ * There are two main ways to make a copy, either copy the points `to` a
37
+ * location, or copy the points `along` a path.
38
+ *
39
+ * When using the `to` property, if a {@link Point} is defined
40
+ * then the points will be copied to that point. If a {@link Transform} is
41
+ * defined, then a copy of the points will be transformed by that transform. An
42
+ * array of points and transforms can be defined to make multiple copies of the
43
+ * points.
44
+ *
45
+ * When using the `along` property, the points are copied a number (`num`) of
46
+ * times along a path with some `step`. The paths can be horiztonal (`'x'`),
47
+ * vertical (`'y'`), along the z axis (`'z'`), at an angle in the xy plane,
48
+ * (`number`), along a direction vector (`TypeParsablePoint`) or through a
49
+ * `'rotation'` around a `center` point and `axis`.
50
+ *
51
+ * When copying along a line (`along` is `'x'`, `y'`, `'z'`,
52
+ * `TypeParsablePoint` or a `number`), then `step` will be the distance offset
53
+ * along the line.
54
+ *
55
+ * When copying along a rotation (`along` is `'rotation'`), then `step` will be
56
+ * the angular step in radians.
57
+ *
58
+ * Any step can use the `original` property - but it will only operate on the
59
+ * last step that uses it. When `original` is `false`, then all points before
60
+ * that copy step will not be included in the returned Point array.
61
+ *
62
+ * @property {TypeParsablePoint | TypeParsableTransform | Array<TypeParsablePoint | TypeParsableTransform>} [to] copy points to
63
+ * a location or locations or transform a copy of the points
64
+ * @property {'x' | 'y' | number | 'rotation' | 'moveOnly' | TypeParsablePoint} [along]
65
+ * copy points along a linear path where `number` is a path at an angle in
66
+ * radians in the xy plane, and `TypeParsablePoint` is a direction vector
67
+ * @property {TypeParsablePoint} [axis] axis to rotate a 'rotation' copy around
68
+ * (default is the z axis so rotation is in xy plane `[0, 0, 1]`)
69
+ * @property {number} [num] the number of copies to make when copying `along` a
70
+ * path
71
+ * @property {number} [step] distance between copies if `along` is `'x'` or
72
+ * `'y'` or a `number`, delta angle between copies if `along` is `'rotation'`
73
+ * @property {TypeParsablePoint} [center] the center point about which to rotate
74
+ * the copies when using `along` = `'rotation'`
75
+ * @property {number | string} [start] copy step index or marker defining the
76
+ * start of the points to copy
77
+ * @property {number | string} [end] copy step index or marker defining the end
78
+ * of the points to copy
79
+ * @property {boolean} [original] `false` excludes all points before this step
80
+ * in the final result (`true`)
81
+ * @example
82
+ * // Grid copy
83
+ * figure.add({
84
+ * name: 'triGrid',
85
+ * make: 'polygon',
86
+ * radius: 0.1,
87
+ * sides: 3,
88
+ * rotation: -Math.PI / 6,
89
+ * fill: 'tris',
90
+ * copy: [
91
+ * {
92
+ * along: 'x',
93
+ * num: 4,
94
+ * step: 0.3,
95
+ * },
96
+ * {
97
+ * along: 'y',
98
+ * num: 4,
99
+ * step: 0.3,
100
+ * },
101
+ * ],
102
+ * });
103
+ *
104
+ * @example
105
+ * // Radial lines copy
106
+ * figure.add({
107
+ * name: 'radialLines',
108
+ * make: 'generic',
109
+ * points: [
110
+ * [-0.2, -0.1], [-0.2, 0.1], [0.2, 0.1],
111
+ * [-0.2, -0.1], [0.2, 0.1], [0.2, -0.1],
112
+ * ],
113
+ * copy: [
114
+ * {
115
+ * to: [[0.6, 0], [1.05, 0], [1.5, 0], [2.2, 0]],
116
+ * },
117
+ * {
118
+ * along: 'rotation',
119
+ * num: 5,
120
+ * step: Math.PI / 5,
121
+ * start: 1, // only copy last step, not original points
122
+ * },
123
+ * ],
124
+ * });
125
+ *
126
+ * @example
127
+ * // Ring copy (without original shape)
128
+ * figure.add({
129
+ * name: 'halfRings',
130
+ * make: 'polygon',
131
+ * radius: 0.1,
132
+ * sides: 20,
133
+ * fill: 'tris',
134
+ * copy: [
135
+ * 'ring1', // marker 1
136
+ * {
137
+ * to: [0.5, 0],
138
+ * original: false, // don't include the original shape
139
+ * },
140
+ * {
141
+ * along: 'rotation',
142
+ * num: 7,
143
+ * step: Math.PI / 7,
144
+ * start: 'ring1', // copy only from marker 1
145
+ * },
146
+ * 'ring2', // marker 2
147
+ * {
148
+ * to: [1, 0],
149
+ * start: 0, // make a copy of the original shape only
150
+ * end: 1,
151
+ * },
152
+ * {
153
+ * along: 'rotation',
154
+ * num: 15,
155
+ * step: Math.PI / 15,
156
+ * start: 'ring2', // copy points from Marker 2 only
157
+ * },
158
+ * ],
159
+ * });
160
+ * @interface
161
+ * @group Misc Shapes
162
+ */
163
+ export type CPY_Step = {
164
+ to?: TypeParsablePoint | TypeParsableTransform | Array<TypeParsablePoint | TypeParsableTransform>;
165
+ along?: 'x' | 'y' | 'z' | number | 'rotation' | 'moveOnly' | TypeParsablePoint;
166
+ axis?: TypeParsablePoint;
167
+ num?: number;
168
+ step?: number;
169
+ center?: TypeParsablePoint;
170
+ start?: number | string;
171
+ end?: number | string;
172
+ original?: boolean;
173
+ };
174
+ export type CPY_Steps = Array<CPY_Step>;
175
+ declare function copyStep(points: Array<Point>, copyStyle: 'linear' | 'to' | 'rotation' | 'x' | 'y' | 'z' | number | TypeParsablePoint, options: CPY_Step, type?: 'points' | 'normals'): Point[];
176
+ declare function copyPoints(points: Array<TypeParsablePoint> | Array<Point>, chain: CPY_Step | CPY_Steps | null | undefined, type?: 'points' | 'normals'): Array<Point>;
177
+ declare function getCopyCount(chain: CPY_Step | CPY_Steps | null | undefined): number;
178
+ export { copyPoints, copyStep, getCopyCount, };
@@ -0,0 +1,17 @@
1
+ import { Point } from '../../tools/g2';
2
+ import type { OBJ_Generic } from '../FigurePrimitives/FigurePrimitiveTypes2D';
3
+ export type OBJ_Ellipse_Defined = {
4
+ width: number;
5
+ height: number;
6
+ xAlign: 'left' | 'center' | 'right' | number;
7
+ yAlign: 'bottom' | 'middle' | 'top' | number;
8
+ sides: number;
9
+ line?: {
10
+ widthIs: 'inside' | 'outside' | 'positive' | 'negative' | 'mid';
11
+ width: number;
12
+ };
13
+ drawBorderBuffer: number | Array<Array<Point>>;
14
+ } & OBJ_Generic;
15
+ declare function getEllipseBorder(options: OBJ_Ellipse_Defined): Point[];
16
+ declare function ellipseBorderToTris(border: Array<Point>): Point[];
17
+ export { getEllipseBorder, ellipseBorderToTris, };
@@ -0,0 +1,13 @@
1
+ import { Point } from '../../tools/g2';
2
+ import type { TypeParsablePoint } from '../../tools/g2';
3
+ declare function getLine(options: {
4
+ p1: Point;
5
+ p2?: Point;
6
+ length: number;
7
+ width: number;
8
+ angle: number;
9
+ widthIs: 'mid' | 'positive' | 'negative';
10
+ border: 'rect' | 'outline' | Array<Array<TypeParsablePoint>>;
11
+ touchBorder: 'rect' | 'border' | number | Array<Array<TypeParsablePoint>>;
12
+ }): (Point[] | "line" | "rect" | TypeParsablePoint[][] | "outline" | "border")[];
13
+ export default getLine;
@@ -0,0 +1,7 @@
1
+ import { Point } from '../../../tools/g2';
2
+ declare function circleCorner(p2in: Point, p1: Point, p3in: Point, sides: number): Array<Point>;
3
+ declare function cutCorner(p2: Point, p1: Point, p3: Point, sides: number, style: 'radius' | 'fromVertex' | 'max', value: number): Array<Point>;
4
+ declare function cornerLine(pointsIn: Array<Point>, close: boolean, type: 'fromVertex' | 'radius', sides: number, size: number): Point[];
5
+ declare function makeCorner(p2: Point, p1: Point, p3: Point, length: number, forceLength?: boolean): Point[];
6
+ declare function lineToCorners(pointsIn: Array<Point>, close: boolean, length: number, forceLength?: boolean): Point[][];
7
+ export { circleCorner, cutCorner, cornerLine, makeCorner, lineToCorners, };
@@ -0,0 +1,23 @@
1
+ import { Point } from '../../../tools/g2';
2
+ import type { TypeDash } from '../../../tools/types';
3
+ declare function makeDashDefinition(dashes: Array<number>): {
4
+ definition: number[];
5
+ sum: number;
6
+ cum: number[];
7
+ };
8
+ declare function getDashElementAndRemainder(dash: {
9
+ definition: Array<number>;
10
+ cum: Array<number>;
11
+ sum: number;
12
+ }, offset: number, precision?: number): number[];
13
+ declare function makeDashes(dash: {
14
+ definition: Array<number>;
15
+ cum: Array<number>;
16
+ sum: number;
17
+ }, p1: Point, p2: Point, offset: number, precision?: number): {
18
+ points: Point[][];
19
+ continues: boolean;
20
+ onLine: boolean;
21
+ };
22
+ declare function lineToDash(points: Array<Point>, dash: TypeDash, close?: boolean, precision?: number): (boolean | Point[][])[];
23
+ export { getDashElementAndRemainder, makeDashDefinition, makeDashes, lineToDash, };