plotboilerplate 1.16.0 → 1.17.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 (173) hide show
  1. package/README.md +1 -0
  2. package/changelog.md +26 -1
  3. package/dist/index.esm.js +355 -441
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.esm.min.js +1 -1
  6. package/dist/index.esm.min.js.map +1 -1
  7. package/dist/plotboilerplate.browser.min.js +1 -1
  8. package/dist/plotboilerplate.browser.min.js.map +1 -1
  9. package/dist/plotboilerplate.js +357 -345
  10. package/dist/plotboilerplate.min.js +1 -1
  11. package/package.json +1 -1
  12. package/src/cjs/BezierPath.d.ts +0 -14
  13. package/src/cjs/BezierPath.js +0 -26
  14. package/src/cjs/BezierPath.js.map +1 -1
  15. package/src/cjs/Bounds.d.ts +22 -1
  16. package/src/cjs/Bounds.js +24 -1
  17. package/src/cjs/Bounds.js.map +1 -1
  18. package/src/cjs/Circle.d.ts +0 -13
  19. package/src/cjs/Circle.js +0 -23
  20. package/src/cjs/Circle.js.map +1 -1
  21. package/src/cjs/CircleSector.d.ts +0 -13
  22. package/src/cjs/CircleSector.js +0 -27
  23. package/src/cjs/CircleSector.js.map +1 -1
  24. package/src/cjs/CubicBezierCurve.d.ts +0 -15
  25. package/src/cjs/CubicBezierCurve.js +0 -36
  26. package/src/cjs/CubicBezierCurve.js.map +1 -1
  27. package/src/cjs/Line.d.ts +0 -14
  28. package/src/cjs/Line.js +0 -26
  29. package/src/cjs/Line.js.map +1 -1
  30. package/src/cjs/PBImage.d.ts +0 -13
  31. package/src/cjs/PBImage.js +0 -14
  32. package/src/cjs/PBImage.js.map +1 -1
  33. package/src/cjs/PBText.d.ts +0 -13
  34. package/src/cjs/PBText.js +0 -14
  35. package/src/cjs/PBText.js.map +1 -1
  36. package/src/cjs/Polygon.d.ts +9 -15
  37. package/src/cjs/Polygon.js +12 -39
  38. package/src/cjs/Polygon.js.map +1 -1
  39. package/src/cjs/Triangle.d.ts +0 -13
  40. package/src/cjs/Triangle.js +0 -37
  41. package/src/cjs/Triangle.js.map +1 -1
  42. package/src/cjs/VEllipse.d.ts +0 -10
  43. package/src/cjs/VEllipse.js +0 -21
  44. package/src/cjs/VEllipse.js.map +1 -1
  45. package/src/cjs/Vector.d.ts +0 -14
  46. package/src/cjs/Vector.js +0 -36
  47. package/src/cjs/Vector.js.map +1 -1
  48. package/src/cjs/Vertex.d.ts +0 -14
  49. package/src/cjs/Vertex.js +0 -25
  50. package/src/cjs/Vertex.js.map +1 -1
  51. package/src/cjs/draw.d.ts +41 -2
  52. package/src/cjs/draw.js +140 -3
  53. package/src/cjs/draw.js.map +1 -1
  54. package/src/cjs/drawgl.d.ts +38 -2
  55. package/src/cjs/drawgl.js +41 -2
  56. package/src/cjs/drawgl.js.map +1 -1
  57. package/src/cjs/drawutilssvg.d.ts +66 -3
  58. package/src/cjs/drawutilssvg.js +140 -15
  59. package/src/cjs/drawutilssvg.js.map +1 -1
  60. package/src/cjs/index.d.ts +0 -1
  61. package/src/cjs/index.js +0 -1
  62. package/src/cjs/index.js.map +1 -1
  63. package/src/cjs/interfaces/DrawLib.d.ts +61 -26
  64. package/src/cjs/interfaces/DrawLib.js +2 -0
  65. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  66. package/src/cjs/interfaces/core.d.ts +0 -12
  67. package/src/cjs/module.d.ts +1 -3
  68. package/src/cjs/module.js +2 -5
  69. package/src/cjs/module.js.map +1 -1
  70. package/src/cjs/utils/creategui.js +16 -2
  71. package/src/cjs/utils/datastructures/Girih.d.ts +5 -0
  72. package/src/cjs/utils/datastructures/Girih.js +18 -14
  73. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  74. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +42 -25
  75. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  76. package/src/cjs/utils/datastructures/GirihTile.js +2 -13
  77. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  78. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +2 -1
  79. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +9 -18
  80. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  81. package/src/esm/BezierPath.d.ts +0 -14
  82. package/src/esm/BezierPath.js +0 -26
  83. package/src/esm/BezierPath.js.map +1 -1
  84. package/src/esm/Bounds.d.ts +22 -1
  85. package/src/esm/Bounds.js +24 -1
  86. package/src/esm/Bounds.js.map +1 -1
  87. package/src/esm/Circle.d.ts +0 -13
  88. package/src/esm/Circle.js +0 -23
  89. package/src/esm/Circle.js.map +1 -1
  90. package/src/esm/CircleSector.d.ts +0 -13
  91. package/src/esm/CircleSector.js +0 -27
  92. package/src/esm/CircleSector.js.map +1 -1
  93. package/src/esm/CubicBezierCurve.d.ts +0 -15
  94. package/src/esm/CubicBezierCurve.js +0 -36
  95. package/src/esm/CubicBezierCurve.js.map +1 -1
  96. package/src/esm/Line.d.ts +0 -14
  97. package/src/esm/Line.js +0 -26
  98. package/src/esm/Line.js.map +1 -1
  99. package/src/esm/PBImage.d.ts +0 -13
  100. package/src/esm/PBImage.js +0 -14
  101. package/src/esm/PBImage.js.map +1 -1
  102. package/src/esm/PBText.d.ts +0 -13
  103. package/src/esm/PBText.js +0 -14
  104. package/src/esm/PBText.js.map +1 -1
  105. package/src/esm/Polygon.d.ts +9 -15
  106. package/src/esm/Polygon.js +12 -39
  107. package/src/esm/Polygon.js.map +1 -1
  108. package/src/esm/Triangle.d.ts +0 -13
  109. package/src/esm/Triangle.js +0 -37
  110. package/src/esm/Triangle.js.map +1 -1
  111. package/src/esm/VEllipse.d.ts +0 -10
  112. package/src/esm/VEllipse.js +0 -21
  113. package/src/esm/VEllipse.js.map +1 -1
  114. package/src/esm/Vector.d.ts +0 -14
  115. package/src/esm/Vector.js +0 -36
  116. package/src/esm/Vector.js.map +1 -1
  117. package/src/esm/Vertex.d.ts +0 -14
  118. package/src/esm/Vertex.js +0 -25
  119. package/src/esm/Vertex.js.map +1 -1
  120. package/src/esm/draw.d.ts +41 -2
  121. package/src/esm/draw.js +139 -3
  122. package/src/esm/draw.js.map +1 -1
  123. package/src/esm/drawgl.d.ts +38 -2
  124. package/src/esm/drawgl.js +41 -2
  125. package/src/esm/drawgl.js.map +1 -1
  126. package/src/esm/drawutilssvg.d.ts +66 -3
  127. package/src/esm/drawutilssvg.js +140 -15
  128. package/src/esm/drawutilssvg.js.map +1 -1
  129. package/src/esm/index.d.ts +0 -1
  130. package/src/esm/index.js +0 -1
  131. package/src/esm/index.js.map +1 -1
  132. package/src/esm/interfaces/DrawLib.d.ts +61 -26
  133. package/src/esm/interfaces/DrawLib.js +2 -0
  134. package/src/esm/interfaces/DrawLib.js.map +1 -1
  135. package/src/esm/interfaces/core.d.ts +0 -12
  136. package/src/esm/module.d.ts +1 -3
  137. package/src/esm/module.js +5 -4
  138. package/src/esm/module.js.map +1 -1
  139. package/src/esm/utils/datastructures/Girih.d.ts +5 -0
  140. package/src/esm/utils/datastructures/Girih.js +18 -14
  141. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  142. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +42 -25
  143. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  144. package/src/esm/utils/datastructures/GirihTile.js +2 -13
  145. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  146. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +2 -1
  147. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +9 -18
  148. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  149. package/src/ts/BezierPath.ts +0 -29
  150. package/src/ts/Bounds.ts +25 -1
  151. package/src/ts/Circle.ts +0 -26
  152. package/src/ts/CircleSector.ts +0 -30
  153. package/src/ts/CubicBezierCurve.ts +0 -39
  154. package/src/ts/Line.ts +0 -29
  155. package/src/ts/PBImage.ts +0 -15
  156. package/src/ts/PBText.ts +0 -17
  157. package/src/ts/Polygon.ts +16 -42
  158. package/src/ts/Triangle.ts +0 -40
  159. package/src/ts/VEllipse.ts +0 -24
  160. package/src/ts/Vector.ts +0 -40
  161. package/src/ts/Vertex.ts +0 -28
  162. package/src/ts/draw.ts +192 -3
  163. package/src/ts/drawgl.ts +44 -2
  164. package/src/ts/drawutilssvg.ts +181 -15
  165. package/src/ts/index.ts +0 -1
  166. package/src/ts/interfaces/DrawLib.ts +69 -26
  167. package/src/ts/interfaces/core.ts +0 -11
  168. package/src/ts/module.ts +2 -4
  169. package/src/ts/utils/datastructures/Girih.ts +204 -209
  170. package/src/ts/utils/datastructures/GirihPenroseRhombus.ts +170 -152
  171. package/src/ts/utils/datastructures/GirihTile.ts +394 -419
  172. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +9 -18
  173. package/src/ts/SVGBuilder.ts +0 -109
package/src/ts/Polygon.ts CHANGED
@@ -23,7 +23,8 @@
23
23
  * @modified 2021-12-16 Added the `getEvenDistributionPolygon()` function.
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
- * @version 1.9.0
26
+ * @modified 2022-03-08 Added the `Polygon.clone()` function.
27
+ * @version 1.10.0
27
28
  *
28
29
  * @file Polygon
29
30
  * @public
@@ -143,9 +144,9 @@ export class Polygon implements SVGSerializable {
143
144
  * @memberof Polygon
144
145
  * @return {Polygon} this for chaining
145
146
  **/
146
- move(vert: XYCoords): Polygon {
147
+ move(amount: XYCoords): Polygon {
147
148
  for (var i in this.vertices) {
148
- this.vertices[i].add(vert);
149
+ this.vertices[i].add(amount);
149
150
  }
150
151
  return this;
151
152
  }
@@ -336,6 +337,18 @@ export class Polygon implements SVGSerializable {
336
337
  return Bounds.computeFromVertices(this.vertices);
337
338
  }
338
339
 
340
+ /**
341
+ * Create a deep copy of this polygon.
342
+ *
343
+ * @return {Polygon} The cloned polygon.
344
+ */
345
+ clone(): Polygon {
346
+ return new Polygon(
347
+ this.vertices.map(vert => vert.clone()),
348
+ this.isOpen
349
+ );
350
+ }
351
+
339
352
  /**
340
353
  * Convert this polygon to a sequence of quadratic Bézier curves.<br>
341
354
  * <br>
@@ -479,45 +492,6 @@ export class Polygon implements SVGSerializable {
479
492
  return BezierPath.fromArray(pathdata);
480
493
  }
481
494
 
482
- /**
483
- * Create an SVG representation of this polygon.
484
- *
485
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
486
- * @method toSVGString
487
- * @param {object=} options - An optional set of options, like 'className'.
488
- * @return {string} The SVG string.
489
- * @instance
490
- * @memberof Polygon
491
- **/
492
- toSVGString(options: { className?: string } | undefined): string {
493
- // options = options || {};
494
- // var buffer: Array<string> = [];
495
- // buffer.push("<path");
496
- // if (options.className) buffer.push(' class="' + options.className + '"');
497
- // buffer.push(' d="');
498
- // if (this.vertices.length > 0) {
499
- // buffer.push("M ");
500
- // buffer.push(this.vertices[0].x.toString());
501
- // buffer.push(" ");
502
- // buffer.push(this.vertices[0].y.toString());
503
- // for (var i = 1; i < this.vertices.length; i++) {
504
- // buffer.push(" L ");
505
- // buffer.push(this.vertices[i].x.toString());
506
- // buffer.push(" ");
507
- // buffer.push(this.vertices[i].y.toString());
508
- // }
509
- // if (!this.isOpen) {
510
- // buffer.push(" Z");
511
- // }
512
- // }
513
- // buffer.push('" />');
514
- // return buffer.join("");
515
- console.warn(
516
- "[Deprecation] Warning: the Polygon.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead."
517
- );
518
- return "";
519
- }
520
-
521
495
  /**
522
496
  * This function should invalidate any installed listeners and invalidate this object.
523
497
  * After calling this function the object might not hold valid data any more and
@@ -451,46 +451,6 @@ export class Triangle implements SVGSerializable {
451
451
  return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + ", c : " + this.c.toString() + "}";
452
452
  }
453
453
 
454
- /**
455
- * Create an SVG representation of this triangle.
456
- *
457
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
458
- * @method toSVGString
459
- * @param {object=} options - An optional set of options, like 'className'.
460
- * @return {string} The SVG string.
461
- * @instance
462
- * @memberof Triangle
463
- **/
464
- toSVGString(options: { className?: string }): string {
465
- // options = options || {};
466
- // var buffer = [];
467
- // buffer.push("<path");
468
- // if (options.className) buffer.push(' class="' + options.className + '"');
469
- // buffer.push(' d="');
470
- // var vertices = [this.a, this.b, this.c];
471
- // if (vertices.length > 0) {
472
- // buffer.push("M ");
473
- // buffer.push(vertices[0].x);
474
- // buffer.push(" ");
475
- // buffer.push(vertices[0].y);
476
- // for (var i = 1; i < vertices.length; i++) {
477
- // buffer.push(" L ");
478
- // buffer.push(vertices[i].x);
479
- // buffer.push(" ");
480
- // buffer.push(vertices[i].y);
481
- // }
482
- // //if( !this.isOpen ) {
483
- // buffer.push(" Z");
484
- // //}
485
- // }
486
- // buffer.push('" />');
487
- // return buffer.join("");
488
- console.warn(
489
- "[Deprecation] Warning: the Triangle.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead."
490
- );
491
- return "";
492
- }
493
-
494
454
  /**
495
455
  * This function should invalidate any installed listeners and invalidate this object.
496
456
  * After calling this function the object might not hold valid data any more and
@@ -413,30 +413,6 @@ export class VEllipse implements SVGSerializable {
413
413
  return curves;
414
414
  }
415
415
 
416
- /**
417
- * Create an SVG representation of this ellipse.
418
- *
419
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
420
- * @param {object} options { className?:string }
421
- * @return string The SVG string
422
- */
423
- toSVGString(options: { className?: string }) {
424
- // options = options || {};
425
- // var buffer: Array<string> = [];
426
- // buffer.push("<ellipse");
427
- // if (options.className) buffer.push(' class="' + options.className + '"');
428
- // buffer.push(' cx="' + this.center.x + '"');
429
- // buffer.push(' cy="' + this.center.y + '"');
430
- // buffer.push(' rx="' + this.axis.x + '"');
431
- // buffer.push(' ry="' + this.axis.y + '"');
432
- // buffer.push(" />");
433
- // return buffer.join("");
434
- console.warn(
435
- "[Deprecation] Warning: the VEllipse.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead."
436
- );
437
- return "";
438
- }
439
-
440
416
  /**
441
417
  * This function should invalidate any installed listeners and invalidate this object.
442
418
  * After calling this function the object might not hold valid data any more and
package/src/ts/Vector.ts CHANGED
@@ -116,46 +116,6 @@ export class Vector extends VertTuple<Vector> implements SVGSerializable {
116
116
  return new Vertex(this.a.x + a * (this.b.x - this.a.x), this.a.y + a * (this.b.y - this.a.y));
117
117
  }
118
118
 
119
- /**
120
- * Create an SVG representation of this line.
121
- *
122
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
123
- * @method toSVGString
124
- * @override
125
- * @param {object=} options - A set of options, like 'className'.
126
- * @return {string} The SVG string representation.
127
- * @instance
128
- * @memberof Vector
129
- **/
130
- toSVGString(options: { className?: string }) {
131
- // options = options || {};
132
- // var buffer = [];
133
- // var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
134
- // buffer.push("<g");
135
- // if (options.className) buffer.push(' class="' + options.className + '"');
136
- // buffer.push(">");
137
- // buffer.push(" <line");
138
- // buffer.push(' x1="' + this.a.x + '"');
139
- // buffer.push(' y1="' + this.a.y + '"');
140
- // buffer.push(' x2="' + vertices[0].x + '"');
141
- // buffer.push(' y2="' + vertices[0].y + '"');
142
- // buffer.push(" />");
143
- // // Add arrow head
144
-
145
- // buffer.push(' <polygon points="');
146
- // for (var i = 0; i < vertices.length; i++) {
147
- // if (i > 0) buffer.push(" ");
148
- // buffer.push("" + vertices[i].x + "," + vertices[i].y);
149
- // }
150
- // buffer.push('"/>');
151
- // buffer.push("</g>");
152
- // return buffer.join("");
153
- console.warn(
154
- "[Deprecation] Warning: the Vector.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead."
155
- );
156
- return "";
157
- }
158
-
159
119
  static utils = {
160
120
  /**
161
121
  * Generate a four-point arrow head, starting at the vector end minus the
package/src/ts/Vertex.ts CHANGED
@@ -574,34 +574,6 @@ export class Vertex implements XYCoords, SVGSerializable {
574
574
  return "(" + this.x + "," + this.y + ")";
575
575
  }
576
576
 
577
- /**
578
- * Convert this vertex to SVG code.
579
- *
580
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
581
- * @method toSVGString
582
- * @param {object=} options - An optional set of options, like 'className'.
583
- * @return {string} A string representing the SVG code for this vertex.
584
- * @instance
585
- * @memberof Vertex
586
- * @deprecated
587
- **/
588
- toSVGString(options: { className?: string }): string {
589
- // options = options || {};
590
- // var buffer = [];
591
- // buffer.push("<circle");
592
- // if (options.className) buffer.push(' class="' + options.className + '"');
593
- // buffer.push(' cx="' + this.x + '"');
594
- // buffer.push(' cy="' + this.y + '"');
595
- // buffer.push(' r="2"');
596
- // buffer.push(" />");
597
- // return buffer.join("");
598
- console.warn(
599
- "[Deprecation] Warning: the Vertex.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead."
600
- );
601
- return "";
602
- }
603
- // END Vertex
604
-
605
577
  /**
606
578
  * This function should invalidate any installed listeners and invalidate this object.
607
579
  * After calling this function the object might not hold valid data any more and
package/src/ts/draw.ts CHANGED
@@ -39,7 +39,10 @@
39
39
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
40
40
  * @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
41
41
  * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
42
- * @version 1.10.0
42
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
43
+ * @modified 2022-02-03 Added the `cross(...)` function.
44
+ * @modified 2022-03-27 Added the `texturedPoly` function.
45
+ * @version 1.12.0
43
46
  **/
44
47
 
45
48
  import { CubicBezierCurve } from "./CubicBezierCurve";
@@ -47,6 +50,7 @@ import { Polygon } from "./Polygon";
47
50
  import { Vertex } from "./Vertex";
48
51
  import { DrawLib, SVGPathParams, XYCoords, UID, DrawLibConfiguration, FontStyle, FontWeight } from "./interfaces";
49
52
  import { drawutilssvg } from "./drawutilssvg";
53
+ import { Bounds } from "./Bounds";
50
54
 
51
55
  // Todo: rename this class to Drawutils?
52
56
  /**
@@ -251,6 +255,146 @@ export class drawutils implements DrawLib<void> {
251
255
  this.ctx.restore();
252
256
  }
253
257
 
258
+ /**
259
+ * Draw an image at the given position with the given size.<br>
260
+ * <br>
261
+ * Note: SVG images may have resizing issues at the moment.Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
262
+ *
263
+ * @method texturedPoly
264
+ * @param {Image} textureImage - The image object to draw.
265
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
266
+ * @param {Polygon} polygon - The polygon to use as clip path.
267
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
268
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
269
+ * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
270
+ * @return {void}
271
+ * @instance
272
+ * @memberof drawutils
273
+ **/
274
+ texturedPoly(
275
+ textureImage: HTMLImageElement,
276
+ textureSize: Bounds,
277
+ polygon: Polygon,
278
+ polygonPosition: Vertex,
279
+ rotation: number
280
+ ): void {
281
+ var basePolygonBounds = polygon.getBounds();
282
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
283
+ // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
284
+ // var rotationalOffset = { x: 0, y: 0 };
285
+ var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
286
+
287
+ // Get the position offset of the polygon
288
+ var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
289
+ // var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
290
+ var targetTextureOffset = new Vertex(textureSize.min.x, textureSize.min.y).sub(polygonPosition);
291
+
292
+ this.ctx.save();
293
+ // this.ctx.translate(this.offset.x + rotationCenter.x * this.scale.x, this.offset.y + rotationCenter.y * this.scale.y);
294
+ this.ctx.translate(this.offset.x + polygonPosition.x * this.scale.x, this.offset.y + polygonPosition.y * this.scale.y);
295
+
296
+ drawutils.helpers.clipPoly(
297
+ this.ctx,
298
+ {
299
+ x: -polygonPosition.x * this.scale.x,
300
+ y: -polygonPosition.y * this.scale.y
301
+ },
302
+ this.scale,
303
+ polygon.vertices
304
+ );
305
+ this.ctx.scale(this.scale.x, this.scale.y);
306
+ this.ctx.rotate(rotation);
307
+ this.ctx.drawImage(
308
+ textureImage,
309
+ 0,
310
+ 0,
311
+ textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
312
+ textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
313
+ targetTextureOffset.x, // * this.scale.x,
314
+ targetTextureOffset.y, // * this.scale.y,
315
+ targetTextureSize.x, // * this.scale.x,
316
+ targetTextureSize.y // * this.scale.y
317
+ );
318
+
319
+ this.ctx.restore();
320
+ }
321
+
322
+ _texturedPoly(
323
+ textureImage: HTMLImageElement,
324
+ textureSize: Bounds,
325
+ polygon: Polygon,
326
+ polygonPosition: Vertex,
327
+ rotation: number,
328
+ rotationCenter: XYCoords = { x: 0, y: 0 }
329
+ ): void {
330
+ var basePolygonBounds = polygon.getBounds();
331
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
332
+ var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
333
+ // var rotationalOffset = { x: 0, y: 0 };
334
+ var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
335
+
336
+ // Get the position offset of the polygon
337
+ var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
338
+ var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
339
+
340
+ this.ctx.save();
341
+
342
+ // this.ctx.translate(
343
+ // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
344
+ // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
345
+ // );
346
+ this.ctx.translate(
347
+ this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
348
+ this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
349
+ );
350
+ this.ctx.rotate(rotation);
351
+
352
+ drawutils.helpers.clipPoly(
353
+ this.ctx,
354
+ {
355
+ x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
356
+ y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
357
+ },
358
+ this.scale,
359
+ polygon.vertices
360
+ );
361
+ this.ctx.drawImage(
362
+ textureImage,
363
+ 0,
364
+ 0,
365
+ textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
366
+ textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
367
+ (-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
368
+ (-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y,
369
+ targetTextureSize.x * this.scale.x,
370
+ targetTextureSize.y * this.scale.y
371
+ );
372
+
373
+ // const scaledTextureSize = new Bounds(
374
+ // new Vertex(
375
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
376
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
377
+ // ).scaleXY(this.scale, rotationCenter),
378
+ // new Vertex(
379
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
380
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
381
+ // ).scaleXY(this.scale, rotationCenter)
382
+ // );
383
+ // this.ctx.drawImage(
384
+ // textureImage,
385
+ // 0,
386
+ // 0,
387
+ // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
388
+ // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
389
+ // scaledTextureSize.min.x,
390
+ // scaledTextureSize.min.y,
391
+ // scaledTextureSize.width,
392
+ // scaledTextureSize.height
393
+ // );
394
+
395
+ this.ctx.restore();
396
+ }
397
+
254
398
  /**
255
399
  * Draw a rectangle.
256
400
  *
@@ -784,11 +928,12 @@ export class drawutils implements DrawLib<void> {
784
928
  * @param {XYCoords} center - The center of the crosshair.
785
929
  * @param {number} radius - The radius of the crosshair.
786
930
  * @param {string} color - The CSS color to draw the crosshair with.
931
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
787
932
  * @return {void}
788
933
  * @instance
789
934
  * @memberof drawutils
790
935
  */
791
- crosshair(center: XYCoords, radius: number, color: string) {
936
+ crosshair(center: XYCoords, radius: number, color: string, lineWidth?: number) {
792
937
  this.ctx.save();
793
938
  this.ctx.beginPath();
794
939
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
@@ -796,7 +941,35 @@ export class drawutils implements DrawLib<void> {
796
941
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - radius);
797
942
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y + radius);
798
943
  this.ctx.strokeStyle = color;
799
- this.ctx.lineWidth = 0.5;
944
+ this.ctx.lineWidth = lineWidth || 0.5;
945
+ this.ctx.stroke();
946
+ this.ctx.closePath();
947
+ this.ctx.restore();
948
+ }
949
+
950
+ /**
951
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
952
+ * <br>
953
+ * Note that the x's radius will not be affected by scaling.
954
+ *
955
+ * @method crosshair
956
+ * @param {XYCoords} center - The center of the crosshair.
957
+ * @param {number} radius - The radius of the crosshair.
958
+ * @param {string} color - The CSS color to draw the crosshair with.
959
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
960
+ * @return {void}
961
+ * @instance
962
+ * @memberof drawutils
963
+ */
964
+ cross(center: XYCoords, radius: number, color: string, lineWidth?: number) {
965
+ this.ctx.save();
966
+ this.ctx.beginPath();
967
+ this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
968
+ this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
969
+ this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y + radius);
970
+ this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y - radius);
971
+ this.ctx.strokeStyle = color;
972
+ this.ctx.lineWidth = lineWidth || 1.0;
800
973
  this.ctx.stroke();
801
974
  this.ctx.closePath();
802
975
  this.ctx.restore();
@@ -992,4 +1165,20 @@ export class drawutils implements DrawLib<void> {
992
1165
  this.ctx.fillStyle = color;
993
1166
  this.ctx.fillRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
994
1167
  }
1168
+
1169
+ private static helpers = {
1170
+ // A helper function to define the clipping path.
1171
+ // This could be a candidate for the draw library.
1172
+ clipPoly: (ctx: CanvasRenderingContext2D, offset: XYCoords, scale: XYCoords, vertices: Array<XYCoords>): void => {
1173
+ ctx.beginPath();
1174
+ // Set clip mask
1175
+ ctx.moveTo(offset.x + vertices[0].x * scale.x, offset.y + vertices[0].y * scale.y);
1176
+ for (var i = 1; i < vertices.length; i++) {
1177
+ const vert: XYCoords = vertices[i];
1178
+ ctx.lineTo(offset.x + vert.x * scale.x, offset.y + vert.y * scale.y);
1179
+ }
1180
+ ctx.closePath();
1181
+ ctx.clip();
1182
+ }
1183
+ };
995
1184
  }
package/src/ts/drawgl.ts CHANGED
@@ -6,7 +6,10 @@
6
6
  * @modified 2020-10-15 Re-added the text() function.
7
7
  * @modified 2021-01-24 Added the `setCurrentId` function.
8
8
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
9
- * @version 0.0.5
9
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
10
+ * @modified 2022-02-03 Added the `cross(...)` function.
11
+ * @modified 2022-03-27 Added the `texturedPoly` function.
12
+ * @version 0.0.7
10
13
  **/
11
14
 
12
15
  import { CubicBezierCurve } from "./CubicBezierCurve";
@@ -22,6 +25,7 @@ import {
22
25
  FontStyle,
23
26
  FontWeight
24
27
  } from "./interfaces";
28
+ import { Bounds } from "./Bounds";
25
29
 
26
30
  /**
27
31
  * @classdesc A wrapper class for basic drawing operations. This is the WebGL
@@ -283,6 +287,25 @@ export class drawutilsgl implements DrawLib<void> {
283
287
  // NOT YET IMPLEMENTED
284
288
  }
285
289
 
290
+ /**
291
+ * Draw an image at the given position with the given size.<br>
292
+ * <br>
293
+ * Note: SVG images may have resizing issues at the moment.Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
294
+ *
295
+ * @method texturedPoly
296
+ * @param {Image} textureImage - The image object to draw.
297
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
298
+ * @param {Polygon} polygon - The polygon to use as clip path.
299
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
300
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
301
+ * @return {void}
302
+ * @instance
303
+ * @memberof drawutilsgl
304
+ **/
305
+ texturedPoly(textureImage: HTMLImageElement, textureSize: Bounds, polygon: Polygon, polygonPosition: Vertex, rotation: number) {
306
+ // NOT YET IMPLEMENTED
307
+ }
308
+
286
309
  // +---------------------------------------------------------------------------------
287
310
  // | This is the final helper function for drawing and filling stuff. It is not
288
311
  // | intended to be used from the outside.
@@ -588,11 +611,30 @@ export class drawutilsgl implements DrawLib<void> {
588
611
  * @param {XYCoords} center - The center of the crosshair.
589
612
  * @param {number} radius - The radius of the crosshair.
590
613
  * @param {string} color - The CSS color to draw the crosshair with.
614
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
615
+ * @return {void}
616
+ * @instance
617
+ * @memberof drawutils
618
+ */
619
+ crosshair(center: XYCoords, radius: number, color: string, lineWidth?: number) {
620
+ // NOT YET IMPLEMENTED
621
+ }
622
+
623
+ /**
624
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
625
+ * <br>
626
+ * Note that the x's radius will not be affected by scaling.
627
+ *
628
+ * @method crosshair
629
+ * @param {XYCoords} center - The center of the crosshair.
630
+ * @param {number} radius - The radius of the crosshair.
631
+ * @param {string} color - The CSS color to draw the crosshair with.
632
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
591
633
  * @return {void}
592
634
  * @instance
593
635
  * @memberof drawutils
594
636
  */
595
- crosshair(center: XYCoords, radius: number, color: string) {
637
+ cross(center: XYCoords, radius: number, color: string, lineWidth?: number) {
596
638
  // NOT YET IMPLEMENTED
597
639
  }
598
640