plotboilerplate 1.20.2 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/index.esm.js +1985 -1368
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.esm.min.js +1 -1
  4. package/dist/index.esm.min.js.map +1 -1
  5. package/dist/plotboilerplate.browser.min.js +1 -1
  6. package/dist/plotboilerplate.browser.min.js.map +1 -1
  7. package/dist/plotboilerplate.js +1170 -541
  8. package/dist/plotboilerplate.min.js +1 -1
  9. package/package.json +1 -1
  10. package/src/cjs/BezierPath.d.ts +27 -49
  11. package/src/cjs/BezierPath.js +67 -234
  12. package/src/cjs/BezierPath.js.map +1 -1
  13. package/src/cjs/Bounds.d.ts +14 -1
  14. package/src/cjs/Bounds.js +21 -1
  15. package/src/cjs/Bounds.js.map +1 -1
  16. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  17. package/src/cjs/CubicBezierCurve.js +130 -12
  18. package/src/cjs/CubicBezierCurve.js.map +1 -1
  19. package/src/cjs/Line.d.ts +2 -1
  20. package/src/cjs/Line.js +1 -0
  21. package/src/cjs/Line.js.map +1 -1
  22. package/src/cjs/PBText.d.ts +2 -1
  23. package/src/cjs/PBText.js +10 -9
  24. package/src/cjs/PBText.js.map +1 -1
  25. package/src/cjs/PlotBoilerplate.d.ts +4 -13
  26. package/src/cjs/PlotBoilerplate.js +61 -15
  27. package/src/cjs/PlotBoilerplate.js.map +1 -1
  28. package/src/cjs/Polygon.d.ts +35 -1
  29. package/src/cjs/Polygon.js +87 -1
  30. package/src/cjs/Polygon.js.map +1 -1
  31. package/src/cjs/VEllipse.js +1 -1
  32. package/src/cjs/VEllipse.js.map +1 -1
  33. package/src/cjs/Vector.d.ts +4 -4
  34. package/src/cjs/Vector.js +2 -2
  35. package/src/cjs/Vector.js.map +1 -1
  36. package/src/cjs/VertTuple.d.ts +2 -1
  37. package/src/cjs/VertTuple.js +4 -3
  38. package/src/cjs/VertTuple.js.map +1 -1
  39. package/src/cjs/Vertex.d.ts +14 -3
  40. package/src/cjs/Vertex.js +18 -3
  41. package/src/cjs/Vertex.js.map +1 -1
  42. package/src/cjs/draw.d.ts +154 -75
  43. package/src/cjs/draw.js +308 -137
  44. package/src/cjs/draw.js.map +1 -1
  45. package/src/cjs/drawgl.d.ts +87 -50
  46. package/src/cjs/drawgl.js +86 -31
  47. package/src/cjs/drawgl.js.map +1 -1
  48. package/src/cjs/drawutilssvg.d.ts +226 -53
  49. package/src/cjs/drawutilssvg.js +374 -92
  50. package/src/cjs/drawutilssvg.js.map +1 -1
  51. package/src/cjs/interfaces/DrawLib.d.ts +157 -79
  52. package/src/cjs/interfaces/DrawLib.js +6 -0
  53. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  54. package/src/cjs/interfaces/core.d.ts +13 -2
  55. package/src/cjs/interfaces/core.js +1 -0
  56. package/src/cjs/interfaces/core.js.map +1 -1
  57. package/src/cjs/utils/creategui.js +16 -10
  58. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  59. package/src/cjs/utils/detectDarkMode.js +32 -0
  60. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  61. package/src/esm/BezierPath.d.ts +27 -49
  62. package/src/esm/BezierPath.js +67 -234
  63. package/src/esm/BezierPath.js.map +1 -1
  64. package/src/esm/Bounds.d.ts +14 -1
  65. package/src/esm/Bounds.js +19 -1
  66. package/src/esm/Bounds.js.map +1 -1
  67. package/src/esm/CubicBezierCurve.d.ts +70 -1
  68. package/src/esm/CubicBezierCurve.js +130 -12
  69. package/src/esm/CubicBezierCurve.js.map +1 -1
  70. package/src/esm/Line.d.ts +2 -1
  71. package/src/esm/Line.js +1 -0
  72. package/src/esm/Line.js.map +1 -1
  73. package/src/esm/PBText.d.ts +2 -1
  74. package/src/esm/PBText.js +10 -9
  75. package/src/esm/PBText.js.map +1 -1
  76. package/src/esm/PlotBoilerplate.d.ts +4 -13
  77. package/src/esm/PlotBoilerplate.js +62 -16
  78. package/src/esm/PlotBoilerplate.js.map +1 -1
  79. package/src/esm/Polygon.d.ts +35 -1
  80. package/src/esm/Polygon.js +85 -1
  81. package/src/esm/Polygon.js.map +1 -1
  82. package/src/esm/VEllipse.js +1 -1
  83. package/src/esm/VEllipse.js.map +1 -1
  84. package/src/esm/Vector.d.ts +4 -4
  85. package/src/esm/Vector.js +2 -2
  86. package/src/esm/Vector.js.map +1 -1
  87. package/src/esm/VertTuple.d.ts +2 -1
  88. package/src/esm/VertTuple.js +4 -3
  89. package/src/esm/VertTuple.js.map +1 -1
  90. package/src/esm/Vertex.d.ts +14 -3
  91. package/src/esm/Vertex.js +18 -3
  92. package/src/esm/Vertex.js.map +1 -1
  93. package/src/esm/draw.d.ts +154 -75
  94. package/src/esm/draw.js +304 -135
  95. package/src/esm/draw.js.map +1 -1
  96. package/src/esm/drawgl.d.ts +87 -50
  97. package/src/esm/drawgl.js +86 -31
  98. package/src/esm/drawgl.js.map +1 -1
  99. package/src/esm/drawutilssvg.d.ts +226 -53
  100. package/src/esm/drawutilssvg.js +369 -92
  101. package/src/esm/drawutilssvg.js.map +1 -1
  102. package/src/esm/interfaces/DrawLib.d.ts +157 -79
  103. package/src/esm/interfaces/DrawLib.js +6 -0
  104. package/src/esm/interfaces/DrawLib.js.map +1 -1
  105. package/src/esm/interfaces/core.d.ts +13 -2
  106. package/src/esm/interfaces/core.js +1 -0
  107. package/src/esm/interfaces/core.js.map +1 -1
  108. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  109. package/src/esm/utils/detectDarkMode.js +28 -0
  110. package/src/esm/utils/detectDarkMode.js.map +1 -0
  111. package/src/ts/BezierPath.ts +72 -241
  112. package/src/ts/Bounds.ts +25 -1
  113. package/src/ts/CubicBezierCurve.ts +139 -12
  114. package/src/ts/Line.ts +2 -1
  115. package/src/ts/PBText.ts +10 -9
  116. package/src/ts/PlotBoilerplate.ts +56 -19
  117. package/src/ts/Polygon.ts +91 -1
  118. package/src/ts/VEllipse.ts +2 -2
  119. package/src/ts/Vector.ts +4 -4
  120. package/src/ts/VertTuple.ts +4 -3
  121. package/src/ts/Vertex.ts +20 -4
  122. package/src/ts/draw.ts +311 -115
  123. package/src/ts/drawgl.ts +133 -71
  124. package/src/ts/drawutilssvg.ts +543 -121
  125. package/src/ts/interfaces/DrawLib.ts +219 -83
  126. package/src/ts/interfaces/core.ts +14 -2
  127. package/src/ts/utils/detectDarkMode.ts +30 -0
@@ -82,7 +82,8 @@
82
82
  * @modified 2023-02-10 Fixing an issue of the `style.position` setting when `fitToParent=true` from `absolute` to `static` (default).
83
83
  * @modified 2023-02-10 Cleaning up most type errors in the main class (mostly null checks).
84
84
  * @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
85
- * @version 1.17.2
85
+ * @modified 2023-09-29 Adding proper dicionary key and value types to the params of `PlotBoilerplate.utils.safeMergeByKeys` (was `object` before).
86
+ * @version 1.17.3
86
87
  *
87
88
  * @file PlotBoilerplate
88
89
  * @fileoverview The main class.
@@ -399,7 +400,7 @@ export class PlotBoilerplate {
399
400
  visible: true
400
401
  };
401
402
 
402
- if (typeof config.canvas == "undefined") {
403
+ if (typeof config.canvas === "undefined") {
403
404
  throw "No canvas specified.";
404
405
  }
405
406
 
@@ -496,6 +497,10 @@ export class PlotBoilerplate {
496
497
  fill: true
497
498
  }
498
499
  },
500
+ // bezierPath: {
501
+ // color: "#0022a8",
502
+ // lineWidth: 1
503
+ // },
499
504
  polygon: {
500
505
  color: "#0022a8",
501
506
  lineWidth: 1
@@ -557,7 +562,10 @@ export class PlotBoilerplate {
557
562
  this.grid = new Grid(new Vertex(0, 0), new Vertex(50, 50));
558
563
  this.canvasSize = { width: PlotBoilerplate.DEFAULT_CANVAS_WIDTH, height: PlotBoilerplate.DEFAULT_CANVAS_HEIGHT };
559
564
  const canvasElement: Element =
560
- typeof config.canvas == "string" ? (document.querySelector(config.canvas) as Element) : config.canvas;
565
+ typeof config.canvas === "string" ? (document.querySelector(config.canvas) as Element) : config.canvas;
566
+ if (typeof canvasElement === "undefined") {
567
+ throw `Cannot initialize PlotBoilerplate with a null canvas (element "${config.canvas} not found).`;
568
+ }
561
569
  // Which renderer to use: Canvas2D, WebGL (experimental) or SVG?
562
570
  if (canvasElement.tagName.toLowerCase() === "canvas") {
563
571
  this.canvas = canvasElement as HTMLCanvasElement;
@@ -1259,20 +1267,10 @@ export class PlotBoilerplate {
1259
1267
  if (this.drawConfig.drawBezierHandleLines && this.drawConfig.drawHandleLines) {
1260
1268
  draw.setCurrentId(`${d.uid}_l0`);
1261
1269
  draw.setCurrentClassName(`${d.className}-start-line`);
1262
- draw.line(
1263
- d.bezierCurves[c].startPoint,
1264
- d.bezierCurves[c].startControlPoint,
1265
- this.drawConfig.bezier.handleLine.color,
1266
- this.drawConfig.bezier.handleLine.lineWidth
1267
- );
1270
+ draw.handleLine(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint);
1268
1271
  draw.setCurrentId(`${d.uid}_l1`);
1269
1272
  draw.setCurrentClassName(`${d.className}-end-line`);
1270
- draw.line(
1271
- d.bezierCurves[c].endPoint,
1272
- d.bezierCurves[c].endControlPoint,
1273
- this.drawConfig.bezier.handleLine.color,
1274
- this.drawConfig.bezier.handleLine.lineWidth
1275
- );
1273
+ draw.handleLine(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint);
1276
1274
  }
1277
1275
  curveIndex++;
1278
1276
  } // END for
@@ -1291,11 +1289,11 @@ export class PlotBoilerplate {
1291
1289
  draw.setCurrentId(`${d.uid}_e0`);
1292
1290
  draw.setCurrentClassName(`${d.className}-v-line`);
1293
1291
  // draw.line( d.center.clone().add(0,d.axis.y-d.center.y), d.axis, '#c8c8c8' );
1294
- draw.line(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
1292
+ draw.handleLine(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
1295
1293
  draw.setCurrentId(`${d.uid}_e1`);
1296
1294
  draw.setCurrentClassName(`${d.className}-h-line`);
1297
1295
  // draw.line( d.center.clone().add(d.axis.x-d.center.x,0), d.axis, '#c8c8c8' );
1298
- draw.line(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
1296
+ draw.handleLine(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
1299
1297
  }
1300
1298
  draw.setCurrentId(d.uid);
1301
1299
  draw.setCurrentClassName(`${d.className}`);
@@ -2233,7 +2231,45 @@ export class PlotBoilerplate {
2233
2231
  * @param {Object} extension
2234
2232
  * @return {Object} base extended by the new attributes.
2235
2233
  **/
2236
- safeMergeByKeys: (base: Object, extension: Object): Object => {
2234
+ safeMergeByKeys: <KeyType extends string | number | symbol, ValueType>(
2235
+ base: Record<KeyType, ValueType>,
2236
+ extension: Record<KeyType, ValueType>
2237
+ ): Record<KeyType, ValueType> => {
2238
+ for (var k in extension) {
2239
+ if (!extension.hasOwnProperty(k)) {
2240
+ continue;
2241
+ }
2242
+ if (base.hasOwnProperty(k)) {
2243
+ const typ = typeof base[k];
2244
+ const extVal = extension[k];
2245
+ try {
2246
+ if (typ == "boolean") {
2247
+ if (typeof extVal === "string") base[k] = Boolean(!!JSON.parse(extVal)) as unknown as ValueType;
2248
+ else base[k] = extVal as ValueType;
2249
+ } else if (typ == "number") {
2250
+ if (typeof extVal === "string") base[k] = Number(JSON.parse(extVal) * 1) as unknown as ValueType;
2251
+ else base[k] = extension[k] as ValueType;
2252
+ } else if (typ == "function" && typeof extVal == "function") {
2253
+ base[k] = extension[k];
2254
+ } else {
2255
+ // Probably a sting
2256
+ base[k] = extension[k];
2257
+ }
2258
+ } catch (e) {
2259
+ console.error("error in key ", k, extVal, e);
2260
+ }
2261
+ } else {
2262
+ base[k] = extension[k];
2263
+ }
2264
+ }
2265
+ return base;
2266
+ },
2267
+
2268
+ /*
2269
+ __safeMergeByKeys: <KeyType extends string | number | symbol, ValueType extends boolean | number | string | Function>(
2270
+ base: Record<KeyType, ValueType>,
2271
+ extension: Record<KeyType, string>
2272
+ ): Record<KeyType, ValueType> => {
2237
2273
  for (var k in extension) {
2238
2274
  if (!extension.hasOwnProperty(k)) continue;
2239
2275
  if (base.hasOwnProperty(k)) {
@@ -2252,6 +2288,7 @@ export class PlotBoilerplate {
2252
2288
  }
2253
2289
  return base;
2254
2290
  },
2291
+ *()
2255
2292
 
2256
2293
  /**
2257
2294
  * A helper function to scale elements (usually the canvas) using CSS.
@@ -2314,7 +2351,7 @@ export class PlotBoilerplate {
2314
2351
  * @param {boolean} fallback - A default value if the key does not exist.
2315
2352
  * @return {boolean}
2316
2353
  **/
2317
- bool: (obj: any, key: string, fallback: boolean) => {
2354
+ bool: (obj: any, key: string, fallback: boolean | null) => {
2318
2355
  if (!obj.hasOwnProperty(key)) return fallback;
2319
2356
  if (typeof obj[key] == "boolean") return obj[key];
2320
2357
  else {
package/src/ts/Polygon.ts CHANGED
@@ -24,7 +24,10 @@
24
24
  * @modified 2022-02-02 Added the `destroy` method.
25
25
  * @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
26
26
  * @modified 2022-03-08 Added the `Polygon.clone()` function.
27
- * @version 1.10.0
27
+ * @modified 2023-09-25 Added the `Polygon.getInterpolationPolygon(number)` function.
28
+ * @modified 2023-09-25 Added the `Polygon.lineIntersections(Line,boolean)` function.
29
+ * @modified 2023-09-29 Added the `Polygon.closestLineIntersection(Line,boolean)` function.
30
+ * @version 1.11.0
28
31
  *
29
32
  * @file Polygon
30
33
  * @public
@@ -32,7 +35,9 @@
32
35
 
33
36
  import { BezierPath } from "./BezierPath";
34
37
  import { Bounds } from "./Bounds";
38
+ import { Line } from "./Line";
35
39
  import { UIDGenerator } from "./UIDGenerator";
40
+ import { VertTuple } from "./VertTuple";
36
41
  import { Vertex } from "./Vertex";
37
42
  import { XYCoords, SVGSerializable, UID } from "./interfaces";
38
43
 
@@ -276,6 +281,91 @@ export class Polygon implements SVGSerializable {
276
281
  return this;
277
282
  }
278
283
 
284
+ /**
285
+ * Get all line intersections with this polygon.
286
+ *
287
+ * See demo `47-closest-vector-projection-on-polygon` for how it works.
288
+ *
289
+ * @param {VertTuple} line - The line to find intersections with.
290
+ * @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
291
+ * @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
292
+ */
293
+ lineIntersections(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vertex> {
294
+ // Find the intersections of all lines inside the edge bounds
295
+ const intersectionPoints: Array<Vertex> = [];
296
+ for (var i = 0; i < this.vertices.length; i++) {
297
+ const polyLine = new Line(this.vertices[i], this.vertices[(i + 1) % this.vertices.length]);
298
+ const intersection = polyLine.intersection(line);
299
+ // true => only inside bounds
300
+ // ignore last edge if open
301
+ if (
302
+ (!this.isOpen || i + 1 !== this.vertices.length) &&
303
+ intersection !== null &&
304
+ polyLine.hasPoint(intersection, true) &&
305
+ (!inVectorBoundsOnly || line.hasPoint(intersection, inVectorBoundsOnly))
306
+ ) {
307
+ intersectionPoints.push(intersection);
308
+ }
309
+ }
310
+ return intersectionPoints;
311
+ }
312
+
313
+ /**
314
+ * Get the closest line-polygon-intersection point (closest the line point A).
315
+ *
316
+ * See demo `47-closest-vector-projection-on-polygon` for how it works.
317
+ *
318
+ * @param {VertTuple} line - The line to find intersections with.
319
+ * @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are considered (located strictly between start and end vertex).
320
+ * @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
321
+ */
322
+ closestLineIntersection(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Vertex | null {
323
+ const allIntersections = this.lineIntersections(line, inVectorBoundsOnly);
324
+ if (allIntersections.length <= 0) {
325
+ // Empty polygon -> no intersections
326
+ return null;
327
+ }
328
+ // Find the closest intersection
329
+ let closestIntersection = new Vertex(Number.MAX_VALUE, Number.MAX_VALUE);
330
+ let curDist = Number.MAX_VALUE;
331
+ for (var i in allIntersections) {
332
+ const curVert = allIntersections[i];
333
+ const dist = curVert.distance(line.a);
334
+ if (dist < curDist) {
335
+ // && line.hasPoint(curVert)) {
336
+ curDist = dist;
337
+ closestIntersection = curVert;
338
+ }
339
+ }
340
+ return closestIntersection;
341
+ }
342
+
343
+ /**
344
+ * Construct a new polygon from this polygon with more vertices on each edge. The
345
+ * interpolation count determines the number of additional vertices on each edge.
346
+ * An interpolation count of `0` will return a polygon that equals the source
347
+ * polygon.
348
+ *
349
+ * @param {number} interpolationCount
350
+ * @returns {Polygon} A polygon with `interpolationCount` more vertices (as as factor).
351
+ */
352
+ getInterpolationPolygon(interpolationCount: number): Polygon {
353
+ const verts: Array<Vertex> = [];
354
+ for (var i = 0; i < this.vertices.length; i++) {
355
+ const curVert = this.vertices[i];
356
+ const nextVert = this.vertices[(i + 1) % this.vertices.length];
357
+ verts.push(curVert.clone());
358
+ // Add interpolation points
359
+ if (!this.isOpen || i + 1 !== this.vertices.length) {
360
+ const lerpAmount = 1.0 / (interpolationCount + 1);
361
+ for (var j = 1; j <= interpolationCount; j++) {
362
+ verts.push(curVert.clone().lerp(nextVert, lerpAmount * j));
363
+ }
364
+ }
365
+ }
366
+ return new Polygon(verts, this.isOpen);
367
+ }
368
+
279
369
  /**
280
370
  * Convert this polygon into a new polygon with n evenly distributed vertices.
281
371
  *
@@ -392,8 +392,8 @@ export class VEllipse implements SVGSerializable {
392
392
  let startTangent: Vector = this.tangentAt(curAngle);
393
393
  let endTangent: Vector = this.tangentAt(nextAngle);
394
394
 
395
- // Find intersection
396
- let intersection: Vertex | undefined = startTangent.intersection(endTangent);
395
+ // Find intersection (ignore that the result might be null in some extreme cases)
396
+ let intersection: Vertex = startTangent.intersection(endTangent) as Vertex;
397
397
  // What if intersection is undefined?
398
398
  // --> This *can* not happen if segmentCount > 2 and height and width of the ellipse are not zero.
399
399
 
package/src/ts/Vector.ts CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  import { VertTuple } from "./VertTuple";
22
22
  import { Vertex } from "./Vertex";
23
- import { SVGSerializable } from "./interfaces";
23
+ import { SVGSerializable, XYCoords } from "./interfaces";
24
24
 
25
25
  /**
26
26
  * @classdesc A vector (Vertex,Vertex) is a line with a visible direction.<br>
@@ -156,13 +156,13 @@ export class Vector extends VertTuple<Vector> implements SVGSerializable {
156
156
  * Example:
157
157
  * buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
158
158
  *
159
- * @param {Vertex} zA - The start vertex of the vector to calculate the arrow head for.
160
- * @param {Vertex} zB - The end vertex of the vector.
159
+ * @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
160
+ * @param {XYCoords} zB - The end vertex of the vector.
161
161
  * @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
162
162
  * @param {number} scaleX - The horizontal scaling during draw.
163
163
  * @param {number} scaleY - the vertical scaling during draw.
164
164
  **/
165
- buildArrowHead: (zA: Vertex, zB: Vertex, headlen: number, scaleX: number, scaleY: number) => {
165
+ buildArrowHead: (zA: XYCoords, zB: XYCoords, headlen: number, scaleX: number, scaleY: number): Array<Vertex> => {
166
166
  const angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
167
167
  const vertices: Array<Vertex> = [];
168
168
  vertices.push(new Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
@@ -9,7 +9,8 @@
9
9
  * @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
10
10
  * @modified 2021-01-20 Added UID.
11
11
  * @modified 2022-02-02 Added the `destroy` method.
12
- * @version 1.2.0
12
+ * @modified 2023-09-29 Fixed a calculation error in the VertTuple.hasPoint() function; distance measure was broken!
13
+ * @version 1.2.1
13
14
  */
14
15
 
15
16
  import { Vertex } from "./Vertex";
@@ -277,11 +278,11 @@ export class VertTuple<T extends VertTuple<T>> {
277
278
  hasPoint(point: XYCoords, insideBoundsOnly?: boolean): boolean {
278
279
  const t: number = this.getClosestT(point);
279
280
  // Compare to pointDistance?
281
+ const distance: number = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
280
282
  if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
281
- const distance: number = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
282
283
  return distance < Vertex.EPSILON && t >= 0 && t <= 1;
283
284
  } else {
284
- return t >= 0 && t <= 1;
285
+ return distance < Vertex.EPSILON; // t >= 0 && t <= 1;
285
286
  }
286
287
  }
287
288
 
package/src/ts/Vertex.ts CHANGED
@@ -29,6 +29,8 @@
29
29
  * @modified 2022-02-02 Added the `destroy` method.
30
30
  * @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
31
31
  * @modified 2022-11-28 Added the `subXY`, `subX` and `subY` methods to the `Vertex` class.
32
+ * @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
33
+ * @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
32
34
  * @version 2.8.0
33
35
  *
34
36
  * @file Vertex
@@ -607,6 +609,20 @@ export class Vertex implements XYCoords, SVGSerializable {
607
609
  return this;
608
610
  }
609
611
 
612
+ /**
613
+ * Set both coordinates of this vertex to their absolute value (abs(x), abs(y)).
614
+ *
615
+ * @method abs
616
+ * @return {Vertex} this
617
+ * @instance
618
+ * @memberof Vertex
619
+ */
620
+ abs(): Vertex {
621
+ this.x = Math.abs(this.x);
622
+ this.y = Math.abs(this.y);
623
+ return this;
624
+ }
625
+
610
626
  /**
611
627
  * Get a string representation of this vertex.
612
628
  *
@@ -662,15 +678,15 @@ export class Vertex implements XYCoords, SVGSerializable {
662
678
  * Example:
663
679
  * buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
664
680
  *
665
- * @param {Vertex} zA - The start vertex of the vector to calculate the arrow head for.
666
- * @param {Vertex} zB - The end vertex of the vector.
681
+ * @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
682
+ * @param {XYCoords} zB - The end vertex of the vector.
667
683
  * @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
668
684
  * @param {number} scaleX - The horizontal scaling during draw.
669
685
  * @param {number} scaleY - the vertical scaling during draw.
670
686
  **/
671
687
  // @DEPRECATED: use Vector.utils.buildArrowHead instead!!!
672
- buildArrowHead: (zA: Vertex, zB: Vertex, headlen: number, scaleX: number, scaleY: number): Array<Vertex> => {
673
- // console.warn('This function is deprecated! Use Vector.utils.buildArrowHead instead!');
688
+ buildArrowHead: (zA: XYCoords, zB: XYCoords, headlen: number, scaleX: number, scaleY: number): Array<Vertex> => {
689
+ console.warn("[DEPRECATION] Vertex.utils.buildArrowHead is deprecated. Please use Vector.utils.buildArrowHead instead.");
674
690
  var angle: number = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
675
691
 
676
692
  var vertices: Array<Vertex> = [];