plotboilerplate 1.23.3 → 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 +1390 -265
- 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 +1264 -99
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- 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.js +2 -9
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +48 -4
- package/src/cjs/Polygon.js +91 -16
- 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 +17 -2
- package/src/cjs/Vertex.js +18 -1
- package/src/cjs/Vertex.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/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/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.js +2 -9
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +48 -4
- package/src/esm/Polygon.js +89 -16
- 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 +17 -2
- package/src/esm/Vertex.js +18 -1
- package/src/esm/Vertex.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/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/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 +3 -9
- package/src/ts/Polygon.ts +103 -22
- 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 +20 -2
- package/src/ts/interfaces/core.ts +42 -0
- package/src/ts/utils/algorithms/convexPolygonIncircle.ts +82 -78
- package/src/ts/utils/createRandomizedPolygon.ts +31 -0
- 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
package/src/esm/Bounds.js
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
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
|
import { Polygon } from "./Polygon";
|
|
15
19
|
import { Vertex } from "./Vertex";
|
|
@@ -35,6 +39,54 @@ export class Bounds {
|
|
|
35
39
|
this.width = max.x - min.x;
|
|
36
40
|
this.height = max.y - min.y;
|
|
37
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the center point of the north bound.
|
|
44
|
+
*
|
|
45
|
+
* @method getNorthPoint
|
|
46
|
+
* @instance
|
|
47
|
+
* @memberof Bounds
|
|
48
|
+
* @return {Vertex} The "northmost" centered point of this bounding box.
|
|
49
|
+
*/
|
|
50
|
+
getNorthPoint() {
|
|
51
|
+
return new Vertex(this.min.x + this.width / 2.0, this.min.y);
|
|
52
|
+
}
|
|
53
|
+
;
|
|
54
|
+
/**
|
|
55
|
+
* Get the center point of the south bound.
|
|
56
|
+
*
|
|
57
|
+
* @method getNorthPoint
|
|
58
|
+
* @instance
|
|
59
|
+
* @memberof Bounds
|
|
60
|
+
* @return {Vertex} The "southhmost" centered point of this bounding box.
|
|
61
|
+
*/
|
|
62
|
+
getSouthPoint() {
|
|
63
|
+
return new Vertex(this.min.x + this.width / 2.0, this.max.y);
|
|
64
|
+
}
|
|
65
|
+
;
|
|
66
|
+
/**
|
|
67
|
+
* Get the center point of the west bound.
|
|
68
|
+
*
|
|
69
|
+
* @method getWestPoint
|
|
70
|
+
* @instance
|
|
71
|
+
* @memberof Bounds
|
|
72
|
+
* @return {Vertex} The "westhmost" centered point of this bounding box.
|
|
73
|
+
*/
|
|
74
|
+
getWestPoint() {
|
|
75
|
+
return new Vertex(this.min.x, this.min.y + this.height / 2.0);
|
|
76
|
+
}
|
|
77
|
+
;
|
|
78
|
+
/**
|
|
79
|
+
* Get the center point of the east bound.
|
|
80
|
+
*
|
|
81
|
+
* @method getEastPoint
|
|
82
|
+
* @instance
|
|
83
|
+
* @memberof Bounds
|
|
84
|
+
* @return {Vertex} The "easthmost" centered point of this bounding box.
|
|
85
|
+
*/
|
|
86
|
+
getEastPoint() {
|
|
87
|
+
return new Vertex(this.max.x, this.min.y + this.height / 2.0);
|
|
88
|
+
}
|
|
89
|
+
;
|
|
38
90
|
/**
|
|
39
91
|
* Convert this rectangular bounding box to a polygon with four vertices.
|
|
40
92
|
*
|
|
@@ -57,6 +109,22 @@ export class Bounds {
|
|
|
57
109
|
getCenter() {
|
|
58
110
|
return new Vertex(this.min.x + (this.max.x - this.min.x) / 2.0, this.min.y + (this.max.y - this.min.y) / 2);
|
|
59
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the minimum of `width` and `height`.
|
|
114
|
+
*
|
|
115
|
+
* @returns {number} The value of Math.min( this.width, this.height )
|
|
116
|
+
*/
|
|
117
|
+
getMinDimension() {
|
|
118
|
+
return Math.min(this.width, this.height);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the minimum of `width` and `height`.
|
|
122
|
+
*
|
|
123
|
+
* @returns {number} The value of Math.min( this.width, this.height )
|
|
124
|
+
*/
|
|
125
|
+
getMaxDimension() {
|
|
126
|
+
return Math.max(this.width, this.height);
|
|
127
|
+
}
|
|
60
128
|
/**
|
|
61
129
|
* Generate a random point inside this bounds object. Safe areas at the border to avoid
|
|
62
130
|
* included.
|
|
@@ -107,12 +175,13 @@ export class Bounds {
|
|
|
107
175
|
* @static
|
|
108
176
|
* @method computeFromVertices
|
|
109
177
|
* @memberof Bounds
|
|
110
|
-
* @param {Array<
|
|
178
|
+
* @param {Array<XYCoords>} vertices - The set of vertices you want to get the bounding box for.
|
|
111
179
|
* @return The minimal Bounds for the given vertices.
|
|
112
180
|
**/
|
|
113
181
|
static computeFromVertices(vertices) {
|
|
114
|
-
if (vertices.length == 0)
|
|
182
|
+
if (vertices.length == 0) {
|
|
115
183
|
return new Bounds(new Vertex(0, 0), new Vertex(0, 0));
|
|
184
|
+
}
|
|
116
185
|
let xMin = vertices[0].x;
|
|
117
186
|
let xMax = vertices[0].x;
|
|
118
187
|
let yMin = vertices[0].y;
|
|
@@ -127,6 +196,35 @@ export class Bounds {
|
|
|
127
196
|
}
|
|
128
197
|
return new Bounds(new Vertex(xMin, yMin), new Vertex(xMax, yMax));
|
|
129
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Compute the minimal bounding box for a given set of existing bounding boxes.
|
|
201
|
+
*
|
|
202
|
+
* An empty vertex array will return an empty bounding box located at (0,0).
|
|
203
|
+
*
|
|
204
|
+
* @static
|
|
205
|
+
* @method computeFromBoundsSet
|
|
206
|
+
* @memberof Bounds
|
|
207
|
+
* @param {Array<IBounds>} boundingBoxes - The set of existing bounding boxes to get the containing bounding box for.
|
|
208
|
+
* @return The minimal Bounds for the given bounds instances.
|
|
209
|
+
**/
|
|
210
|
+
static computeFromBoundsSet(boundingBoxes) {
|
|
211
|
+
if (boundingBoxes.length == 0) {
|
|
212
|
+
return new Bounds(new Vertex(0, 0), new Vertex(0, 0));
|
|
213
|
+
}
|
|
214
|
+
let xMin = boundingBoxes[0].min.x;
|
|
215
|
+
let xMax = boundingBoxes[0].max.x;
|
|
216
|
+
let yMin = boundingBoxes[0].min.y;
|
|
217
|
+
let yMax = boundingBoxes[0].min.y;
|
|
218
|
+
let bounds;
|
|
219
|
+
for (var i in boundingBoxes) {
|
|
220
|
+
bounds = boundingBoxes[i];
|
|
221
|
+
xMin = Math.min(xMin, bounds.min.x);
|
|
222
|
+
xMax = Math.max(xMax, bounds.max.x);
|
|
223
|
+
yMin = Math.min(yMin, bounds.min.y);
|
|
224
|
+
yMax = Math.max(yMax, bounds.min.y);
|
|
225
|
+
}
|
|
226
|
+
return new Bounds(new Vertex(xMin, yMin), new Vertex(xMax, yMax));
|
|
227
|
+
}
|
|
130
228
|
/**
|
|
131
229
|
* Create a new `Bounds` instance just from `width` and `height`, located at (0,0) or the optionally given origin.
|
|
132
230
|
*
|
package/src/esm/Bounds.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bounds.js","sourceRoot":"","sources":["../ts/Bounds.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Bounds.js","sourceRoot":"","sources":["../ts/Bounds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;IAgBI;AAEJ,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;IAMI;AACJ,MAAM,OAAO,MAAM;IAiCjB;;;;;;;QAOI;IACJ,YAAY,GAAa,EAAE,GAAa;QACtC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAC9B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GAAG,CAAC,CAAC,CAAC,CAAC;YACpC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACpC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACpC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,aAAa,CAAC,KAAa,EAAE,MAAc,EAAE,MAAiB;QACnE,OAAO,IAAI,MAAM,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC;IAC3H,CAAC;CACF,CAAC,mBAAmB"}
|
package/src/esm/Circle.d.ts
CHANGED
|
@@ -12,13 +12,16 @@
|
|
|
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
|
**/
|
|
19
|
+
import { Bounds } from "./Bounds";
|
|
17
20
|
import { Line } from "./Line";
|
|
18
21
|
import { Vector } from "./Vector";
|
|
19
22
|
import { VertTuple } from "./VertTuple";
|
|
20
23
|
import { Vertex } from "./Vertex";
|
|
21
|
-
import { SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
24
|
+
import { IBounded, Intersectable, SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
22
25
|
/**
|
|
23
26
|
* @classdesc A simple circle: center point and radius.
|
|
24
27
|
*
|
|
@@ -30,7 +33,7 @@ import { SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
|
30
33
|
* @requires UID
|
|
31
34
|
* @requires UIDGenerator
|
|
32
35
|
**/
|
|
33
|
-
export declare class Circle implements SVGSerializable {
|
|
36
|
+
export declare class Circle implements IBounded, Intersectable, SVGSerializable {
|
|
34
37
|
/**
|
|
35
38
|
* Required to generate proper CSS classes and other class related IDs.
|
|
36
39
|
**/
|
|
@@ -72,6 +75,16 @@ export declare class Circle implements SVGSerializable {
|
|
|
72
75
|
* @param {number} radius - The radius of the circle.
|
|
73
76
|
*/
|
|
74
77
|
constructor(center: Vertex, radius: number);
|
|
78
|
+
/**
|
|
79
|
+
* Move the circle by the given amount.
|
|
80
|
+
*
|
|
81
|
+
* @method move
|
|
82
|
+
* @param {XYCoords} amount - The amount to move.
|
|
83
|
+
* @instance
|
|
84
|
+
* @memberof Circle
|
|
85
|
+
* @return {Circle} this for chaining
|
|
86
|
+
**/
|
|
87
|
+
move(amount: XYCoords): Circle;
|
|
75
88
|
/**
|
|
76
89
|
* Check if the given circle is fully contained inside this circle.
|
|
77
90
|
*
|
|
@@ -129,6 +142,15 @@ export declare class Circle implements SVGSerializable {
|
|
|
129
142
|
* @memberof Circle
|
|
130
143
|
**/
|
|
131
144
|
tangentAt(angle: number): Vector;
|
|
145
|
+
/**
|
|
146
|
+
* Get the bounding box (bounds) of this Circle.
|
|
147
|
+
*
|
|
148
|
+
* @method getBounds
|
|
149
|
+
* @instance
|
|
150
|
+
* @memberof Circle
|
|
151
|
+
* @return {Bounds} The rectangular bounds of this Circle.
|
|
152
|
+
**/
|
|
153
|
+
getBounds(): Bounds;
|
|
132
154
|
/**
|
|
133
155
|
* Calculate the intersection points (if exists) with the given circle.
|
|
134
156
|
*
|
|
@@ -146,10 +168,30 @@ export declare class Circle implements SVGSerializable {
|
|
|
146
168
|
* @instance
|
|
147
169
|
* @memberof Circle
|
|
148
170
|
* @param {Vertex} a- The first of the two points defining the line.
|
|
149
|
-
* @param {
|
|
171
|
+
* @param {XYCoords} b - The second of the two points defining the line.
|
|
150
172
|
* @return {Line|null} The intersection points (as a line) or null if this circle does not intersect the line given.
|
|
151
173
|
**/
|
|
152
174
|
lineIntersection(a: Vertex, b: XYCoords): Line | null;
|
|
175
|
+
/**
|
|
176
|
+
* Get all line intersections with this circle.
|
|
177
|
+
*
|
|
178
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
179
|
+
*
|
|
180
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
181
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
182
|
+
* @returns {Array<Vertex>} - An array of all intersections with the circle outline.
|
|
183
|
+
*/
|
|
184
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vertex>;
|
|
185
|
+
/**
|
|
186
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
187
|
+
*
|
|
188
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
189
|
+
*
|
|
190
|
+
* @param line
|
|
191
|
+
* @param lineIntersectionTangents
|
|
192
|
+
* @returns
|
|
193
|
+
*/
|
|
194
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vector>;
|
|
153
195
|
/**
|
|
154
196
|
* Calculate the closest point on the outline of this circle to the given point.
|
|
155
197
|
*
|
package/src/esm/Circle.js
CHANGED
|
@@ -12,8 +12,11 @@
|
|
|
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
|
**/
|
|
19
|
+
import { Bounds } from "./Bounds";
|
|
17
20
|
import { Line } from "./Line";
|
|
18
21
|
import { UIDGenerator } from "./UIDGenerator";
|
|
19
22
|
import { Vector } from "./Vector";
|
|
@@ -47,6 +50,19 @@ export class Circle {
|
|
|
47
50
|
this.center = center;
|
|
48
51
|
this.radius = radius;
|
|
49
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Move the circle by the given amount.
|
|
55
|
+
*
|
|
56
|
+
* @method move
|
|
57
|
+
* @param {XYCoords} amount - The amount to move.
|
|
58
|
+
* @instance
|
|
59
|
+
* @memberof Circle
|
|
60
|
+
* @return {Circle} this for chaining
|
|
61
|
+
**/
|
|
62
|
+
move(amount) {
|
|
63
|
+
this.center.add(amount);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
50
66
|
/**
|
|
51
67
|
* Check if the given circle is fully contained inside this circle.
|
|
52
68
|
*
|
|
@@ -117,7 +133,21 @@ export class Circle {
|
|
|
117
133
|
const pointA = Circle.circleUtils.vertAt(angle, this.radius);
|
|
118
134
|
// Construct the perpendicular of the line in point a. Then move relative to center.
|
|
119
135
|
return new Vector(pointA, new Vertex(0, 0)).add(this.center).perp();
|
|
136
|
+
// return (new Vector(this.center.clone(), pointA).add(pointA) as Vector).perp() as Vector;
|
|
120
137
|
}
|
|
138
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
139
|
+
/**
|
|
140
|
+
* Get the bounding box (bounds) of this Circle.
|
|
141
|
+
*
|
|
142
|
+
* @method getBounds
|
|
143
|
+
* @instance
|
|
144
|
+
* @memberof Circle
|
|
145
|
+
* @return {Bounds} The rectangular bounds of this Circle.
|
|
146
|
+
**/
|
|
147
|
+
getBounds() {
|
|
148
|
+
return new Bounds(this.center.clone().subXY(Math.abs(this.radius), Math.abs(this.radius)), this.center.clone().addXY(Math.abs(this.radius), Math.abs(this.radius)));
|
|
149
|
+
}
|
|
150
|
+
//--- END --- Implement interface `Intersectable`
|
|
121
151
|
/**
|
|
122
152
|
* Calculate the intersection points (if exists) with the given circle.
|
|
123
153
|
*
|
|
@@ -177,7 +207,7 @@ export class Circle {
|
|
|
177
207
|
* @instance
|
|
178
208
|
* @memberof Circle
|
|
179
209
|
* @param {Vertex} a- The first of the two points defining the line.
|
|
180
|
-
* @param {
|
|
210
|
+
* @param {XYCoords} b - The second of the two points defining the line.
|
|
181
211
|
* @return {Line|null} The intersection points (as a line) or null if this circle does not intersect the line given.
|
|
182
212
|
**/
|
|
183
213
|
lineIntersection(a, b) {
|
|
@@ -210,8 +240,54 @@ export class Circle {
|
|
|
210
240
|
interA.y = (-det * diff.x + Math.abs(diff.y) * sqrt) / distSquared;
|
|
211
241
|
interB.y = (-det * diff.x - Math.abs(diff.y) * sqrt) / distSquared;
|
|
212
242
|
return new Line(interA.add(this.center), interB.add(this.center));
|
|
213
|
-
// return new Line(interA, interB);
|
|
214
243
|
}
|
|
244
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
245
|
+
/**
|
|
246
|
+
* Get all line intersections with this circle.
|
|
247
|
+
*
|
|
248
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
249
|
+
*
|
|
250
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
251
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
252
|
+
* @returns {Array<Vertex>} - An array of all intersections with the circle outline.
|
|
253
|
+
*/
|
|
254
|
+
lineIntersections(line, inVectorBoundsOnly = false) {
|
|
255
|
+
// Find the intersections of all lines inside the edge bounds
|
|
256
|
+
const intersectioLine = this.lineIntersection(line.a, line.b);
|
|
257
|
+
if (!intersectioLine) {
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
260
|
+
if (inVectorBoundsOnly) {
|
|
261
|
+
// const maxDist = line.length();
|
|
262
|
+
return [intersectioLine.a, intersectioLine.b].filter((vert) => line.hasPoint(vert, true));
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
return [intersectioLine.a, intersectioLine.b];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
270
|
+
*
|
|
271
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
272
|
+
*
|
|
273
|
+
* @param line
|
|
274
|
+
* @param lineIntersectionTangents
|
|
275
|
+
* @returns
|
|
276
|
+
*/
|
|
277
|
+
lineIntersectionTangents(line, inVectorBoundsOnly = false) {
|
|
278
|
+
// Find the intersections of all lines plus their tangents inside the circle bounds
|
|
279
|
+
const interSectionPoints = this.lineIntersections(line, inVectorBoundsOnly);
|
|
280
|
+
return interSectionPoints.map((vert) => {
|
|
281
|
+
// Calculate angle
|
|
282
|
+
const lineFromCenter = new Line(this.center, vert);
|
|
283
|
+
const angle = lineFromCenter.angle();
|
|
284
|
+
// console.log("angle", (angle / Math.PI) * 180.0);
|
|
285
|
+
// const angle = Math.random() * Math.PI * 2; // TODO
|
|
286
|
+
// Calculate tangent at angle
|
|
287
|
+
return this.tangentAt(angle);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
//--- END --- Implement interface `Intersectable`
|
|
215
291
|
/**
|
|
216
292
|
* Calculate the closest point on the outline of this circle to the given point.
|
|
217
293
|
*
|
package/src/esm/Circle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Circle.js","sourceRoot":"","sources":["../ts/Circle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Circle.js","sourceRoot":"","sources":["../ts/Circle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;IAiBI;AAEJ,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC;;;;;;;;;;IAUI;AACJ,MAAM,OAAO,MAAM;IAsCjB;;;;;;;OAOG;IACH,YAAY,MAAc,EAAE,MAAc;QA7C1C;;YAEI;QACK,cAAS,GAAW,QAAQ,CAAC;QA2CpC,IAAI,CAAC,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;QAQI;IACJ,IAAI,CAAC,MAAgB;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACH,aAAa,CAAC,KAAe;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IACnD,CAAC;IAED;;;;;;;;OAQG;IACH,cAAc,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3E,CAAC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,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC;IACxE,CAAC;CACF,AANiB,CAMhB"}
|
|
@@ -8,11 +8,18 @@
|
|
|
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
|
**/
|
|
17
|
+
import { Bounds } from "./Bounds";
|
|
13
18
|
import { Circle } from "./Circle";
|
|
19
|
+
import { Vector } from "./Vector";
|
|
20
|
+
import { VertTuple } from "./VertTuple";
|
|
14
21
|
import { Vertex } from "./Vertex";
|
|
15
|
-
import { SVGPathParams, SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
22
|
+
import { IBounded, Intersectable, SVGPathParams, SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
16
23
|
/**
|
|
17
24
|
* @classdesc A simple circle sector: circle, start- and end-angle.
|
|
18
25
|
*
|
|
@@ -22,7 +29,7 @@ import { SVGPathParams, SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
|
22
29
|
* @requires UIDGenerator
|
|
23
30
|
* @requires XYCoords
|
|
24
31
|
**/
|
|
25
|
-
export declare class CircleSector implements SVGSerializable {
|
|
32
|
+
export declare class CircleSector implements IBounded, Intersectable, SVGSerializable {
|
|
26
33
|
/**
|
|
27
34
|
* Required to generate proper CSS classes and other class related IDs.
|
|
28
35
|
**/
|
|
@@ -71,6 +78,28 @@ export declare class CircleSector implements SVGSerializable {
|
|
|
71
78
|
* @param {number} endAngle - The end angle of the sector.
|
|
72
79
|
*/
|
|
73
80
|
constructor(circle: Circle, startAngle: number, endAngle: number);
|
|
81
|
+
/**
|
|
82
|
+
* Get the bounds of this ellipse.
|
|
83
|
+
*
|
|
84
|
+
* The bounds are approximated by the underlying segment buffer; the more segment there are,
|
|
85
|
+
* the more accurate will be the returned bounds.
|
|
86
|
+
*
|
|
87
|
+
* @method getBounds
|
|
88
|
+
* @instance
|
|
89
|
+
* @memberof VEllipse
|
|
90
|
+
* @return {Bounds} The bounds of this curve.
|
|
91
|
+
**/
|
|
92
|
+
getBounds(): Bounds;
|
|
93
|
+
/**
|
|
94
|
+
* Move the circle sector by the given amount.
|
|
95
|
+
*
|
|
96
|
+
* @method move
|
|
97
|
+
* @param {XYCoords} amount - The amount to move.
|
|
98
|
+
* @instance
|
|
99
|
+
* @memberof CircleSector
|
|
100
|
+
* @return {CircleSector} this for chaining
|
|
101
|
+
**/
|
|
102
|
+
move(amount: XYCoords): CircleSector;
|
|
74
103
|
/**
|
|
75
104
|
* Checks wether the given angle (must be inside 0 and PI*2) is contained inside this sector.
|
|
76
105
|
*
|
|
@@ -123,6 +152,26 @@ export declare class CircleSector implements SVGSerializable {
|
|
|
123
152
|
* @return {CircleSector | null} The intersecion of both sectors or null if they don't intersect.
|
|
124
153
|
*/
|
|
125
154
|
circleSectorIntersection(sector: CircleSector): CircleSector | null;
|
|
155
|
+
/**
|
|
156
|
+
* Get the line intersections as vectors with this ellipse.
|
|
157
|
+
*
|
|
158
|
+
* @method lineIntersections
|
|
159
|
+
* @instance
|
|
160
|
+
* @param {VertTuple<Vector> ray - The line/ray to intersect this ellipse with.
|
|
161
|
+
* @param {boolean} inVectorBoundsOnly - (default=false) Set to true if only intersections within the vector bounds are of interest.
|
|
162
|
+
* @returns
|
|
163
|
+
*/
|
|
164
|
+
lineIntersections(ray: VertTuple<Vector>, inVectorBoundsOnly?: boolean): Array<Vertex>;
|
|
165
|
+
/**
|
|
166
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
167
|
+
*
|
|
168
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
169
|
+
*
|
|
170
|
+
* @param line
|
|
171
|
+
* @param lineIntersectionTangents
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vector>;
|
|
126
175
|
/**
|
|
127
176
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
128
177
|
* After calling this function the object might not hold valid data any more and
|
package/src/esm/CircleSector.js
CHANGED
|
@@ -8,10 +8,18 @@
|
|
|
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
|
**/
|
|
17
|
+
import { Bounds } from "./Bounds";
|
|
13
18
|
import { Circle } from "./Circle";
|
|
19
|
+
import { Line } from "./Line";
|
|
14
20
|
import { UIDGenerator } from "./UIDGenerator";
|
|
21
|
+
import { Vertex } from "./Vertex";
|
|
22
|
+
import { geomutils } from "./geomutils";
|
|
15
23
|
/**
|
|
16
24
|
* @classdesc A simple circle sector: circle, start- and end-angle.
|
|
17
25
|
*
|
|
@@ -41,6 +49,49 @@ export class CircleSector {
|
|
|
41
49
|
this.startAngle = startAngle;
|
|
42
50
|
this.endAngle = endAngle;
|
|
43
51
|
}
|
|
52
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
53
|
+
/**
|
|
54
|
+
* Get the bounds of this ellipse.
|
|
55
|
+
*
|
|
56
|
+
* The bounds are approximated by the underlying segment buffer; the more segment there are,
|
|
57
|
+
* the more accurate will be the returned bounds.
|
|
58
|
+
*
|
|
59
|
+
* @method getBounds
|
|
60
|
+
* @instance
|
|
61
|
+
* @memberof VEllipse
|
|
62
|
+
* @return {Bounds} The bounds of this curve.
|
|
63
|
+
**/
|
|
64
|
+
getBounds() {
|
|
65
|
+
const _self = this;
|
|
66
|
+
const circleBounds = this.circle.getBounds();
|
|
67
|
+
// Calculage angles from east, west, north and south box points and check if they are inside
|
|
68
|
+
const candidates = [
|
|
69
|
+
circleBounds.getNorthPoint(),
|
|
70
|
+
circleBounds.getSouthPoint(),
|
|
71
|
+
circleBounds.getWestPoint(),
|
|
72
|
+
circleBounds.getEastPoint()
|
|
73
|
+
].filter((point) => {
|
|
74
|
+
// Check for each candidate points if they are contained in this sector. Drop if not.
|
|
75
|
+
const angle = new Line(_self.circle.center, point).angle();
|
|
76
|
+
return _self.containsAngle(angle);
|
|
77
|
+
});
|
|
78
|
+
// Compute bounds and inlcude start end end point (they are definitely part of the bounds)
|
|
79
|
+
return Bounds.computeFromVertices(candidates.concat([this.getStartPoint(), this.getEndPoint()]));
|
|
80
|
+
}
|
|
81
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
82
|
+
/**
|
|
83
|
+
* Move the circle sector by the given amount.
|
|
84
|
+
*
|
|
85
|
+
* @method move
|
|
86
|
+
* @param {XYCoords} amount - The amount to move.
|
|
87
|
+
* @instance
|
|
88
|
+
* @memberof CircleSector
|
|
89
|
+
* @return {CircleSector} this for chaining
|
|
90
|
+
**/
|
|
91
|
+
move(amount) {
|
|
92
|
+
this.circle.move(amount);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
44
95
|
/**
|
|
45
96
|
* Checks wether the given angle (must be inside 0 and PI*2) is contained inside this sector.
|
|
46
97
|
*
|
|
@@ -51,12 +102,22 @@ export class CircleSector {
|
|
|
51
102
|
* @return {boolean} True if (and only if) this sector contains the given angle.
|
|
52
103
|
*/
|
|
53
104
|
containsAngle(angle) {
|
|
54
|
-
|
|
55
|
-
|
|
105
|
+
var wrappedAngle = geomutils.mapAngleTo2PI(angle);
|
|
106
|
+
var wrappedStart = geomutils.mapAngleTo2PI(this.startAngle);
|
|
107
|
+
var wrappedEnd = geomutils.mapAngleTo2PI(this.endAngle);
|
|
108
|
+
// TODO: cleanup
|
|
109
|
+
// if (this.startAngle <= this.endAngle) {
|
|
110
|
+
// return angle >= this.startAngle && angle < this.endAngle;
|
|
111
|
+
// } else {
|
|
112
|
+
// // startAngle > endAngle
|
|
113
|
+
// return angle >= this.startAngle || angle < this.endAngle;
|
|
114
|
+
// }
|
|
115
|
+
if (wrappedStart <= wrappedEnd) {
|
|
116
|
+
return wrappedAngle >= wrappedStart && wrappedAngle < wrappedEnd;
|
|
56
117
|
}
|
|
57
118
|
else {
|
|
58
119
|
// startAngle > endAngle
|
|
59
|
-
return
|
|
120
|
+
return wrappedAngle >= wrappedStart || wrappedAngle < wrappedEnd;
|
|
60
121
|
}
|
|
61
122
|
}
|
|
62
123
|
/**
|
|
@@ -150,6 +211,50 @@ export class CircleSector {
|
|
|
150
211
|
}
|
|
151
212
|
return resultSector;
|
|
152
213
|
}
|
|
214
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
215
|
+
/**
|
|
216
|
+
* Get the line intersections as vectors with this ellipse.
|
|
217
|
+
*
|
|
218
|
+
* @method lineIntersections
|
|
219
|
+
* @instance
|
|
220
|
+
* @param {VertTuple<Vector> ray - The line/ray to intersect this ellipse with.
|
|
221
|
+
* @param {boolean} inVectorBoundsOnly - (default=false) Set to true if only intersections within the vector bounds are of interest.
|
|
222
|
+
* @returns
|
|
223
|
+
*/
|
|
224
|
+
lineIntersections(ray, inVectorBoundsOnly = false) {
|
|
225
|
+
// First get all line intersections from underlying ellipse.
|
|
226
|
+
const ellipseIntersections = this.circle.lineIntersections(ray, inVectorBoundsOnly);
|
|
227
|
+
// Drop all intersection points that are not contained in the circle sectors bounds.
|
|
228
|
+
const tmpLine = new Line(this.circle.center, new Vertex());
|
|
229
|
+
return ellipseIntersections.filter((intersectionPoint) => {
|
|
230
|
+
tmpLine.b.set(intersectionPoint);
|
|
231
|
+
const lineAngle = tmpLine.angle();
|
|
232
|
+
return this.containsAngle(geomutils.wrapMinMax(lineAngle, 0, Math.PI * 2));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
237
|
+
*
|
|
238
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
239
|
+
*
|
|
240
|
+
* @param line
|
|
241
|
+
* @param lineIntersectionTangents
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
lineIntersectionTangents(line, inVectorBoundsOnly = false) {
|
|
245
|
+
// Find the intersections of all lines plus their tangents inside the circle bounds
|
|
246
|
+
const interSectionPoints = this.lineIntersections(line, inVectorBoundsOnly);
|
|
247
|
+
return interSectionPoints.map((vert) => {
|
|
248
|
+
// Calculate angle
|
|
249
|
+
const lineFromCenter = new Line(this.circle.center, vert);
|
|
250
|
+
const angle = lineFromCenter.angle();
|
|
251
|
+
// console.log("angle", (angle / Math.PI) * 180.0);
|
|
252
|
+
// const angle = Math.random() * Math.PI * 2; // TODO
|
|
253
|
+
// Calculate tangent at angle
|
|
254
|
+
return this.circle.tangentAt(angle);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
//--- END --- Implement interface `Intersectable`
|
|
153
258
|
/**
|
|
154
259
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
155
260
|
* After calling this function the object might not hold valid data any more and
|