plotboilerplate 1.12.10 → 1.13.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 (73) hide show
  1. package/README.md +4 -1
  2. package/changelog.md +13 -0
  3. package/dist/index.esm.js +220 -26
  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 +234 -25
  10. package/dist/plotboilerplate.min.js +1 -1
  11. package/package.json +1 -1
  12. package/src/cjs/PBText.d.ts +116 -0
  13. package/src/cjs/PBText.js +66 -0
  14. package/src/cjs/PBText.js.map +1 -0
  15. package/src/cjs/PlotBoilerplate.d.ts +2 -1
  16. package/src/cjs/PlotBoilerplate.js +27 -1
  17. package/src/cjs/PlotBoilerplate.js.map +1 -1
  18. package/src/cjs/draw.d.ts +30 -2
  19. package/src/cjs/draw.js +51 -6
  20. package/src/cjs/draw.js.map +1 -1
  21. package/src/cjs/drawgl.d.ts +29 -2
  22. package/src/cjs/drawgl.js +21 -4
  23. package/src/cjs/drawgl.js.map +1 -1
  24. package/src/cjs/drawutilssvg.d.ts +25 -7
  25. package/src/cjs/drawutilssvg.js +62 -14
  26. package/src/cjs/drawutilssvg.js.map +1 -1
  27. package/src/cjs/entry.js +1 -0
  28. package/src/cjs/index.d.ts +1 -0
  29. package/src/cjs/index.js +1 -0
  30. package/src/cjs/index.js.map +1 -1
  31. package/src/cjs/interfaces/DrawLib.d.ts +27 -6
  32. package/src/cjs/interfaces/DrawLib.js +3 -0
  33. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  34. package/src/cjs/interfaces/core.d.ts +9 -1
  35. package/src/cjs/interfaces/core.js +1 -0
  36. package/src/cjs/interfaces/core.js.map +1 -1
  37. package/src/esm/PBText.d.ts +116 -0
  38. package/src/esm/PBText.js +61 -0
  39. package/src/esm/PBText.js.map +1 -0
  40. package/src/esm/PlotBoilerplate.d.ts +2 -1
  41. package/src/esm/PlotBoilerplate.js +27 -1
  42. package/src/esm/PlotBoilerplate.js.map +1 -1
  43. package/src/esm/draw.d.ts +30 -2
  44. package/src/esm/draw.js +51 -6
  45. package/src/esm/draw.js.map +1 -1
  46. package/src/esm/drawgl.d.ts +29 -2
  47. package/src/esm/drawgl.js +21 -4
  48. package/src/esm/drawgl.js.map +1 -1
  49. package/src/esm/drawutilssvg.d.ts +25 -7
  50. package/src/esm/drawutilssvg.js +62 -14
  51. package/src/esm/drawutilssvg.js.map +1 -1
  52. package/src/esm/entry.js +1 -0
  53. package/src/esm/index.d.ts +1 -0
  54. package/src/esm/index.js +1 -0
  55. package/src/esm/index.js.map +1 -1
  56. package/src/esm/interfaces/DrawLib.d.ts +27 -6
  57. package/src/esm/interfaces/DrawLib.js +3 -0
  58. package/src/esm/interfaces/DrawLib.js.map +1 -1
  59. package/src/esm/interfaces/core.d.ts +9 -1
  60. package/src/esm/interfaces/core.js +1 -0
  61. package/src/esm/interfaces/core.js.map +1 -1
  62. package/src/ts/PBText.ts +147 -0
  63. package/src/ts/PlotBoilerplate.ts +24 -1
  64. package/src/ts/draw.ts +71 -8
  65. package/src/ts/drawgl.ts +48 -8
  66. package/src/ts/drawutilssvg.ts +94 -17
  67. package/src/ts/index.ts +1 -0
  68. package/src/ts/interfaces/DrawLib.ts +30 -4
  69. package/src/ts/interfaces/core.ts +9 -0
  70. package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
  71. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
  72. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
  73. package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
@@ -13,6 +13,7 @@
13
13
  * @modified 2021-05-31 Added the `drawLib.setConfiguration` function.
14
14
  * @modified 2021-05-31 Splitted the large interfaces.ts file into this one and others.
15
15
  * @modified 2021-06-21 Added `IBounds.getCenter()`.
16
+ * @modified 2021-11-16 Added `text` options to the `DrawConfig`.
16
17
  **/
17
18
 
18
19
  import { Vertex } from "../Vertex";
@@ -28,6 +29,7 @@ import { BezierPath } from "../BezierPath";
28
29
  import { Line } from "../Line";
29
30
  import { PlotBoilerplate } from "../PlotBoilerplate";
30
31
  import { DrawLib } from "./DrawLib";
32
+ import { PBText } from "../PBText";
31
33
 
32
34
  /**
33
35
  * @classdesc Coordinates (x,y) on the plane.
@@ -73,6 +75,7 @@ export type Drawable =
73
75
  | Circle
74
76
  | CircleSector
75
77
  | PBImage
78
+ | PBText
76
79
  | VEllipse
77
80
  | VEllipseSector
78
81
  | Polygon
@@ -189,6 +192,12 @@ export interface DrawConfig {
189
192
  line: DrawSettings;
190
193
  vector: DrawSettings;
191
194
  image: DrawSettings;
195
+ text: {
196
+ color: string;
197
+ lineWidth: number;
198
+ fill?: boolean;
199
+ anchor?: boolean;
200
+ };
192
201
  }
193
202
 
194
203
  /** This is a fix for the problem, that the constructor's "name" attribute is not
@@ -1,5 +0,0 @@
1
- /**
2
- *
3
- */
4
-
5
- const polygonClearDuplicateVertices
@@ -1,45 +0,0 @@
1
- /**
2
- * @requires Line
3
- * @requires Vertex
4
- *
5
- * @author Ikaros Kappler
6
- * @date 2020-12-04
7
- */
8
-
9
-
10
- /**
11
- * Collect all self-intersection points of the given polygon.
12
- *
13
- * @name findPolygonSelfIntersections
14
- * @param {Array<Vertex>} polygon
15
- * @return Array<Vertex>
16
- */
17
- var findPolygonSelfIntersections = function( polygon ) {
18
- var pointList = [];
19
- var lineA = new Line( new Vertex(), new Vertex() );
20
- var lineB = new Line( new Vertex(), new Vertex() );
21
- for( var a = 0; a < polygon.vertices.length; a++ ) {
22
- lineA.a.set( polygon.getVertexAt(a) );
23
- lineA.b.set( polygon.getVertexAt(a+1) );
24
- for( var b = 0; b < polygon.vertices.length; b++ ) {
25
- // Same edge or neighbour edges intersect by definition.
26
- // Skip them.
27
- if( a == b || a+1 == b || a == b+1
28
- || (a==0&&b+1==polygon.vertices.length) || (b==0&&a+1==polygon.vertices.length) )
29
- continue;
30
- lineB.a.set( polygon.getVertexAt(b) );
31
- lineB.b.set( polygon.getVertexAt(b+1) );
32
-
33
- // Commpute the intersection point of the (infinite) lines.
34
- // The point is undefined if and only if both line are parallel (co-linear).
35
- const intersectionPoint = lineA.intersection(lineB);
36
-
37
- // Check if the intersection point is on both (finite) edges of the polygon.
38
- if( intersectionPoint
39
- && lineA.hasPoint(intersectionPoint) && lineB.hasPoint(intersectionPoint) ) {
40
- pointList.push( intersectionPoint );
41
- }
42
- }
43
- }
44
- return pointList;
45
- };
@@ -1,113 +0,0 @@
1
- /**
2
- * This function cuts a given self-intersecting polygon into non-self-intersecting
3
- * sub polygons.
4
- *
5
- * The algorithm only works for non-self-overlapping polygons.
6
- * Please note that the union set of the sub polygons themselves will _not_ be disjunct if
7
- * the input polyon overlaps with itself!
8
- *
9
- *
10
- * @requires Line
11
- * @requires Vertex
12
- * @requires greinerHormann
13
- *
14
- * @date 2020-12-04
15
- */
16
-
17
- (function(_context) {
18
-
19
- /**
20
- * @param {Array<Vertex>} vertices
21
- * @param {number=10} maxDepth
22
- */
23
- var splitToNonIntersectingPolygons = function( vertices, maxDepth ) {
24
- if( typeof maxDepth === "undefined" )
25
- maxDepth = 10;
26
- return _splitToNonIntersectingPolygons( vertices, maxDepth );
27
- };
28
-
29
-
30
- var _splitToNonIntersectingPolygons = function( vertices, maxDepth ) {
31
-
32
- if( maxDepth <= 0 ) {
33
- console.log('aborting at max depth');
34
- return [ vertices ];
35
- }
36
-
37
- if( vertices.length <= 3 ) {
38
- // No intersections possible
39
- return [ vertices ];
40
- }
41
-
42
- // var pointList = [];
43
- var n = vertices.length;
44
- var lineA = new Line( new Vertex(), new Vertex() );
45
- var lineB = new Line( new Vertex(), new Vertex() );
46
- for( var a = 0; a < vertices.length; a++ ) {
47
- lineA.a.set( vertices[a] );
48
- lineA.b.set( vertices[(a+1) % n] );
49
- for( var b = 0; b < vertices.length; b++ ) {
50
- // Equal or neighbour edges intersect by definition.
51
- // We ignore them.
52
- if( a == b || a+1 == b || a == b+1 || (a==0&&b+1==vertices.length) || (b==0&&a+1==vertices.length) )
53
- continue;
54
- lineB.a.set( vertices[b] );
55
- lineB.b.set( vertices[(b+1) % n] );
56
-
57
- const intersectionPoint = lineA.intersection(lineB);
58
- // console.log( 'intersectionPoint', intersectionPoint );
59
- if( intersectionPoint && lineA.hasPoint(intersectionPoint) && lineB.hasPoint(intersectionPoint) ) {
60
- // console.log( 'intersection found' );
61
- // pointList.push( intersectionPoint );
62
- // Cut polygon into two here
63
- var split = splitPolygonAt( vertices, a, b, intersectionPoint );
64
-
65
- // Split has 2 elements.
66
- var leftCleaned = _splitToNonIntersectingPolygons( split[0], maxDepth-1 );
67
- var rightCleaned = _splitToNonIntersectingPolygons( split[1], maxDepth-1 );
68
-
69
- return leftCleaned.concat( rightCleaned );
70
- }
71
- }
72
- }
73
- // console.log( 'intersectionPoints', pointList );
74
-
75
- // No intersection found:
76
- // just return a list with the original
77
- // polygon as its only element.
78
- return [ vertices ];
79
- };
80
-
81
-
82
- // Pre: edgeIndexA < edgeIndexB && vertices.length >= 4
83
- var splitPolygonAt = function( vertices, edgeIndexA, edgeIndexB, intersectionPoint ) {
84
-
85
- // console.log( 'split', edgeIndexA, edgeIndexB );
86
-
87
- var first = [];
88
- var second = [];
89
- for( var i = 0; i < vertices.length; i++ ) {
90
- if( i <= edgeIndexA )
91
- first.push( vertices[i] );
92
-
93
- if( i == edgeIndexA ) {
94
- first.push( intersectionPoint );
95
- second.push( intersectionPoint ); // clone???
96
- }
97
-
98
- if( i > edgeIndexA && i <= edgeIndexB )
99
- second.push( vertices[i] );
100
-
101
- if( i > edgeIndexB )
102
- first.push( vertices[i] );
103
-
104
- }
105
-
106
- // console.log( 'split', first, second );
107
-
108
- return [ first, second ];
109
- };
110
-
111
- _context.splitToNonIntersectingPolygons = splitToNonIntersectingPolygons;
112
-
113
- })(globalThis || window);
@@ -1,88 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * The Sutherland-Hodgman convex polygon clipping algorithm.
5
- *
6
- * Converted to Vertex variant {x:number,y:number} by Ikaros Kappler.
7
- *
8
- * @date 2021-01-29
9
- * @version 1.0.0
10
- *
11
- * Original version:
12
- * https://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping#JavaScript
13
- */
14
-
15
-
16
-
17
- (function() {
18
-
19
-
20
- /**
21
- * @param {Vertex}
22
- * @param {Vertex}
23
- **/
24
- var inside = function (_cp1,_cp2,p) {
25
- // console.log('x', _cp1);
26
- return (_cp2.x-_cp1.x)*(p.y-_cp1.y) > (_cp2.y-_cp1.y)*(p.x-_cp1.x);
27
- };
28
-
29
- /**
30
- * @param {Vertex}
31
- * @param {Vertex}
32
- * @param {Vertex}
33
- * @param {Vertex}
34
- */
35
- var intersection = function (_cp1,_cp2,_s,_e) {
36
- var
37
- dc = { x: _cp1.x - _cp2.x,
38
- y : _cp1.y - _cp2.y
39
- },
40
- dp = { x: _s.x - _e.x,
41
- y : _s.y - _e.y
42
- },
43
- n1 = _cp1.x * _cp2.y - _cp1.y * _cp2.x,
44
- n2 = _s.x * _e.y - _s.y * _e.x,
45
- n3 = 1.0 / (dc.x * dp.y - dc.y * dp.x);
46
- return { x : (n1*dp.x - n2*dc.x) * n3,
47
- y : (n1*dp.y - n2*dc.y) * n3
48
- };
49
- };
50
-
51
-
52
- /**
53
- * @param {Array<Vertex>} subjectPolygon
54
- * @param {Array<Vertex>} clipPolygon - Must be convex.
55
- */
56
- var sutherlandHodgman = function(subjectPolygon, clipPolygon) {
57
-
58
- var cp1, cp2, s, e;
59
-
60
- var outputList = subjectPolygon;
61
- cp1 = clipPolygon[clipPolygon.length-1];
62
-
63
- for (var j in clipPolygon) {
64
- var cp2 = clipPolygon[j];
65
- var inputList = outputList;
66
- outputList = [];
67
- s = inputList[inputList.length - 1]; // last on the input list
68
- for (var i in inputList) {
69
- var e = inputList[i];
70
- if (inside(cp1,cp2,e)) {
71
- if (!inside(cp1,cp2,s)) {
72
- outputList.push(intersection(cp1,cp2,s,e));
73
- }
74
- outputList.push(e);
75
- }
76
- else if (inside(cp1,cp2,s)) {
77
- outputList.push(intersection(cp1,cp2,s,e));
78
- }
79
- s = e;
80
- }
81
- cp1 = cp2;
82
- }
83
- return outputList
84
- }
85
-
86
- globalThis.sutherlandHodgman = sutherlandHodgman;
87
-
88
- })();