plotboilerplate 1.23.3 → 1.25.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 +19 -1
- package/dist/index.esm.js +1684 -394
- 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 +12450 -11120
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +9 -5
- 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 +37 -6
- package/src/cjs/PlotBoilerplate.js +224 -125
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +68 -5
- package/src/cjs/Polygon.js +143 -22
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +52 -3
- package/src/cjs/Triangle.js +80 -1
- 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 +28 -4
- package/src/cjs/VertTuple.js +36 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +31 -4
- package/src/cjs/Vertex.js +35 -1
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +67 -0
- package/src/cjs/interfaces/core.js +4 -0
- package/src/cjs/interfaces/core.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/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/datastructures/Color.d.ts +147 -1
- package/src/cjs/utils/datastructures/Color.js +385 -41
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/datastructures/ColorGradient.d.ts +79 -0
- package/src/cjs/utils/datastructures/ColorGradient.js +171 -0
- package/src/cjs/utils/datastructures/ColorGradient.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.d.ts +245 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.js +667 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js +520 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.d.ts +117 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.js +325 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.js.map +1 -0
- package/src/cjs/utils/dom/components/Test.d.ts +7 -0
- package/src/cjs/utils/dom/components/Test.js +30 -0
- package/src/cjs/utils/dom/components/Test.js.map +1 -0
- package/src/cjs/utils/dom/guiSizeToggler.js +1 -1
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +16 -8
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +49 -28
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleHelper.d.ts +10 -1
- package/src/cjs/utils/helpers/CircleHelper.js +13 -2
- package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +11 -2
- package/src/cjs/utils/helpers/CircleSectorHelper.js +20 -20
- package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/cjs/utils/helpers/TriangleHelper.d.ts +57 -0
- package/src/cjs/utils/helpers/TriangleHelper.js +83 -0
- package/src/cjs/utils/helpers/TriangleHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseHelper.d.ts +32 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js +88 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +44 -4
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js +108 -25
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/cjs/utils/parsers/LinearColorGradientParser.d.ts +78 -0
- package/src/cjs/utils/parsers/LinearColorGradientParser.js +224 -0
- package/src/cjs/utils/parsers/LinearColorGradientParser.js.map +1 -0
- package/src/createDemoDrawables.js +4 -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 +37 -6
- package/src/esm/PlotBoilerplate.js +224 -125
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +68 -5
- package/src/esm/Polygon.js +138 -22
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +52 -3
- package/src/esm/Triangle.js +77 -1
- 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 +28 -4
- package/src/esm/VertTuple.js +36 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +31 -4
- package/src/esm/Vertex.js +35 -1
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +67 -0
- package/src/esm/interfaces/core.js +4 -0
- package/src/esm/interfaces/core.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/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/datastructures/Color.d.ts +147 -1
- package/src/esm/utils/datastructures/Color.js +386 -42
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/datastructures/ColorGradient.d.ts +79 -0
- package/src/esm/utils/datastructures/ColorGradient.js +166 -0
- package/src/esm/utils/datastructures/ColorGradient.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.d.ts +245 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.js +732 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.js +582 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.d.ts +117 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.js +332 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.js.map +1 -0
- package/src/esm/utils/dom/components/Test.d.ts +7 -0
- package/src/esm/utils/dom/components/Test.js +26 -0
- package/src/esm/utils/dom/components/Test.js.map +1 -0
- package/src/esm/utils/dom/guiSizeToggler.js +1 -1
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +16 -8
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +47 -27
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleHelper.d.ts +10 -1
- package/src/esm/utils/helpers/CircleHelper.js +13 -2
- package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleSectorHelper.d.ts +11 -2
- package/src/esm/utils/helpers/CircleSectorHelper.js +20 -20
- package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/esm/utils/helpers/TriangleHelper.d.ts +57 -0
- package/src/esm/utils/helpers/TriangleHelper.js +78 -0
- package/src/esm/utils/helpers/TriangleHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseHelper.d.ts +32 -0
- package/src/esm/utils/helpers/VEllipseHelper.js +83 -0
- package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +44 -4
- package/src/esm/utils/helpers/VEllipseSectorHelper.js +107 -24
- package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/esm/utils/parsers/LinearColorGradientParser.d.ts +78 -0
- package/src/esm/utils/parsers/LinearColorGradientParser.js +217 -0
- package/src/esm/utils/parsers/LinearColorGradientParser.js.map +1 -0
- package/src/external.d.ts +9 -0
- 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 +236 -114
- package/src/ts/Polygon.ts +164 -29
- package/src/ts/Triangle.ts +85 -3
- 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 +39 -4
- package/src/ts/Vertex.ts +40 -4
- package/src/ts/interfaces/core.ts +73 -0
- package/src/ts/utils/algorithms/convexPolygonIncircle.ts +82 -78
- package/src/ts/utils/createRandomizedPolygon.ts +31 -0
- package/src/ts/utils/datastructures/Color.ts +423 -44
- package/src/ts/utils/datastructures/ColorGradient.ts +196 -0
- package/src/ts/utils/dom/components/ColorGradientPicker.tsx +877 -0
- package/src/ts/utils/dom/components/ColorGradientSelector.tsx +445 -0
- package/src/ts/utils/dom/components/Test.tsx +44 -0
- package/src/ts/utils/dom/components/_ColorGradientPicker_raw.ts_ +392 -0
- package/src/ts/utils/dom/guiSizeToggler.ts +1 -1
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +61 -35
- package/src/ts/utils/helpers/CircleHelper.ts +17 -3
- package/src/ts/utils/helpers/CircleSectorHelper.ts +118 -126
- package/src/ts/utils/helpers/TriangleHelper.ts +102 -0
- package/src/ts/utils/helpers/VEllipseHelper.ts +115 -0
- package/src/ts/utils/helpers/VEllipseSectorHelper.ts +144 -26
- package/src/ts/utils/parsers/LinearColorGradientParser.ts +297 -0
package/src/ts/BezierPath.ts
CHANGED
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
* @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
26
26
|
* @modified 2023-10-06 Adding the `BezierPath.toPathPoints()` method.
|
|
27
27
|
* @modified 2023-10-07 Adding the `BezierPath.fromCurve(CubicBezierCurve)` static function.
|
|
28
|
-
* @
|
|
28
|
+
* @modified 2025-04-09 Added the `BezierPath.move` method to match the convention – which just calls `translate`.
|
|
29
|
+
* @modified 2025-04-09 Modified the `BezierPath.translate` method: chaning parameter `Vertex` to more generalized `XYCoords`.
|
|
30
|
+
* @modified 2025-04-14 Class `BezierPath` is now implementing interface `Intersectable`.
|
|
31
|
+
* @version 2.7.0
|
|
29
32
|
*
|
|
30
33
|
* @file BezierPath
|
|
31
34
|
* @public
|
|
@@ -34,8 +37,10 @@
|
|
|
34
37
|
import { Bounds } from "./Bounds";
|
|
35
38
|
import { CubicBezierCurve } from "./CubicBezierCurve";
|
|
36
39
|
import { UIDGenerator } from "./UIDGenerator";
|
|
40
|
+
import { Vector } from "./Vector";
|
|
41
|
+
import { VertTuple } from "./VertTuple";
|
|
37
42
|
import { Vertex } from "./Vertex";
|
|
38
|
-
import { XYCoords, SVGSerializable, UID } from "./interfaces";
|
|
43
|
+
import { XYCoords, SVGSerializable, UID, Intersectable, IBounded } from "./interfaces";
|
|
39
44
|
|
|
40
45
|
/**
|
|
41
46
|
* @classdesc A BezierPath class.
|
|
@@ -50,7 +55,7 @@ import { XYCoords, SVGSerializable, UID } from "./interfaces";
|
|
|
50
55
|
* @requires UID
|
|
51
56
|
* @requires UIDGenerator
|
|
52
57
|
**/
|
|
53
|
-
export class BezierPath implements SVGSerializable {
|
|
58
|
+
export class BezierPath implements IBounded, Intersectable, SVGSerializable {
|
|
54
59
|
/**
|
|
55
60
|
* Required to generate proper CSS classes and other class related IDs.
|
|
56
61
|
**/
|
|
@@ -309,13 +314,13 @@ export class BezierPath implements SVGSerializable {
|
|
|
309
314
|
* Move the whole bezier path by the given (x,y)-amount.
|
|
310
315
|
*
|
|
311
316
|
* @method translate
|
|
312
|
-
* @param {
|
|
317
|
+
* @param {XYCoords} amount - The amount to be added (amount.x and amount.y)
|
|
313
318
|
* to each vertex of the curve.
|
|
314
319
|
* @instance
|
|
315
320
|
* @memberof BezierPath
|
|
316
321
|
* @return {BezierPath} this for chaining
|
|
317
322
|
**/
|
|
318
|
-
translate(amount:
|
|
323
|
+
translate(amount: XYCoords): BezierPath {
|
|
319
324
|
for (var i = 0; i < this.bezierCurves.length; i++) {
|
|
320
325
|
var curve = this.bezierCurves[i];
|
|
321
326
|
curve.getStartPoint().add(amount);
|
|
@@ -331,6 +336,20 @@ export class BezierPath implements SVGSerializable {
|
|
|
331
336
|
return this;
|
|
332
337
|
}
|
|
333
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Move the whole bezier path by the given (x,y)-amount.
|
|
341
|
+
*
|
|
342
|
+
* @method move
|
|
343
|
+
* @param {XYCoords} amount - The amount to be added (amount.x and amount.y)
|
|
344
|
+
* to each vertex of the curve.
|
|
345
|
+
* @instance
|
|
346
|
+
* @memberof BezierPath
|
|
347
|
+
* @return {BezierPath} this for chaining
|
|
348
|
+
**/
|
|
349
|
+
move(amount: XYCoords): BezierPath {
|
|
350
|
+
return this.translate(amount);
|
|
351
|
+
}
|
|
352
|
+
|
|
334
353
|
/**
|
|
335
354
|
* Scale the whole bezier path by the given uniform factor.
|
|
336
355
|
*
|
|
@@ -559,6 +578,38 @@ export class BezierPath implements SVGSerializable {
|
|
|
559
578
|
return bCurve.getPerpendicular(relativeU);
|
|
560
579
|
}
|
|
561
580
|
|
|
581
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
582
|
+
/**
|
|
583
|
+
* Get all line intersections with this shape.
|
|
584
|
+
*
|
|
585
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
586
|
+
*
|
|
587
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
588
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
589
|
+
* @returns {Array<Vertex>} - An array of all intersections with the shape's outline.
|
|
590
|
+
*/
|
|
591
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vertex> {
|
|
592
|
+
return this.bezierCurves.reduce((accu: Array<Vertex>, curCurve: CubicBezierCurve) => {
|
|
593
|
+
return accu.concat(curCurve.lineIntersections(line, inVectorBoundsOnly));
|
|
594
|
+
}, []);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
599
|
+
*
|
|
600
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
601
|
+
*
|
|
602
|
+
* @param line
|
|
603
|
+
* @param lineIntersectionTangents
|
|
604
|
+
* @returns
|
|
605
|
+
*/
|
|
606
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vector> {
|
|
607
|
+
return this.bezierCurves.reduce((accu: Array<Vector>, curCurve: CubicBezierCurve) => {
|
|
608
|
+
return accu.concat(curCurve.lineIntersectionTangents(line, inVectorBoundsOnly));
|
|
609
|
+
}, []);
|
|
610
|
+
}
|
|
611
|
+
//--- END --- Implement interface `Intersectable`
|
|
612
|
+
|
|
562
613
|
/**
|
|
563
614
|
* This is a helper function to locate the curve index for a given
|
|
564
615
|
* absolute path position u.
|
|
@@ -816,6 +867,7 @@ export class BezierPath implements SVGSerializable {
|
|
|
816
867
|
neighbourCurve.updateArcLengths();
|
|
817
868
|
}
|
|
818
869
|
|
|
870
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
819
871
|
/**
|
|
820
872
|
* Get the bounds of this Bézier path.
|
|
821
873
|
*
|
|
@@ -837,6 +889,7 @@ export class BezierPath implements SVGSerializable {
|
|
|
837
889
|
}
|
|
838
890
|
return new Bounds(min, max);
|
|
839
891
|
}
|
|
892
|
+
//--- END --- Implement interface `IBounded`
|
|
840
893
|
|
|
841
894
|
/**
|
|
842
895
|
* Get n 'equally' distributed vertices along this Bézier path.
|
package/src/ts/Bounds.ts
CHANGED
|
@@ -9,13 +9,16 @@
|
|
|
9
9
|
* @modified 2022-10-09 Added the `fromDimension` function.
|
|
10
10
|
* @modified 2022-11-28 Added the `clone` method.
|
|
11
11
|
* @modified 2023-09-29 Added the `randomPoint` method.
|
|
12
|
-
* @
|
|
12
|
+
* @modified 2025-03-23 Added the `getMinDimension` and `getMaxDimension` methods.
|
|
13
|
+
* @modified 2025-04-18 Change parameter type in `Bounds.computeFromVertices` from `Vertex` to more general `XYCoords`.
|
|
14
|
+
* @modified 2025-04-19 Added methods to `Bounds` class: `getNorthPoint`, `getSouthPoint`, `getEastPoint` and `getWestPoint`.
|
|
15
|
+
* @modified 2025-04-26 Added static method `Bounds.computeFromBoundsSet` to calculate containing bounds for a set of bounding boxes.
|
|
16
|
+
* @version 1.8.0
|
|
13
17
|
**/
|
|
14
18
|
|
|
15
19
|
import { Polygon } from "./Polygon";
|
|
16
20
|
import { XYCoords, IBounds, XYDimension } from "./interfaces";
|
|
17
21
|
import { Vertex } from "./Vertex";
|
|
18
|
-
import { VertTuple } from "./VertTuple";
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* @classdesc A bounds class with min and max values. Implementing IBounds.
|
|
@@ -72,6 +75,55 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
72
75
|
this.height = max.y - min.y;
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Get the center point of the north bound.
|
|
80
|
+
*
|
|
81
|
+
* @method getNorthPoint
|
|
82
|
+
* @instance
|
|
83
|
+
* @memberof Bounds
|
|
84
|
+
* @return {Vertex} The "northmost" centered point of this bounding box.
|
|
85
|
+
*/
|
|
86
|
+
getNorthPoint() : Vertex {
|
|
87
|
+
return new Vertex(this.min.x + this.width/2.0, this.min.y );
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the center point of the south bound.
|
|
92
|
+
*
|
|
93
|
+
* @method getNorthPoint
|
|
94
|
+
* @instance
|
|
95
|
+
* @memberof Bounds
|
|
96
|
+
* @return {Vertex} The "southhmost" centered point of this bounding box.
|
|
97
|
+
*/
|
|
98
|
+
getSouthPoint() : Vertex {
|
|
99
|
+
return new Vertex( this.min.x + this.width/2.0, this.max.y );
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get the center point of the west bound.
|
|
104
|
+
*
|
|
105
|
+
* @method getWestPoint
|
|
106
|
+
* @instance
|
|
107
|
+
* @memberof Bounds
|
|
108
|
+
* @return {Vertex} The "westhmost" centered point of this bounding box.
|
|
109
|
+
*/
|
|
110
|
+
getWestPoint() : Vertex {
|
|
111
|
+
return new Vertex( this.min.x, this.min.y + this.height/2.0 );
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get the center point of the east bound.
|
|
116
|
+
*
|
|
117
|
+
* @method getEastPoint
|
|
118
|
+
* @instance
|
|
119
|
+
* @memberof Bounds
|
|
120
|
+
* @return {Vertex} The "easthmost" centered point of this bounding box.
|
|
121
|
+
*/
|
|
122
|
+
getEastPoint() : Vertex {
|
|
123
|
+
return new Vertex( this.max.x, this.min.y + this.height/2.0 );
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
|
|
75
127
|
/**
|
|
76
128
|
* Convert this rectangular bounding box to a polygon with four vertices.
|
|
77
129
|
*
|
|
@@ -99,6 +151,24 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
99
151
|
return new Vertex(this.min.x + (this.max.x - this.min.x) / 2.0, this.min.y + (this.max.y - this.min.y) / 2);
|
|
100
152
|
}
|
|
101
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Get the minimum of `width` and `height`.
|
|
156
|
+
*
|
|
157
|
+
* @returns {number} The value of Math.min( this.width, this.height )
|
|
158
|
+
*/
|
|
159
|
+
getMinDimension(): number {
|
|
160
|
+
return Math.min(this.width, this.height);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Get the minimum of `width` and `height`.
|
|
165
|
+
*
|
|
166
|
+
* @returns {number} The value of Math.min( this.width, this.height )
|
|
167
|
+
*/
|
|
168
|
+
getMaxDimension(): number {
|
|
169
|
+
return Math.max(this.width, this.height);
|
|
170
|
+
}
|
|
171
|
+
|
|
102
172
|
/**
|
|
103
173
|
* Generate a random point inside this bounds object. Safe areas at the border to avoid
|
|
104
174
|
* included.
|
|
@@ -156,18 +226,20 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
156
226
|
* @static
|
|
157
227
|
* @method computeFromVertices
|
|
158
228
|
* @memberof Bounds
|
|
159
|
-
* @param {Array<
|
|
229
|
+
* @param {Array<XYCoords>} vertices - The set of vertices you want to get the bounding box for.
|
|
160
230
|
* @return The minimal Bounds for the given vertices.
|
|
161
231
|
**/
|
|
162
|
-
static computeFromVertices(vertices: Array<
|
|
163
|
-
if (vertices.length == 0)
|
|
232
|
+
static computeFromVertices(vertices: Array<XYCoords>): Bounds {
|
|
233
|
+
if (vertices.length == 0) {
|
|
234
|
+
return new Bounds(new Vertex(0, 0), new Vertex(0, 0));
|
|
235
|
+
}
|
|
164
236
|
|
|
165
237
|
let xMin = vertices[0].x;
|
|
166
238
|
let xMax = vertices[0].x;
|
|
167
239
|
let yMin = vertices[0].y;
|
|
168
240
|
let yMax = vertices[0].y;
|
|
169
241
|
|
|
170
|
-
let vert:
|
|
242
|
+
let vert: XYCoords;
|
|
171
243
|
for (var i in vertices) {
|
|
172
244
|
vert = vertices[i];
|
|
173
245
|
xMin = Math.min(xMin, vert.x);
|
|
@@ -178,6 +250,38 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
178
250
|
return new Bounds(new Vertex(xMin, yMin), new Vertex(xMax, yMax));
|
|
179
251
|
}
|
|
180
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Compute the minimal bounding box for a given set of existing bounding boxes.
|
|
255
|
+
*
|
|
256
|
+
* An empty vertex array will return an empty bounding box located at (0,0).
|
|
257
|
+
*
|
|
258
|
+
* @static
|
|
259
|
+
* @method computeFromBoundsSet
|
|
260
|
+
* @memberof Bounds
|
|
261
|
+
* @param {Array<IBounds>} boundingBoxes - The set of existing bounding boxes to get the containing bounding box for.
|
|
262
|
+
* @return The minimal Bounds for the given bounds instances.
|
|
263
|
+
**/
|
|
264
|
+
static computeFromBoundsSet(boundingBoxes:Array<IBounds>) : Bounds {
|
|
265
|
+
if (boundingBoxes.length == 0) {
|
|
266
|
+
return new Bounds(new Vertex(0, 0), new Vertex(0, 0));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
let xMin = boundingBoxes[0].min.x;
|
|
270
|
+
let xMax = boundingBoxes[0].max.x;
|
|
271
|
+
let yMin = boundingBoxes[0].min.y;
|
|
272
|
+
let yMax = boundingBoxes[0].min.y;
|
|
273
|
+
|
|
274
|
+
let bounds: IBounds;
|
|
275
|
+
for (var i in boundingBoxes) {
|
|
276
|
+
bounds = boundingBoxes[i];
|
|
277
|
+
xMin = Math.min(xMin, bounds.min.x);
|
|
278
|
+
xMax = Math.max(xMax, bounds.max.x);
|
|
279
|
+
yMin = Math.min(yMin, bounds.min.y);
|
|
280
|
+
yMax = Math.max(yMax, bounds.min.y);
|
|
281
|
+
}
|
|
282
|
+
return new Bounds(new Vertex(xMin, yMin), new Vertex(xMax, yMax));
|
|
283
|
+
}
|
|
284
|
+
|
|
181
285
|
/**
|
|
182
286
|
* Create a new `Bounds` instance just from `width` and `height`, located at (0,0) or the optionally given origin.
|
|
183
287
|
*
|
package/src/ts/Circle.ts
CHANGED
|
@@ -12,15 +12,18 @@
|
|
|
12
12
|
* @modified 2022-08-15 Added the `containsPoint` function.
|
|
13
13
|
* @modified 2022-08-23 Added the `lineIntersection` function.
|
|
14
14
|
* @modified 2022-08-23 Added the `closestPoint` function.
|
|
15
|
-
* @
|
|
15
|
+
* @modified 2025-04-09 Added the `Circle.move(amount: XYCoords)` method.
|
|
16
|
+
* @modified 2025-04-16 Class `Circle` now implements interface `Intersectable`.
|
|
17
|
+
* @version 1.5.0
|
|
16
18
|
**/
|
|
17
19
|
|
|
20
|
+
import { Bounds } from "./Bounds";
|
|
18
21
|
import { Line } from "./Line";
|
|
19
22
|
import { UIDGenerator } from "./UIDGenerator";
|
|
20
23
|
import { Vector } from "./Vector";
|
|
21
24
|
import { VertTuple } from "./VertTuple";
|
|
22
25
|
import { Vertex } from "./Vertex";
|
|
23
|
-
import { SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
26
|
+
import { IBounded, Intersectable, SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* @classdesc A simple circle: center point and radius.
|
|
@@ -33,7 +36,7 @@ import { SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
|
33
36
|
* @requires UID
|
|
34
37
|
* @requires UIDGenerator
|
|
35
38
|
**/
|
|
36
|
-
export class Circle implements SVGSerializable {
|
|
39
|
+
export class Circle implements IBounded, Intersectable, SVGSerializable {
|
|
37
40
|
/**
|
|
38
41
|
* Required to generate proper CSS classes and other class related IDs.
|
|
39
42
|
**/
|
|
@@ -85,6 +88,20 @@ export class Circle implements SVGSerializable {
|
|
|
85
88
|
this.radius = radius;
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Move the circle by the given amount.
|
|
93
|
+
*
|
|
94
|
+
* @method move
|
|
95
|
+
* @param {XYCoords} amount - The amount to move.
|
|
96
|
+
* @instance
|
|
97
|
+
* @memberof Circle
|
|
98
|
+
* @return {Circle} this for chaining
|
|
99
|
+
**/
|
|
100
|
+
move(amount: XYCoords): Circle {
|
|
101
|
+
this.center.add(amount);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
88
105
|
/**
|
|
89
106
|
* Check if the given circle is fully contained inside this circle.
|
|
90
107
|
*
|
|
@@ -159,8 +176,26 @@ export class Circle implements SVGSerializable {
|
|
|
159
176
|
const pointA: Vertex = Circle.circleUtils.vertAt(angle, this.radius);
|
|
160
177
|
// Construct the perpendicular of the line in point a. Then move relative to center.
|
|
161
178
|
return (new Vector(pointA, new Vertex(0, 0)).add(this.center) as Vector).perp() as Vector;
|
|
179
|
+
// return (new Vector(this.center.clone(), pointA).add(pointA) as Vector).perp() as Vector;
|
|
162
180
|
}
|
|
163
181
|
|
|
182
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
183
|
+
/**
|
|
184
|
+
* Get the bounding box (bounds) of this Circle.
|
|
185
|
+
*
|
|
186
|
+
* @method getBounds
|
|
187
|
+
* @instance
|
|
188
|
+
* @memberof Circle
|
|
189
|
+
* @return {Bounds} The rectangular bounds of this Circle.
|
|
190
|
+
**/
|
|
191
|
+
getBounds(): Bounds {
|
|
192
|
+
return new Bounds(
|
|
193
|
+
this.center.clone().subXY(Math.abs(this.radius), Math.abs(this.radius)),
|
|
194
|
+
this.center.clone().addXY(Math.abs(this.radius), Math.abs(this.radius))
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
//--- END --- Implement interface `Intersectable`
|
|
198
|
+
|
|
164
199
|
/**
|
|
165
200
|
* Calculate the intersection points (if exists) with the given circle.
|
|
166
201
|
*
|
|
@@ -221,7 +256,7 @@ export class Circle implements SVGSerializable {
|
|
|
221
256
|
* @instance
|
|
222
257
|
* @memberof Circle
|
|
223
258
|
* @param {Vertex} a- The first of the two points defining the line.
|
|
224
|
-
* @param {
|
|
259
|
+
* @param {XYCoords} b - The second of the two points defining the line.
|
|
225
260
|
* @return {Line|null} The intersection points (as a line) or null if this circle does not intersect the line given.
|
|
226
261
|
**/
|
|
227
262
|
lineIntersection(a: Vertex, b: XYCoords): Line | null {
|
|
@@ -262,9 +297,56 @@ export class Circle implements SVGSerializable {
|
|
|
262
297
|
interB.y = (-det * diff.x - Math.abs(diff.y) * sqrt) / distSquared;
|
|
263
298
|
|
|
264
299
|
return new Line(interA.add(this.center), interB.add(this.center));
|
|
265
|
-
// return new Line(interA, interB);
|
|
266
300
|
}
|
|
267
301
|
|
|
302
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
303
|
+
/**
|
|
304
|
+
* Get all line intersections with this circle.
|
|
305
|
+
*
|
|
306
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
307
|
+
*
|
|
308
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
309
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
310
|
+
* @returns {Array<Vertex>} - An array of all intersections with the circle outline.
|
|
311
|
+
*/
|
|
312
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vertex> {
|
|
313
|
+
// Find the intersections of all lines inside the edge bounds
|
|
314
|
+
const intersectioLine: Line | null = this.lineIntersection(line.a, line.b);
|
|
315
|
+
if (!intersectioLine) {
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
if (inVectorBoundsOnly) {
|
|
319
|
+
// const maxDist = line.length();
|
|
320
|
+
return [intersectioLine.a, intersectioLine.b].filter((vert: Vertex) => line.hasPoint(vert, true));
|
|
321
|
+
} else {
|
|
322
|
+
return [intersectioLine.a, intersectioLine.b];
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
328
|
+
*
|
|
329
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
330
|
+
*
|
|
331
|
+
* @param line
|
|
332
|
+
* @param lineIntersectionTangents
|
|
333
|
+
* @returns
|
|
334
|
+
*/
|
|
335
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vector> {
|
|
336
|
+
// Find the intersections of all lines plus their tangents inside the circle bounds
|
|
337
|
+
const interSectionPoints: Array<Vertex> = this.lineIntersections(line, inVectorBoundsOnly);
|
|
338
|
+
return interSectionPoints.map((vert: Vertex) => {
|
|
339
|
+
// Calculate angle
|
|
340
|
+
const lineFromCenter = new Line(this.center, vert);
|
|
341
|
+
const angle: number = lineFromCenter.angle();
|
|
342
|
+
// console.log("angle", (angle / Math.PI) * 180.0);
|
|
343
|
+
// const angle = Math.random() * Math.PI * 2; // TODO
|
|
344
|
+
// Calculate tangent at angle
|
|
345
|
+
return this.tangentAt(angle);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
//--- END --- Implement interface `Intersectable`
|
|
349
|
+
|
|
268
350
|
/**
|
|
269
351
|
* Calculate the closest point on the outline of this circle to the given point.
|
|
270
352
|
*
|
package/src/ts/CircleSector.ts
CHANGED
|
@@ -8,14 +8,22 @@
|
|
|
8
8
|
* @modified 2024-03-08 Added the `containsAngle` method.
|
|
9
9
|
* @modified 2024-03-09 Added the `circleSectorIntersection` method to find coherent sector intersections..
|
|
10
10
|
* @modified 2024-03-09 Added the `angleAt` method to determine any angle at some ratio.
|
|
11
|
+
* @modified 2025-04-02 Adding the `CircleSector.lineIntersections` and `CircleSector.lineIntersectionTangents` and implementing `Intersectable`.
|
|
12
|
+
* @modified 2025-04-09 Adding the `CircleSector.move()` method.
|
|
13
|
+
* @modified 2025-04-19 Tweaking the `CircleSector.containsAngle` method: all values (input angle, start- and end- angle) are wrapped into [0,2*PI) now.
|
|
14
|
+
* @modified 2025-04-19 Class `CircleSector` implements interface `Bounded` now (method `getBounds` added).
|
|
11
15
|
* @version 1.2.0
|
|
12
16
|
**/
|
|
13
17
|
|
|
18
|
+
import { Bounds } from "./Bounds";
|
|
14
19
|
import { Circle } from "./Circle";
|
|
15
20
|
import { Line } from "./Line";
|
|
16
21
|
import { UIDGenerator } from "./UIDGenerator";
|
|
22
|
+
import { Vector } from "./Vector";
|
|
23
|
+
import { VertTuple } from "./VertTuple";
|
|
17
24
|
import { Vertex } from "./Vertex";
|
|
18
|
-
import {
|
|
25
|
+
import { geomutils } from "./geomutils";
|
|
26
|
+
import { IBounded, Intersectable, SVGPathParams, SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
19
27
|
|
|
20
28
|
/**
|
|
21
29
|
* @classdesc A simple circle sector: circle, start- and end-angle.
|
|
@@ -26,7 +34,7 @@ import { PathSegment, SVGPathParams, SVGSerializable, UID, XYCoords } from "./in
|
|
|
26
34
|
* @requires UIDGenerator
|
|
27
35
|
* @requires XYCoords
|
|
28
36
|
**/
|
|
29
|
-
export class CircleSector implements SVGSerializable {
|
|
37
|
+
export class CircleSector implements IBounded, Intersectable, SVGSerializable {
|
|
30
38
|
/**
|
|
31
39
|
* Required to generate proper CSS classes and other class related IDs.
|
|
32
40
|
**/
|
|
@@ -87,6 +95,52 @@ export class CircleSector implements SVGSerializable {
|
|
|
87
95
|
this.endAngle = endAngle;
|
|
88
96
|
}
|
|
89
97
|
|
|
98
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
99
|
+
/**
|
|
100
|
+
* Get the bounds of this ellipse.
|
|
101
|
+
*
|
|
102
|
+
* The bounds are approximated by the underlying segment buffer; the more segment there are,
|
|
103
|
+
* the more accurate will be the returned bounds.
|
|
104
|
+
*
|
|
105
|
+
* @method getBounds
|
|
106
|
+
* @instance
|
|
107
|
+
* @memberof VEllipse
|
|
108
|
+
* @return {Bounds} The bounds of this curve.
|
|
109
|
+
**/
|
|
110
|
+
getBounds(): Bounds {
|
|
111
|
+
const _self = this;
|
|
112
|
+
const circleBounds : Bounds = this.circle.getBounds();
|
|
113
|
+
// Calculage angles from east, west, north and south box points and check if they are inside
|
|
114
|
+
const candidates : Array<Vertex> = [
|
|
115
|
+
circleBounds.getNorthPoint(),
|
|
116
|
+
circleBounds.getSouthPoint(),
|
|
117
|
+
circleBounds.getWestPoint(),
|
|
118
|
+
circleBounds.getEastPoint()
|
|
119
|
+
].filter( (point : Vertex) => {
|
|
120
|
+
// Check for each candidate points if they are contained in this sector. Drop if not.
|
|
121
|
+
const angle : number = new Line(_self.circle.center, point).angle();
|
|
122
|
+
return _self.containsAngle(angle);
|
|
123
|
+
});
|
|
124
|
+
// Compute bounds and inlcude start end end point (they are definitely part of the bounds)
|
|
125
|
+
return Bounds.computeFromVertices(candidates.concat([this.getStartPoint(), this.getEndPoint()]));
|
|
126
|
+
}
|
|
127
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Move the circle sector by the given amount.
|
|
132
|
+
*
|
|
133
|
+
* @method move
|
|
134
|
+
* @param {XYCoords} amount - The amount to move.
|
|
135
|
+
* @instance
|
|
136
|
+
* @memberof CircleSector
|
|
137
|
+
* @return {CircleSector} this for chaining
|
|
138
|
+
**/
|
|
139
|
+
move(amount: XYCoords): CircleSector {
|
|
140
|
+
this.circle.move(amount);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
|
|
90
144
|
/**
|
|
91
145
|
* Checks wether the given angle (must be inside 0 and PI*2) is contained inside this sector.
|
|
92
146
|
*
|
|
@@ -97,11 +151,21 @@ export class CircleSector implements SVGSerializable {
|
|
|
97
151
|
* @return {boolean} True if (and only if) this sector contains the given angle.
|
|
98
152
|
*/
|
|
99
153
|
containsAngle(angle: number) {
|
|
100
|
-
|
|
101
|
-
|
|
154
|
+
var wrappedAngle = geomutils.mapAngleTo2PI(angle);
|
|
155
|
+
var wrappedStart = geomutils.mapAngleTo2PI(this.startAngle);
|
|
156
|
+
var wrappedEnd = geomutils.mapAngleTo2PI(this.endAngle);
|
|
157
|
+
// TODO: cleanup
|
|
158
|
+
// if (this.startAngle <= this.endAngle) {
|
|
159
|
+
// return angle >= this.startAngle && angle < this.endAngle;
|
|
160
|
+
// } else {
|
|
161
|
+
// // startAngle > endAngle
|
|
162
|
+
// return angle >= this.startAngle || angle < this.endAngle;
|
|
163
|
+
// }
|
|
164
|
+
if (wrappedStart <= wrappedEnd) {
|
|
165
|
+
return wrappedAngle >= wrappedStart && wrappedAngle < wrappedEnd;
|
|
102
166
|
} else {
|
|
103
167
|
// startAngle > endAngle
|
|
104
|
-
return
|
|
168
|
+
return wrappedAngle >= wrappedStart || wrappedAngle < wrappedEnd;
|
|
105
169
|
}
|
|
106
170
|
}
|
|
107
171
|
|
|
@@ -206,6 +270,52 @@ export class CircleSector implements SVGSerializable {
|
|
|
206
270
|
return resultSector;
|
|
207
271
|
}
|
|
208
272
|
|
|
273
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
274
|
+
/**
|
|
275
|
+
* Get the line intersections as vectors with this ellipse.
|
|
276
|
+
*
|
|
277
|
+
* @method lineIntersections
|
|
278
|
+
* @instance
|
|
279
|
+
* @param {VertTuple<Vector> ray - The line/ray to intersect this ellipse with.
|
|
280
|
+
* @param {boolean} inVectorBoundsOnly - (default=false) Set to true if only intersections within the vector bounds are of interest.
|
|
281
|
+
* @returns
|
|
282
|
+
*/
|
|
283
|
+
lineIntersections(ray: VertTuple<Vector>, inVectorBoundsOnly: boolean = false): Array<Vertex> {
|
|
284
|
+
// First get all line intersections from underlying ellipse.
|
|
285
|
+
const ellipseIntersections: Array<Vertex> = this.circle.lineIntersections(ray, inVectorBoundsOnly);
|
|
286
|
+
// Drop all intersection points that are not contained in the circle sectors bounds.
|
|
287
|
+
const tmpLine = new Line(this.circle.center, new Vertex());
|
|
288
|
+
return ellipseIntersections.filter((intersectionPoint: Vertex) => {
|
|
289
|
+
tmpLine.b.set(intersectionPoint);
|
|
290
|
+
const lineAngle = tmpLine.angle();
|
|
291
|
+
return this.containsAngle(geomutils.wrapMinMax(lineAngle, 0, Math.PI * 2));
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
297
|
+
*
|
|
298
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
299
|
+
*
|
|
300
|
+
* @param line
|
|
301
|
+
* @param lineIntersectionTangents
|
|
302
|
+
* @returns
|
|
303
|
+
*/
|
|
304
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vector> {
|
|
305
|
+
// Find the intersections of all lines plus their tangents inside the circle bounds
|
|
306
|
+
const interSectionPoints: Array<Vertex> = this.lineIntersections(line, inVectorBoundsOnly);
|
|
307
|
+
return interSectionPoints.map((vert: Vertex) => {
|
|
308
|
+
// Calculate angle
|
|
309
|
+
const lineFromCenter = new Line(this.circle.center, vert);
|
|
310
|
+
const angle: number = lineFromCenter.angle();
|
|
311
|
+
// console.log("angle", (angle / Math.PI) * 180.0);
|
|
312
|
+
// const angle = Math.random() * Math.PI * 2; // TODO
|
|
313
|
+
// Calculate tangent at angle
|
|
314
|
+
return this.circle.tangentAt(angle);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
//--- END --- Implement interface `Intersectable`
|
|
318
|
+
|
|
209
319
|
/**
|
|
210
320
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
211
321
|
* After calling this function the object might not hold valid data any more and
|