plotboilerplate 1.23.2 → 1.24.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 +6 -0
- package/dist/index.esm.js +8351 -6928
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1590 -123
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +4 -2
- package/src/cjs/BezierPath.d.ts +41 -5
- package/src/cjs/BezierPath.js +52 -2
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +67 -3
- package/src/cjs/Bounds.js +101 -3
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/Circle.d.ts +46 -4
- package/src/cjs/Circle.js +82 -3
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +51 -2
- package/src/cjs/CircleSector.js +112 -3
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +113 -7
- package/src/cjs/CubicBezierCurve.js +281 -33
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +38 -3
- package/src/cjs/Line.js +64 -1
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +4 -2
- package/src/cjs/PlotBoilerplate.js +9 -12
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +153 -6
- package/src/cjs/Polygon.js +304 -23
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +73 -4
- package/src/cjs/Triangle.js +94 -2
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.d.ts +62 -3
- package/src/cjs/VEllipse.js +181 -17
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/VEllipseSector.d.ts +86 -2
- package/src/cjs/VEllipseSector.js +148 -4
- package/src/cjs/VEllipseSector.js.map +1 -1
- package/src/cjs/Vector.d.ts +12 -2
- package/src/cjs/Vector.js +15 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +39 -10
- package/src/cjs/VertTuple.js +49 -11
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +18 -2
- package/src/cjs/Vertex.js +22 -2
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +1 -0
- package/src/cjs/draw.js +2 -1
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawutilssvg.js +24 -0
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/geomutils.d.ts +32 -1
- package/src/cjs/geomutils.js +47 -1
- package/src/cjs/geomutils.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +39 -0
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/cjs/utils/algorithms/PolygonInset.js +431 -0
- package/src/cjs/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/cjs/utils/algorithms/convexPolygonIncircle.d.ts +2 -1
- package/src/cjs/utils/algorithms/convexPolygonIncircle.js +14 -6
- package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/cjs/utils/createRandomizedPolygon.d.ts +14 -0
- package/src/cjs/utils/createRandomizedPolygon.js +32 -0
- package/src/cjs/utils/createRandomizedPolygon.js.map +1 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -1
- package/src/cjs/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/cjs/utils/dom/guiSizeToggler.js +5 -3
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +9 -7
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +37 -23
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +10 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.js +19 -20
- package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/cjs/utils/helpers/VEllipseHelper.d.ts +30 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js +86 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +42 -3
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js +107 -25
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/createDemoDrawables.js +3 -1
- package/src/esm/BezierPath.d.ts +41 -5
- package/src/esm/BezierPath.js +50 -2
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +67 -3
- package/src/esm/Bounds.js +101 -3
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/Circle.d.ts +46 -4
- package/src/esm/Circle.js +79 -3
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CircleSector.d.ts +51 -2
- package/src/esm/CircleSector.js +108 -3
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +113 -7
- package/src/esm/CubicBezierCurve.js +277 -33
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +38 -3
- package/src/esm/Line.js +62 -1
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -2
- package/src/esm/PlotBoilerplate.js +9 -12
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +153 -6
- package/src/esm/Polygon.js +301 -23
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +73 -4
- package/src/esm/Triangle.js +91 -2
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.d.ts +62 -3
- package/src/esm/VEllipse.js +178 -17
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/VEllipseSector.d.ts +86 -2
- package/src/esm/VEllipseSector.js +146 -7
- package/src/esm/VEllipseSector.js.map +1 -1
- package/src/esm/Vector.d.ts +12 -2
- package/src/esm/Vector.js +15 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +39 -10
- package/src/esm/VertTuple.js +49 -11
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +18 -2
- package/src/esm/Vertex.js +22 -2
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +1 -0
- package/src/esm/draw.js +2 -1
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawutilssvg.js +24 -0
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/geomutils.d.ts +32 -1
- package/src/esm/geomutils.js +47 -1
- package/src/esm/geomutils.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +39 -0
- package/src/esm/interfaces/core.js +2 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/esm/utils/algorithms/PolygonInset.js +424 -0
- package/src/esm/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/esm/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/esm/utils/algorithms/convexPolygonIncircle.d.ts +2 -1
- package/src/esm/utils/algorithms/convexPolygonIncircle.js +15 -7
- package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/esm/utils/algorithms/createRandomizedPolygon.d.ts +14 -0
- package/src/esm/utils/algorithms/createRandomizedPolygon.js +28 -0
- package/src/esm/utils/algorithms/createRandomizedPolygon.js.map +1 -0
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/esm/utils/createRandomizedPolygon.d.ts +14 -0
- package/src/esm/utils/createRandomizedPolygon.js +28 -0
- package/src/esm/utils/createRandomizedPolygon.js.map +1 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -1
- package/src/esm/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/esm/utils/dom/guiSizeToggler.js +4 -2
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +9 -7
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +35 -22
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleSectorHelper.d.ts +10 -1
- package/src/esm/utils/helpers/CircleSectorHelper.js +19 -20
- package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/esm/utils/helpers/VEllipseHelper.d.ts +30 -0
- package/src/esm/utils/helpers/VEllipseHelper.js +81 -0
- package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +42 -3
- package/src/esm/utils/helpers/VEllipseSectorHelper.js +106 -24
- package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/ts/BezierPath.ts +58 -5
- package/src/ts/Bounds.ts +110 -6
- package/src/ts/Circle.ts +87 -5
- package/src/ts/CircleSector.ts +115 -5
- package/src/ts/CubicBezierCurve.ts +332 -42
- package/src/ts/Line.ts +66 -3
- package/src/ts/PlotBoilerplate.ts +10 -12
- package/src/ts/Polygon.ts +329 -27
- package/src/ts/Triangle.ts +101 -5
- package/src/ts/VEllipse.ts +214 -19
- package/src/ts/VEllipseSector.ts +154 -8
- package/src/ts/Vector.ts +16 -2
- package/src/ts/VertTuple.ts +53 -13
- package/src/ts/Vertex.ts +24 -3
- package/src/ts/draw.ts +2 -1
- package/src/ts/drawutilssvg.ts +29 -0
- package/src/ts/geomutils.ts +49 -1
- package/src/ts/interfaces/core.ts +42 -0
- package/src/ts/utils/algorithms/PolygonInset.ts +529 -0
- package/src/ts/utils/algorithms/clearDuplicateVertices.ts +11 -8
- package/src/ts/utils/algorithms/convexPolygonIncircle.ts +82 -78
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts +25 -26
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts +92 -99
- package/src/ts/utils/createRandomizedPolygon.ts +31 -0
- package/src/ts/utils/detectDarkMode.ts +1 -3
- package/src/ts/utils/dom/guiSizeToggler.ts +4 -2
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +45 -29
- package/src/ts/utils/helpers/CircleSectorHelper.ts +115 -125
- package/src/ts/utils/helpers/VEllipseHelper.ts +113 -0
- package/src/ts/utils/helpers/VEllipseSectorHelper.ts +142 -25
|
@@ -22,16 +22,18 @@
|
|
|
22
22
|
* @modified 2021-03-31 Fixed the issue with the new AlloyFinger (Typescript).
|
|
23
23
|
* @modified 2022-02-03 Changing the element to catch events (eventCatcher instead of canvas).
|
|
24
24
|
* @modified 2024-03-10 Fixing some types for Typescript 5 compatibility.
|
|
25
|
-
* @
|
|
25
|
+
* @modified 2025-04-14 Added the `BezierPathInteractionHelper.drawHandleLines` method.
|
|
26
|
+
* @modified 2025-04-14 Fixing correct event types for touch events in `BezierPathInteractionHelper`.
|
|
27
|
+
* @modified 2025-04-14 BezierPathInteractionHelper: Changed default value of `HelperOptions.autoAdjustPaths` from `true` to `false`.
|
|
28
|
+
* @version 1.2.0
|
|
26
29
|
*
|
|
27
30
|
* @file BezierPathInteractionHelper
|
|
28
31
|
* @public
|
|
29
32
|
**/
|
|
30
33
|
|
|
31
|
-
// import { AlloyFinger } from "alloyfinger"; // node_modules
|
|
32
34
|
// I would like to use AlloyFinger from the node_modules, but it seems
|
|
33
35
|
// AlloyTeam has forgotten to publish their d.ts file.
|
|
34
|
-
import
|
|
36
|
+
import AlloyFinger from "alloyfinger-typescript";
|
|
35
37
|
import { BezierPath } from "../../BezierPath";
|
|
36
38
|
import { CubicBezierCurve } from "../../CubicBezierCurve";
|
|
37
39
|
import { KeyHandler } from "../../KeyHandler";
|
|
@@ -40,7 +42,8 @@ import { PlotBoilerplate } from "../../PlotBoilerplate";
|
|
|
40
42
|
import { VertListener } from "../../VertexListeners";
|
|
41
43
|
import { Vertex } from "../../Vertex";
|
|
42
44
|
import { XMouseEvent } from "../../MouseHandler";
|
|
43
|
-
import { XYCoords } from "../../interfaces";
|
|
45
|
+
import { DrawLib, XYCoords } from "../../interfaces";
|
|
46
|
+
import { AFTouchEvent } from "alloyfinger-typescript/src/cjs/alloy_finger";
|
|
44
47
|
|
|
45
48
|
/**
|
|
46
49
|
* Handler type for mouse-pointer-moved listeners.
|
|
@@ -153,7 +156,9 @@ export class BezierPathInteractionHelper {
|
|
|
153
156
|
this.pb = pb;
|
|
154
157
|
this.paths = [];
|
|
155
158
|
this.onPointerMoved =
|
|
156
|
-
typeof options.onPointerMoved === "function"
|
|
159
|
+
typeof options.onPointerMoved === "function"
|
|
160
|
+
? options.onPointerMoved
|
|
161
|
+
: (i: number, a: Vertex | null, b: Vertex | null, t: number) => {};
|
|
157
162
|
this.onVertexInserted =
|
|
158
163
|
typeof options.onVertexInserted === "function"
|
|
159
164
|
? options.onVertexInserted
|
|
@@ -163,7 +168,7 @@ export class BezierPathInteractionHelper {
|
|
|
163
168
|
? options.onVerticesDeleted
|
|
164
169
|
: (i: number, r: Array<number>, n: BezierPath, o: BezierPath) => {};
|
|
165
170
|
this.onPathRemoved = typeof options.onPathRemoved === "function" ? options.onPathRemoved : (i: number, o: BezierPath) => {};
|
|
166
|
-
this.autoAdjustPaths = typeof options.autoAdjustPaths === "boolean" ? options.autoAdjustPaths : true;
|
|
171
|
+
this.autoAdjustPaths = typeof options.autoAdjustPaths === "boolean" ? options.autoAdjustPaths : false; // true;
|
|
167
172
|
this.allowPathRemoval = typeof options.allowPathRemoval === "boolean" ? options.allowPathRemoval : true;
|
|
168
173
|
this.maxDetectDistance = typeof options.maxDetectDistance === "number" ? options.maxDetectDistance : Number.MAX_VALUE;
|
|
169
174
|
|
|
@@ -192,7 +197,9 @@ export class BezierPathInteractionHelper {
|
|
|
192
197
|
this._keyHandler = this._installKeyListener();
|
|
193
198
|
|
|
194
199
|
// Paths might have changed by auto-adjustment.
|
|
195
|
-
if (this.autoAdjustPaths)
|
|
200
|
+
if (this.autoAdjustPaths) {
|
|
201
|
+
pb.redraw();
|
|
202
|
+
}
|
|
196
203
|
}
|
|
197
204
|
|
|
198
205
|
/**
|
|
@@ -263,6 +270,24 @@ export class BezierPathInteractionHelper {
|
|
|
263
270
|
this._handleMoveEvent(this.currentB.x, this.currentB.y);
|
|
264
271
|
}
|
|
265
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Draw grey handle lines.
|
|
275
|
+
*
|
|
276
|
+
*/
|
|
277
|
+
drawHandleLines() {
|
|
278
|
+
this.paths.forEach((path: BezierPath) => {
|
|
279
|
+
path.bezierCurves.forEach((curve: CubicBezierCurve) => {
|
|
280
|
+
this.pb.draw.line(curve.startPoint, curve.startControlPoint, "rgba(64,192,128,0.333)", 1.0, {
|
|
281
|
+
dashOffset: 0.0,
|
|
282
|
+
dashArray: [4, 2]
|
|
283
|
+
});
|
|
284
|
+
this.pb.draw.line(curve.endPoint, curve.endControlPoint, "rgba(64,192,128,0.333)", 1.0, {
|
|
285
|
+
dashOffset: 0.0,
|
|
286
|
+
dashArray: [4, 2]
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
266
291
|
/**
|
|
267
292
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
268
293
|
* After calling this function the object might not hold valid data any more and
|
|
@@ -438,22 +463,31 @@ export class BezierPathInteractionHelper {
|
|
|
438
463
|
var _self: BezierPathInteractionHelper = this;
|
|
439
464
|
const afProps = {
|
|
440
465
|
// Todo: which event types does AlloyFinger use?
|
|
441
|
-
touchStart: function (_event: TouchEvent) {
|
|
466
|
+
// touchStart: function (_event: TouchEvent) {
|
|
467
|
+
// _self.mouseIsOver = true;
|
|
468
|
+
// },
|
|
469
|
+
// /* TouchMoveEvent , AFTouchEvent<"touchStart"> */
|
|
470
|
+
touchStart: function (_event: AFTouchEvent<"touchStart">) {
|
|
442
471
|
_self.mouseIsOver = true;
|
|
443
472
|
},
|
|
444
|
-
touchMove: function (event:
|
|
473
|
+
touchMove: function (event: AFTouchEvent<"touchMove">) {
|
|
474
|
+
// TouchEvent) {
|
|
445
475
|
if (_self.pb.getDraggedElementCount() == 0 && event.touches.length > 0) {
|
|
446
476
|
// console.log('touchmove');
|
|
447
477
|
_self._handleMoveEvent(event.touches[0].clientX, event.touches[0].clientY);
|
|
448
478
|
}
|
|
449
479
|
},
|
|
450
|
-
touchEnd: function (_event:
|
|
480
|
+
touchEnd: function (_event: AFTouchEvent<"touchEnd">) {
|
|
481
|
+
// TouchEvent) {
|
|
451
482
|
_self.mouseIsOver = false;
|
|
452
483
|
_self._clearMoveEvent();
|
|
453
484
|
}
|
|
454
485
|
};
|
|
455
486
|
if (window["createAlloyFinger" as keyof Object]) {
|
|
456
|
-
return (window["createAlloyFinger" as keyof Object] as any)(
|
|
487
|
+
return (window["createAlloyFinger" as keyof Object] as any)(
|
|
488
|
+
this.pb.eventCatcher ? this.pb.eventCatcher : this.pb.eventCatcher,
|
|
489
|
+
afProps
|
|
490
|
+
);
|
|
457
491
|
} else {
|
|
458
492
|
return new AlloyFinger(this.pb.eventCatcher ? this.pb.eventCatcher : this.pb.eventCatcher, afProps);
|
|
459
493
|
}
|
|
@@ -578,24 +612,6 @@ export class BezierPathInteractionHelper {
|
|
|
578
612
|
path.updateArcLengths();
|
|
579
613
|
}
|
|
580
614
|
|
|
581
|
-
/**
|
|
582
|
-
* A helper function to add drag-start-listener to given vertices.
|
|
583
|
-
*/
|
|
584
|
-
/* private static _addVertsDragStartListener( verts:Array<Vertex>, dragStartListener:VertListener ) : void {
|
|
585
|
-
for( var i in verts ) {
|
|
586
|
-
verts[i].addDragStartListener( dragStartListener );
|
|
587
|
-
}
|
|
588
|
-
}; */
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* A helper function to remove drag-start-listener to given vertices.
|
|
592
|
-
*/
|
|
593
|
-
/* private static _removeVertsDragStartListener( verts:Array<Vertex>, dragEndListener:VertListener ) : void {
|
|
594
|
-
for( var i in verts ) {
|
|
595
|
-
verts[i].removeDragStartListener( dragStartListener );
|
|
596
|
-
}
|
|
597
|
-
}; */
|
|
598
|
-
|
|
599
615
|
/**
|
|
600
616
|
* A helper function to add drag-start listeners to all vertices of the given path.
|
|
601
617
|
*
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @version 1.0.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Easily handle circle sectors (mouse or touch) with this circle sector helper.
|
|
10
9
|
*
|
|
@@ -15,138 +14,129 @@
|
|
|
15
14
|
* @date 2021-01-22
|
|
16
15
|
* @modified 2021-01-26 Moving control points with center points
|
|
17
16
|
* @modified 2024-03-10 Adding the `destory` method for properly removing installed listeners.
|
|
18
|
-
* @
|
|
17
|
+
* @modified 2025-04-02 Adding `CircleSectorHelper.drawHandleLines()`,
|
|
18
|
+
* @version 1.2.0
|
|
19
19
|
**/
|
|
20
20
|
|
|
21
21
|
import { CircleSector } from "../../CircleSector";
|
|
22
22
|
import { PlotBoilerplate } from "../../PlotBoilerplate";
|
|
23
23
|
import { VertEvent, VertListener } from "../../VertexListeners";
|
|
24
24
|
import { Vertex } from "../../Vertex";
|
|
25
|
-
|
|
25
|
+
import { DrawLib } from "../../interfaces";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @classdesc A helper for handling circles with an additional radius-control-point.
|
|
29
29
|
*/
|
|
30
30
|
export class CircleSectorHelper {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
public destroy() : void {
|
|
144
|
-
this.circleSector.circle.center.listeners.removeDragListener( this.centerListener );
|
|
145
|
-
this.controlPointStart.listeners.removeDragListener( this.radiusStartListener );
|
|
146
|
-
this.controlPointEnd.listeners.removeDragListener( this.radiusEndListener );
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
31
|
+
private circleSector: CircleSector;
|
|
32
|
+
private controlPointStart: Vertex;
|
|
33
|
+
private controlPointEnd: Vertex;
|
|
34
|
+
|
|
35
|
+
private centerListener: VertListener;
|
|
36
|
+
private radiusStartListener: VertListener;
|
|
37
|
+
private radiusEndListener: VertListener;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The constructor.
|
|
41
|
+
*
|
|
42
|
+
* @constructor
|
|
43
|
+
* @name CircleSectorHelper
|
|
44
|
+
* @param {CircleSector} circleSector - The circle sector to handle.
|
|
45
|
+
* @param {Vertex} controlPointStart - A point to define the radius and start angle (distance and angle from center).
|
|
46
|
+
* @param {Vertex} controlPointEnd - A point to define the radius and end angle (distance and angle from center).
|
|
47
|
+
* @param {PlotBoilerplate} pb - The PlotBoilerplate which contains the circle sector and both points.
|
|
48
|
+
**/
|
|
49
|
+
constructor(circleSector: CircleSector, controlPointStart: Vertex, controlPointEnd: Vertex, pb: PlotBoilerplate) {
|
|
50
|
+
this.circleSector = circleSector;
|
|
51
|
+
this.controlPointStart = controlPointStart;
|
|
52
|
+
this.controlPointEnd = controlPointEnd;
|
|
53
|
+
|
|
54
|
+
this.circleSector.circle.center.listeners.addDragListener((this.centerListener = this._handleDragCenter()));
|
|
55
|
+
this.controlPointStart.listeners.addDragListener((this.radiusStartListener = this._handleDragStartControlPoint()));
|
|
56
|
+
this.controlPointEnd.listeners.addDragListener((this.radiusEndListener = this._handleDragEndControlPoint()));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new drag handler for the circle sector's center point.
|
|
61
|
+
*
|
|
62
|
+
* @private
|
|
63
|
+
* @method handleDragCenter
|
|
64
|
+
* @instance
|
|
65
|
+
* @memberof CircleSectorHelper
|
|
66
|
+
* @returns A new event handler.
|
|
67
|
+
*/
|
|
68
|
+
private _handleDragCenter(): VertListener {
|
|
69
|
+
const _self = this;
|
|
70
|
+
return (e: VertEvent) => {
|
|
71
|
+
_self.controlPointStart.add(e.params.dragAmount);
|
|
72
|
+
_self.controlPointEnd.add(e.params.dragAmount);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new drag handler for the circle sector's start control point.
|
|
78
|
+
*
|
|
79
|
+
* @private
|
|
80
|
+
* @method _handleDragStartControlPoint
|
|
81
|
+
* @instance
|
|
82
|
+
* @memberof CircleSectorHelper
|
|
83
|
+
* @returns A new event handler.
|
|
84
|
+
*/
|
|
85
|
+
private _handleDragStartControlPoint(): VertListener {
|
|
86
|
+
const _self = this;
|
|
87
|
+
return (e: VertEvent) => {
|
|
88
|
+
_self.circleSector.circle.radius = _self.circleSector.circle.center.distance(_self.controlPointStart);
|
|
89
|
+
_self.controlPointEnd.set(_self.circleSector.circle.vertAt(_self.circleSector.endAngle));
|
|
90
|
+
_self.circleSector.startAngle = _self.circleSector.circle.center.angle(_self.controlPointStart);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new drag handler for the circle sector's end control point.
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
* @method _handleDragEndControlPoint
|
|
99
|
+
* @instance
|
|
100
|
+
* @memberof CircleSectorHelper
|
|
101
|
+
* @returns A new event handler.
|
|
102
|
+
*/
|
|
103
|
+
private _handleDragEndControlPoint(): VertListener {
|
|
104
|
+
const _self = this;
|
|
105
|
+
return (e: VertEvent) => {
|
|
106
|
+
_self.circleSector.circle.radius = _self.circleSector.circle.center.distance(_self.controlPointEnd);
|
|
107
|
+
_self.controlPointStart.set(_self.circleSector.circle.vertAt(_self.circleSector.startAngle));
|
|
108
|
+
_self.circleSector.endAngle = _self.circleSector.circle.center.angle(_self.controlPointEnd);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Draw grey handle lines.
|
|
114
|
+
*
|
|
115
|
+
* @param {DrawLib<any>} draw - The draw library instance to use.
|
|
116
|
+
* @param {DrawLib<any>} fill - The fill library instance to use.
|
|
117
|
+
*/
|
|
118
|
+
public drawHandleLines(draw: DrawLib<any>, fill: DrawLib<any>) {
|
|
119
|
+
draw.line(this.circleSector.circle.center, this.controlPointStart, "rgba(64,192,128,0.333)", 1.0, {
|
|
120
|
+
dashOffset: 0.0,
|
|
121
|
+
dashArray: [4, 2]
|
|
122
|
+
});
|
|
123
|
+
draw.line(this.circleSector.circle.center, this.controlPointEnd, "rgba(64,192,128,0.333)", 1.0, {
|
|
124
|
+
dashOffset: 0.0,
|
|
125
|
+
dashArray: [4, 2]
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Destroy this circle helper.
|
|
131
|
+
* The listeners will be removed from the circle sector's points.
|
|
132
|
+
*
|
|
133
|
+
* @method destroy
|
|
134
|
+
* @instance
|
|
135
|
+
* @memberof CircleSectorHelper
|
|
136
|
+
*/
|
|
137
|
+
public destroy(): void {
|
|
138
|
+
this.circleSector.circle.center.listeners.removeDragListener(this.centerListener);
|
|
139
|
+
this.controlPointStart.listeners.removeDragListener(this.radiusStartListener);
|
|
140
|
+
this.controlPointEnd.listeners.removeDragListener(this.radiusEndListener);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper for VEllipses.
|
|
3
|
+
*
|
|
4
|
+
* @author Ikaros Kappler
|
|
5
|
+
* @date 2025-03-31
|
|
6
|
+
* @modified 2025-04-02 Adding `VEllipseHelper.drawHandleLines()`.
|
|
7
|
+
* @modified 2025-04-09 Adding `VEllipseHelper.destroy()`.
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Line } from "../../Line";
|
|
12
|
+
import { VEllipse } from "../../VEllipse";
|
|
13
|
+
import { Vertex } from "../../Vertex";
|
|
14
|
+
import { VertEvent, VertListener } from "../../VertexListeners";
|
|
15
|
+
import { DrawLib } from "../../interfaces";
|
|
16
|
+
|
|
17
|
+
export class VEllipseHelper {
|
|
18
|
+
private readonly ellipse: VEllipse;
|
|
19
|
+
private readonly rotationControlPoint: Vertex;
|
|
20
|
+
|
|
21
|
+
private _rotationControlLine: Line;
|
|
22
|
+
|
|
23
|
+
private _centerPointHandler: VertListener;
|
|
24
|
+
private _rotationPointHandler: VertListener;
|
|
25
|
+
|
|
26
|
+
constructor(ellipse: VEllipse, rotationControlPoint: Vertex) {
|
|
27
|
+
this.ellipse = ellipse;
|
|
28
|
+
this.rotationControlPoint = rotationControlPoint;
|
|
29
|
+
|
|
30
|
+
// const rotationControlLine: Line = new Line(ellipse.center, rotationControlPoint);
|
|
31
|
+
this._rotationControlLine = new Line(ellipse.center, rotationControlPoint);
|
|
32
|
+
|
|
33
|
+
// +---------------------------------------------------------------------
|
|
34
|
+
// | Listen for the center to be moved.
|
|
35
|
+
// +-------------------------------------------
|
|
36
|
+
// ellipse.center.listeners.addDragListener((event: VertEvent) => {
|
|
37
|
+
// rotationControlPoint.add(event.params.dragAmount);
|
|
38
|
+
// });
|
|
39
|
+
ellipse.center.listeners.addDragListener((this._centerPointHandler = this._handleDragCenterPoint()));
|
|
40
|
+
|
|
41
|
+
// +---------------------------------------------------------------------
|
|
42
|
+
// | Listen for rotation changes.
|
|
43
|
+
// +-------------------------------------------
|
|
44
|
+
// rotationControlPoint.listeners.addDragListener((_event: VertEvent) => {
|
|
45
|
+
// var newRotation = rotationControlLine.angle();
|
|
46
|
+
// var rDiff = newRotation - ellipse.rotation;
|
|
47
|
+
// ellipse.rotation = newRotation;
|
|
48
|
+
// ellipse.axis.rotate(rDiff, ellipse.center);
|
|
49
|
+
// });
|
|
50
|
+
rotationControlPoint.listeners.addDragListener((this._rotationPointHandler = this._handleRotationCenterPoint()));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private _handleDragCenterPoint(): VertListener {
|
|
54
|
+
const _self = this;
|
|
55
|
+
return (event: VertEvent) => {
|
|
56
|
+
_self.rotationControlPoint.add(event.params.dragAmount);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private _handleRotationCenterPoint(): VertListener {
|
|
61
|
+
const _self = this;
|
|
62
|
+
return (_event: VertEvent) => {
|
|
63
|
+
var newRotation = _self._rotationControlLine.angle();
|
|
64
|
+
var rDiff = newRotation - _self.ellipse.rotation;
|
|
65
|
+
_self.ellipse.rotation = newRotation;
|
|
66
|
+
_self.ellipse.axis.rotate(rDiff, _self.ellipse.center);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Draw grey handle lines.
|
|
72
|
+
*
|
|
73
|
+
* @param {DrawLib<any>} draw - The draw library instance to use.
|
|
74
|
+
* @param {DrawLib<any>} fill - The fill library instance to use.
|
|
75
|
+
*/
|
|
76
|
+
drawHandleLines(draw: DrawLib<any>, fill: DrawLib<any>) {
|
|
77
|
+
// Draw rotation handle line
|
|
78
|
+
draw.line(this.ellipse.center, this.rotationControlPoint, "rgba(192,64,128,0.333)", 1.0, {
|
|
79
|
+
dashOffset: 0.0,
|
|
80
|
+
dashArray: [4, 2]
|
|
81
|
+
});
|
|
82
|
+
// Draw helper box
|
|
83
|
+
draw.setCurrentId(`${this.ellipse.uid}_e0`);
|
|
84
|
+
draw.setCurrentClassName(`${this.ellipse.className}-v-line`);
|
|
85
|
+
draw.line(
|
|
86
|
+
this.ellipse.center.clone().add(0, this.ellipse.signedRadiusV()).rotate(this.ellipse.rotation, this.ellipse.center),
|
|
87
|
+
this.ellipse.axis,
|
|
88
|
+
"rgba(64,128,192,0.333)",
|
|
89
|
+
1.0,
|
|
90
|
+
{
|
|
91
|
+
dashOffset: 0.0,
|
|
92
|
+
dashArray: [4, 2]
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
draw.setCurrentId(`${this.ellipse.uid}_e1`);
|
|
96
|
+
draw.setCurrentClassName(`${this.ellipse.className}-h-line`);
|
|
97
|
+
draw.line(
|
|
98
|
+
this.ellipse.center.clone().add(this.ellipse.signedRadiusH(), 0).rotate(this.ellipse.rotation, this.ellipse.center),
|
|
99
|
+
this.ellipse.axis,
|
|
100
|
+
"rgba(64,128,192,0.333)",
|
|
101
|
+
1.0,
|
|
102
|
+
{
|
|
103
|
+
dashOffset: 0.0,
|
|
104
|
+
dashArray: [4, 2]
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
detroy(): void {
|
|
110
|
+
this.ellipse.center.listeners.removeDragListener(this._centerPointHandler);
|
|
111
|
+
this.rotationControlPoint.listeners.removeDragListener(this._rotationPointHandler);
|
|
112
|
+
}
|
|
113
|
+
}
|