plotboilerplate 1.18.0 → 1.19.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 (95) hide show
  1. package/dist/index.esm.js +166 -39
  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 +164 -37
  8. package/dist/plotboilerplate.min.js +1 -1
  9. package/package.json +1 -1
  10. package/src/cjs/Bounds.d.ts +11 -1
  11. package/src/cjs/Bounds.js +13 -1
  12. package/src/cjs/Bounds.js.map +1 -1
  13. package/src/cjs/CubicBezierCurve.d.ts +20 -3
  14. package/src/cjs/CubicBezierCurve.js +25 -2
  15. package/src/cjs/CubicBezierCurve.js.map +1 -1
  16. package/src/cjs/Line.d.ts +46 -4
  17. package/src/cjs/Line.js +60 -3
  18. package/src/cjs/Line.js.map +1 -1
  19. package/src/cjs/PlotBoilerplate.d.ts +4 -2
  20. package/src/cjs/PlotBoilerplate.js +44 -28
  21. package/src/cjs/PlotBoilerplate.js.map +1 -1
  22. package/src/cjs/Polygon.js +1 -1
  23. package/src/cjs/Polygon.js.map +1 -1
  24. package/src/cjs/Vector.d.ts +14 -3
  25. package/src/cjs/Vector.js +21 -2
  26. package/src/cjs/Vector.js.map +1 -1
  27. package/src/cjs/interfaces/additionals.d.ts +95 -0
  28. package/src/cjs/interfaces/additionals.js +3 -0
  29. package/src/cjs/interfaces/additionals.js.map +1 -0
  30. package/src/cjs/interfaces/core.d.ts +4 -0
  31. package/src/cjs/interfaces/core.js +1 -0
  32. package/src/cjs/interfaces/core.js.map +1 -1
  33. package/src/cjs/interfaces/index.d.ts +1 -0
  34. package/src/cjs/interfaces/index.js +1 -0
  35. package/src/cjs/interfaces/index.js.map +1 -1
  36. package/src/cjs/utils/algorithms/arrayShuffle.d.ts +8 -0
  37. package/src/cjs/utils/algorithms/arrayShuffle.js +15 -0
  38. package/src/cjs/utils/algorithms/arrayShuffle.js.map +1 -0
  39. package/src/cjs/utils/algorithms/detectPaths.d.ts +20 -0
  40. package/src/cjs/utils/algorithms/detectPaths.js +169 -0
  41. package/src/cjs/utils/algorithms/detectPaths.js.map +1 -0
  42. package/src/cjs/utils/datastructures/GenericPath.d.ts +75 -0
  43. package/src/cjs/utils/datastructures/GenericPath.js +105 -0
  44. package/src/cjs/utils/datastructures/GenericPath.js.map +1 -0
  45. package/src/cjs/utils/datastructures/GirihTile.d.ts +1 -1
  46. package/src/esm/Bounds.d.ts +11 -1
  47. package/src/esm/Bounds.js +13 -1
  48. package/src/esm/Bounds.js.map +1 -1
  49. package/src/esm/CubicBezierCurve.d.ts +20 -3
  50. package/src/esm/CubicBezierCurve.js +25 -2
  51. package/src/esm/CubicBezierCurve.js.map +1 -1
  52. package/src/esm/Line.d.ts +46 -4
  53. package/src/esm/Line.js +60 -3
  54. package/src/esm/Line.js.map +1 -1
  55. package/src/esm/PlotBoilerplate.d.ts +4 -2
  56. package/src/esm/PlotBoilerplate.js +44 -28
  57. package/src/esm/PlotBoilerplate.js.map +1 -1
  58. package/src/esm/Polygon.js +1 -1
  59. package/src/esm/Polygon.js.map +1 -1
  60. package/src/esm/Vector.d.ts +13 -2
  61. package/src/esm/Vector.js +23 -4
  62. package/src/esm/Vector.js.map +1 -1
  63. package/src/esm/interfaces/additionals.d.ts +95 -0
  64. package/src/esm/interfaces/additionals.js +2 -0
  65. package/src/esm/interfaces/additionals.js.map +1 -0
  66. package/src/esm/interfaces/core.d.ts +4 -0
  67. package/src/esm/interfaces/core.js +1 -0
  68. package/src/esm/interfaces/core.js.map +1 -1
  69. package/src/esm/interfaces/index.d.ts +1 -0
  70. package/src/esm/interfaces/index.js +1 -0
  71. package/src/esm/interfaces/index.js.map +1 -1
  72. package/src/esm/utils/algorithms/arrayShuffle.d.ts +8 -0
  73. package/src/esm/utils/algorithms/arrayShuffle.js +11 -0
  74. package/src/esm/utils/algorithms/arrayShuffle.js.map +1 -0
  75. package/src/esm/utils/algorithms/detectPaths.d.ts +20 -0
  76. package/src/esm/utils/algorithms/detectPaths.js +165 -0
  77. package/src/esm/utils/algorithms/detectPaths.js.map +1 -0
  78. package/src/esm/utils/datastructures/GenericPath.d.ts +75 -0
  79. package/src/esm/utils/datastructures/GenericPath.js +100 -0
  80. package/src/esm/utils/datastructures/GenericPath.js.map +1 -0
  81. package/src/esm/utils/datastructures/GirihTile.d.ts +1 -1
  82. package/src/ts/Bounds.ts +14 -1
  83. package/src/ts/CubicBezierCurve.ts +29 -4
  84. package/src/ts/Line.ts +70 -6
  85. package/src/ts/PlotBoilerplate.ts +47 -32
  86. package/src/ts/Polygon.ts +1 -1
  87. package/src/ts/Vector.ts +24 -4
  88. package/src/ts/interfaces/additionals.ts +105 -0
  89. package/src/ts/interfaces/core.ts +2 -0
  90. package/src/ts/interfaces/index.ts +1 -0
  91. package/src/ts/utils/algorithms/arrayShuffle.ts +11 -0
  92. package/src/ts/utils/algorithms/detectPaths.ts +195 -0
  93. package/src/ts/utils/datastructures/GenericPath.ts +113 -0
  94. package/src/ts/utils/datastructures/GirihTile.ts +1 -1
  95. package/changelog.md +0 -731
@@ -1,4 +1,5 @@
1
1
  export * from "./core";
2
2
  export * from "./DrawLib";
3
3
  export * from "./externals";
4
+ export * from "./additionals";
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Randomize a given array in-place.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2022-10-09
6
+ * @version 1.0.0
7
+ **/
8
+ export declare const arrayShuffle: (arr: Array<any>) => void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Randomize a given array in-place.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2022-10-09
6
+ * @version 1.0.0
7
+ **/
8
+ export const arrayShuffle = (arr) => {
9
+ arr.sort(() => Math.random() - 0.5);
10
+ };
11
+ //# sourceMappingURL=arrayShuffle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrayShuffle.js","sourceRoot":"","sources":["../../../ts/utils/algorithms/arrayShuffle.ts"],"names":[],"mappings":"AAAA;;;;;;IAMI;AAEJ,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAe,EAAQ,EAAE;IACpD,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;AACtC,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A function to detect connected paths on the plane given by a random set of segments.
3
+ *
4
+ * Note that is algorithm operates IN PLACE and will ALTER your INPUT array.
5
+ *
6
+ * @author Ikaros Kappler
7
+ * @version 1.0.0
8
+ * @date 2022-10-17
9
+ */
10
+ import { Path, PathSegment } from "../../interfaces";
11
+ /**
12
+ * Run a path detection on the given set of path segments.
13
+ *
14
+ * Note that the array and some path segments may be altered (like reversal) IN PLACE.
15
+ *
16
+ * @param {Array<PathSegment>} segments - The total set (array) of available path segments.
17
+ * @param {number=1.0} epsilon - (optional) An epsilon to use to tell if two plane points should be considered 'equal'.
18
+ * @returns {Array<GenericPath>} An array containing all detected path (consisting of adjacent path segments of the original set).
19
+ */
20
+ export declare const detectPaths: (segments: Array<PathSegment>, epsilon?: number) => Array<Path>;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * A function to detect connected paths on the plane given by a random set of segments.
3
+ *
4
+ * Note that is algorithm operates IN PLACE and will ALTER your INPUT array.
5
+ *
6
+ * @author Ikaros Kappler
7
+ * @version 1.0.0
8
+ * @date 2022-10-17
9
+ */
10
+ import { GenericPath } from "../datastructures/GenericPath";
11
+ /**
12
+ * A private helper function that initializes the visitation tracking and reverses
13
+ * dangling path ends to connect them with preceding paths.
14
+ *
15
+ * Note that this function alters those dangling path segments IN PLACE!
16
+ *
17
+ * @param segments
18
+ * @param epsilon
19
+ * @returns
20
+ */
21
+ const initVisitationArray = (segments, epsilon) => {
22
+ const result = []; // { visited: false, hasPredecessor: false }
23
+ for (var i = 0; i < segments.length; i++) {
24
+ result.push({ visited: false, hasPredecessor: false, hasSuccessor: false });
25
+ for (var j = 0; j < segments.length; j++) {
26
+ if (i === j) {
27
+ continue;
28
+ }
29
+ if (segments[i].getStartPoint().distance(segments[j].getEndPoint()) < epsilon ||
30
+ segments[i].getStartPoint().distance(segments[j].getStartPoint()) < epsilon) {
31
+ result[i].hasPredecessor = true;
32
+ }
33
+ if (segments[i].getEndPoint().distance(segments[j].getEndPoint()) < epsilon ||
34
+ segments[i].getEndPoint().distance(segments[j].getStartPoint()) < epsilon) {
35
+ result[i].hasSuccessor = true;
36
+ }
37
+ }
38
+ }
39
+ // After first initialization make sure that no loose path ends are dangling around
40
+ // if the affected path segment has a predecessor (but nu successor).
41
+ //
42
+ // Revert those segments. This makes the actual detection algorithm much easier.
43
+ for (var i = 0; i < segments.length; i++) {
44
+ if (!result[i].hasSuccessor && result[i].hasPredecessor) {
45
+ segments[i] = segments[i].reverse();
46
+ result[i].hasPredecessor = false;
47
+ result[i].hasSuccessor = true;
48
+ }
49
+ }
50
+ return result;
51
+ };
52
+ /**
53
+ * Find the next unvisited path segment (private helper function).
54
+ *
55
+ * There is a special order: starting path segments (those without any predecessor)
56
+ * will be preferred. If no more open paths are available (no starting path segments),
57
+ * then no more unvisited paths are available or all remaining paths are loops (without
58
+ * determined start/end).
59
+ *
60
+ * Doing this keeps us from the need to run a final loop to connect detected sub paths.
61
+ *
62
+ * @param {Array<PathSegment>} segments - The path segments to search in.
63
+ * @param { Array<Visitation>} isSegmentVisited
64
+ * @returns {number} The index of the next unvisited path segment or -1 if no more are available.
65
+ */
66
+ const locateUnvisitedSegment = (segments, isSegmentVisited) => {
67
+ // First run: detect beginnings
68
+ for (var i = 0; i < segments.length; i++) {
69
+ if (!isSegmentVisited[i].hasPredecessor && !isSegmentVisited[i].visited) {
70
+ return i;
71
+ }
72
+ }
73
+ // Second run: if no beginnings exist -> use inner path segment
74
+ for (var i = 0; i < segments.length; i++) {
75
+ if (!isSegmentVisited[i].visited) {
76
+ return i;
77
+ }
78
+ }
79
+ return -1;
80
+ };
81
+ /**
82
+ * Get the next adjacent path segment to the given (current) segment. This is a private
83
+ * helper function.
84
+ *
85
+ * Note that the function will revert the adjacent path segment if required, so the next
86
+ * starting point 'equals' the current ending point.
87
+ *
88
+ * The visitation tracker will be updated if the adjacent segment was found.
89
+ *
90
+ * @param {Array<PathSegment>} segments - The total set of available path segments (visited and invisited).
91
+ * @param {Array<Visitation>} isSegmentVisited - A tracker of visited path segments so far.
92
+ * @param {PathSegment} currentSegment - The current path segment to find the adjacent segment for.
93
+ * @param {number} epsilon - The epsilon to use to detect 'equal' start/end points. Must be >= 0.
94
+ * @returns {PathSegment | null} The next adjacent path segment of null if no such exists.
95
+ */
96
+ const getAdjacentSegment = (segments, isSegmentVisited, currentSegment, epsilon) => {
97
+ for (var j = 0; j < segments.length; j++) {
98
+ if (isSegmentVisited[j].visited) {
99
+ continue;
100
+ }
101
+ var nextSegment = segments[j];
102
+ // [start]---[end] [start]---[end]
103
+ if (currentSegment.getEndPoint().distance(nextSegment.getStartPoint()) < epsilon) {
104
+ isSegmentVisited[j].visited = true;
105
+ return nextSegment;
106
+ }
107
+ // [start]---[end] [end]---[start]
108
+ else if (currentSegment.getEndPoint().distance(nextSegment.getEndPoint()) < epsilon) {
109
+ isSegmentVisited[j].visited = true;
110
+ return nextSegment.reverse();
111
+ }
112
+ }
113
+ return null;
114
+ };
115
+ /**
116
+ * A private helper function to find the adjacent full path for the given path segment,
117
+ * considering the current path segment is a starting segment (or one inside a loop).
118
+ *
119
+ * @param {Array<PathSegment>} segments - The total set of available path segments.
120
+ * @param { Array<Visitation>} isSegmentVisited - A tracker to determine which segments have already been visited.
121
+ * @param {number} currentSegmentIndex - The index of the current segments to find the containing path for.
122
+ * @param {number} epsilon - The epsilon to use to determine 'equal' path points. Must be >= 0.
123
+ * @returns {GenericPath} The dected path which consists at least of the current path segment.
124
+ */
125
+ const detectAdjacentPath = (segments, isSegmentVisited, currentSegmentIndex, epsilon) => {
126
+ var currentSegment = segments[currentSegmentIndex];
127
+ isSegmentVisited[currentSegmentIndex].visited = true;
128
+ const path = new GenericPath(currentSegment); // { segments: [currentSegment], reverse };
129
+ var i = 0;
130
+ // A safety break if something goes wrong
131
+ while (i < segments.length && currentSegment) {
132
+ currentSegment = getAdjacentSegment(segments, isSegmentVisited, currentSegment, epsilon);
133
+ if (currentSegment) {
134
+ path.segments.push(currentSegment);
135
+ }
136
+ i++;
137
+ }
138
+ return path;
139
+ };
140
+ /**
141
+ * Run a path detection on the given set of path segments.
142
+ *
143
+ * Note that the array and some path segments may be altered (like reversal) IN PLACE.
144
+ *
145
+ * @param {Array<PathSegment>} segments - The total set (array) of available path segments.
146
+ * @param {number=1.0} epsilon - (optional) An epsilon to use to tell if two plane points should be considered 'equal'.
147
+ * @returns {Array<GenericPath>} An array containing all detected path (consisting of adjacent path segments of the original set).
148
+ */
149
+ export const detectPaths = (segments, epsilon) => {
150
+ const eps = typeof epsilon === "undefined" || epsilon < 0 ? 1.0 : epsilon;
151
+ const isSegmentVisited = initVisitationArray(segments, eps);
152
+ const resultPaths = [];
153
+ var nextSegmentIndex = -1;
154
+ var i = 0;
155
+ while ((nextSegmentIndex = locateUnvisitedSegment(segments, isSegmentVisited)) !== -1 && i < segments.length) {
156
+ isSegmentVisited[nextSegmentIndex].visited = true;
157
+ // A safety break (to avoid infinited loops during development).
158
+ i++;
159
+ const path = detectAdjacentPath(segments, isSegmentVisited, nextSegmentIndex, eps);
160
+ i += path.getSegmentCount() - 1;
161
+ resultPaths.push(path);
162
+ }
163
+ return resultPaths;
164
+ };
165
+ //# sourceMappingURL=detectPaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectPaths.js","sourceRoot":"","sources":["../../../ts/utils/algorithms/detectPaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAW5D;;;;;;;;;GASG;AACH,MAAM,mBAAmB,GAAG,CAAC,QAA4B,EAAE,OAAe,EAAqB,EAAE;IAC/F,MAAM,MAAM,GAAsB,EAAE,CAAC,CAAC,4CAA4C;IAClF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,IAAI,CAAC,KAAK,CAAC,EAAE;gBACX,SAAS;aACV;YACD,IACE,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO;gBACzE,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,GAAG,OAAO,EAC3E;gBACA,MAAM,CAAC,CAAC,CAAC,CAAC,cAAc,GAAG,IAAI,CAAC;aACjC;YACD,IACE,QAAQ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AE,GAAG,CAAC,CAAC;QACnF,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;QAChC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACxB;IACD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @author Ikaros Kappler
3
+ * @version 1.0.0
4
+ * @date 2022-10-17
5
+ */
6
+ import { Path, PathSegment } from "../../interfaces/additionals";
7
+ import { Vertex } from "../../Vertex";
8
+ export declare class GenericPath implements Path {
9
+ segments: Array<PathSegment>;
10
+ constructor(startSegment: PathSegment);
11
+ /**
12
+ * Get the number of segments in this path.
13
+ *
14
+ * @method getSegmentCount
15
+ * @memberof Path
16
+ * @return {number} The number (integer) of path segments.
17
+ */
18
+ getSegmentCount(): number;
19
+ /**
20
+ * Get the path segment at the given index.
21
+ *
22
+ * @method getSegmentAt
23
+ * @memberof Path
24
+ * @return {PathSegment} The paths segment at the given index.
25
+ */
26
+ getSegmentAt(index: number): PathSegment;
27
+ /**
28
+ * Create a deep clone of this path.
29
+ *
30
+ * @method clone
31
+ * @memberof Path
32
+ * @return {Path} A deep clone/copy of this path.
33
+ */
34
+ clone(): GenericPath;
35
+ /**
36
+ * Reverse this path (swap start and end and thus – the direction) in-place.
37
+ *
38
+ * @method reverse
39
+ * @memberof Path
40
+ * @return {PathSegment} This path instance.
41
+ */
42
+ reverse(): this;
43
+ /**
44
+ * Get the start point of this path segment.
45
+ *
46
+ * @method getStartPoint
47
+ * @memberof PathSegment
48
+ * @return {Vertex} The start point of this path segment.
49
+ */
50
+ getStartPoint(): Vertex;
51
+ /**
52
+ * Get the end point of this path segment.
53
+ *
54
+ * @method getEndPoint
55
+ * @memberof PathSegment
56
+ * @return {Vertex} The end point of this path segment.
57
+ */
58
+ getEndPoint(): Vertex;
59
+ /**
60
+ * Get the tangent's end point at the start point of this segment.
61
+ *
62
+ * @method getStartTangent
63
+ * @memberof PathSegment
64
+ * @return {Vertex} The end point of the starting point's tangent.
65
+ */
66
+ getStartTangent(): Vertex;
67
+ /**
68
+ * Get the tangent's end point at the end point of this segment.
69
+ *
70
+ * @method getEndTangent
71
+ * @memberof PathSegment
72
+ * @return {Vertex} The end point of the ending point's tangent.
73
+ */
74
+ getEndTangent(): Vertex;
75
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @author Ikaros Kappler
3
+ * @version 1.0.0
4
+ * @date 2022-10-17
5
+ */
6
+ export class GenericPath {
7
+ constructor(startSegment) {
8
+ this.segments = [startSegment];
9
+ }
10
+ /**
11
+ * Get the number of segments in this path.
12
+ *
13
+ * @method getSegmentCount
14
+ * @memberof Path
15
+ * @return {number} The number (integer) of path segments.
16
+ */
17
+ getSegmentCount() {
18
+ return this.segments.length;
19
+ }
20
+ /**
21
+ * Get the path segment at the given index.
22
+ *
23
+ * @method getSegmentAt
24
+ * @memberof Path
25
+ * @return {PathSegment} The paths segment at the given index.
26
+ */
27
+ getSegmentAt(index) {
28
+ return this.segments[index];
29
+ }
30
+ /**
31
+ * Create a deep clone of this path.
32
+ *
33
+ * @method clone
34
+ * @memberof Path
35
+ * @return {Path} A deep clone/copy of this path.
36
+ */
37
+ clone() {
38
+ const newPath = new GenericPath(this.segments[this.segments.length - 1].clone().reverse());
39
+ for (var i = this.segments.length - 2; i >= 0; i--) {
40
+ newPath.segments.push(this.segments[i].clone().reverse());
41
+ }
42
+ return newPath;
43
+ }
44
+ /**
45
+ * Reverse this path (swap start and end and thus – the direction) in-place.
46
+ *
47
+ * @method reverse
48
+ * @memberof Path
49
+ * @return {PathSegment} This path instance.
50
+ */
51
+ reverse() {
52
+ const newSegments = [];
53
+ for (var i = this.segments.length - 1; i >= 0; i--) {
54
+ newSegments.push(this.segments[i].reverse());
55
+ }
56
+ this.segments = newSegments;
57
+ return this;
58
+ }
59
+ /**
60
+ * Get the start point of this path segment.
61
+ *
62
+ * @method getStartPoint
63
+ * @memberof PathSegment
64
+ * @return {Vertex} The start point of this path segment.
65
+ */
66
+ getStartPoint() {
67
+ return this.segments[0].getStartPoint();
68
+ }
69
+ /**
70
+ * Get the end point of this path segment.
71
+ *
72
+ * @method getEndPoint
73
+ * @memberof PathSegment
74
+ * @return {Vertex} The end point of this path segment.
75
+ */
76
+ getEndPoint() {
77
+ return this.segments[this.segments.length - 1].getEndPoint();
78
+ }
79
+ /**
80
+ * Get the tangent's end point at the start point of this segment.
81
+ *
82
+ * @method getStartTangent
83
+ * @memberof PathSegment
84
+ * @return {Vertex} The end point of the starting point's tangent.
85
+ */
86
+ getStartTangent() {
87
+ return this.segments[0].getStartTangent();
88
+ }
89
+ /**
90
+ * Get the tangent's end point at the end point of this segment.
91
+ *
92
+ * @method getEndTangent
93
+ * @memberof PathSegment
94
+ * @return {Vertex} The end point of the ending point's tangent.
95
+ */
96
+ getEndTangent() {
97
+ return this.segments[this.segments.length - 1].getEndTangent();
98
+ }
99
+ }
100
+ //# sourceMappingURL=GenericPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericPath.js","sourceRoot":"","sources":["../../../ts/utils/datastructures/GenericPath.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,OAAO,WAAW;IAGtB,YAAY,YAAyB;QACnC,IAAI,CAAC,QAAQ,GAAG,CAAC,YAAY,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,YAAY,CAAC,KAAa;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK;QACH,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3F,K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
225
  * @param {Polygon} neighbourTile - The polygon (or tile) you want to find adjacency for at the specified edge.
226
226
  * @return {Polygon|null} the passed tile itself if adjacency was found, null otherwise.
227
227
  */
228
- transformTilePositionToAdjacency<P extends Polygon>(baseEdgeIndex: number, neighbourTile: P): P;
228
+ transformTilePositionToAdjacency<P extends Polygon>(baseEdgeIndex: number, neighbourTile: P): P | null;
229
229
  /**
230
230
  * Get the inner tile polygon at the given index.
231
231
  * This function applies MOD to the index.
package/src/ts/Bounds.ts CHANGED
@@ -6,7 +6,8 @@
6
6
  * @modified 2021-02-02 Added the `toPolygon` method.
7
7
  * @modified 2021-06-21 (mid-summer) Added `getCenter` method.
8
8
  * @modified 2022-02-01 Added the `toString` function.
9
- * @version 1.4.0
9
+ * @modified 2022-10-09 Added the `fromDimension` function.
10
+ * @version 1.5.0
10
11
  **/
11
12
 
12
13
  import { Polygon } from "./Polygon";
@@ -154,4 +155,16 @@ export class Bounds implements IBounds, XYDimension {
154
155
  }
155
156
  return new Bounds(new Vertex(xMin, yMin), new Vertex(xMax, yMax));
156
157
  }
158
+
159
+ /**
160
+ * Create a new `Bounds` instance just from `width` and `height`, located at (0,0) or the optionally given origin.
161
+ *
162
+ * @param {number} width - The width of the bounds
163
+ * @param {number} height - The height of the bounds
164
+ * @param {XYCoords={x:0,y:0}} origin - [optional] A origin to locate the new Bounds object at.
165
+ * @returns {Bounds} A new `Bounds` instance width given width and height, located at (0,0) or the given origin..
166
+ */
167
+ static fromDimension(width: number, height: number, origin?: XYCoords): Bounds {
168
+ return new Bounds(origin ?? { x: 0, y: 0 }, { x: (origin ? origin.x : 0) + width, y: (origin ? origin.y : 0) + height });
169
+ }
157
170
  } // END class bounds
@@ -20,7 +20,8 @@
20
20
  * @modified 2021-01-20 Added UID.
21
21
  * @modified 2022-02-02 Added the `destroy` method.
22
22
  * @modified 2022-02-02 Cleared the `toSVGPathData` function (deprecated). Use `drawutilssvg` instead.
23
- * @version 2.6.0
23
+ * @modified 2022-10-17 The `CubicBezierCurve` class now implements the new `PathSegment` interface.
24
+ * @version 2.7.1
24
25
  *
25
26
  * @file CubicBezierCurve
26
27
  * @public
@@ -30,7 +31,7 @@ import { Bounds } from "./Bounds";
30
31
  import { UIDGenerator } from "./UIDGenerator";
31
32
  import { Vertex } from "./Vertex";
32
33
  import { Vector } from "./Vector";
33
- import { XYCoords, UID } from "./interfaces";
34
+ import { XYCoords, UID, PathSegment } from "./interfaces";
34
35
 
35
36
  /**
36
37
  * @classdesc A refactored cubic bezier curve class.
@@ -42,7 +43,7 @@ import { XYCoords, UID } from "./interfaces";
42
43
  * @requires UID
43
44
  * @requires UIDGenerator
44
45
  */
45
- export class CubicBezierCurve {
46
+ export class CubicBezierCurve implements PathSegment {
46
47
  /** @constant {number} */
47
48
  static readonly START_POINT: number = 0;
48
49
  /** @constant {number} */
@@ -157,7 +158,7 @@ export class CubicBezierCurve {
157
158
  // An array of floats
158
159
  this.segmentLengths = [];
159
160
  // float
160
- this.arcLength = null;
161
+ // this.arcLength = null;
161
162
 
162
163
  this.updateArcLengths();
163
164
  }
@@ -627,6 +628,30 @@ export class CubicBezierCurve {
627
628
  );
628
629
  }
629
630
 
631
+ //---BEGIN PathSegment-------------------------
632
+ /**
633
+ * Get the tangent's end point at the start point of this segment.
634
+ *
635
+ * @method getStartTangent
636
+ * @memberof PathSegment
637
+ * @return {Vertex} The end point of the starting point's tangent.
638
+ */
639
+ getStartTangent(): Vertex {
640
+ return this.startControlPoint;
641
+ }
642
+
643
+ /**
644
+ * Get the tangent's end point at the end point of this segment.
645
+ *
646
+ * @method getEndTangent
647
+ * @memberof PathSegment
648
+ * @return {Vertex} The end point of the ending point's tangent.
649
+ */
650
+ getEndTangent(): Vertex {
651
+ return this.endControlPoint;
652
+ }
653
+ //---END PathSegment-------------------------
654
+
630
655
  /**
631
656
  * Check if this and the specified curve are equal.<br>
632
657
  * <br>
package/src/ts/Line.ts CHANGED
@@ -13,7 +13,9 @@
13
13
  * @modified 2020-03-23 Ported to Typescript from JS.
14
14
  * @modified 2020-12-04 The `intersection` function returns undefined if both lines are parallel.
15
15
  * @modified 2022-02-02 Added the `destroy` method.
16
- * @version 2.2.0
16
+ * @modified 2022-10-09 Changed the actual return value of the `intersection` function to null (was undefined before).
17
+ * @modified 2022-10-17 Adding these methods from the `PathSegment` interface: getStartPoint, getEndPoint, revert.
18
+ * @version 2.3.0
17
19
  *
18
20
  * @file Line
19
21
  * @public
@@ -21,7 +23,7 @@
21
23
 
22
24
  import { VertTuple } from "./VertTuple";
23
25
  import { Vertex } from "./Vertex";
24
- import { SVGSerializable } from "./interfaces";
26
+ import { PathSegment, SVGSerializable } from "./interfaces";
25
27
 
26
28
  /**
27
29
  * @classdesc A line consists of two vertices a and b.<br>
@@ -31,7 +33,7 @@ import { SVGSerializable } from "./interfaces";
31
33
  *
32
34
  * @requires Vertex
33
35
  */
34
- export class Line extends VertTuple<Line> implements SVGSerializable {
36
+ export class Line extends VertTuple<Line> implements SVGSerializable, PathSegment {
35
37
  /**
36
38
  * Required to generate proper CSS classes and other class related IDs.
37
39
  **/
@@ -59,9 +61,11 @@ export class Line extends VertTuple<Line> implements SVGSerializable {
59
61
  * @memberof Line
60
62
  **/
61
63
  // !!! DO NOT MOVE TO VertTuple
62
- intersection(line: Line): Vertex | undefined {
64
+ intersection(line: Line): Vertex | null {
63
65
  const denominator: number = this.denominator(line);
64
- if (denominator == 0) return null;
66
+ if (denominator == 0) {
67
+ return null;
68
+ }
65
69
 
66
70
  let a: number = this.a.y - line.a.y;
67
71
  let b: number = this.a.x - line.a.x;
@@ -75,10 +79,70 @@ export class Line extends VertTuple<Line> implements SVGSerializable {
75
79
  const y: number = this.a.y + a * (this.b.y - this.a.y);
76
80
 
77
81
  if (isNaN(a) || isNaN(x) || isNaN(y)) {
78
- return undefined;
82
+ return null;
79
83
  }
80
84
 
81
85
  // if we cast these lines infinitely in both directions, they intersect here:
82
86
  return new Vertex(x, y);
83
87
  }
88
+
89
+ //--- Implement PathSegment ---
90
+ /**
91
+ * Get the start point of this path segment.
92
+ *
93
+ * @method getStartPoint
94
+ * @memberof PathSegment
95
+ * @return {Vertex} The start point of this path segment.
96
+ */
97
+ getStartPoint(): Vertex {
98
+ return this.a;
99
+ }
100
+
101
+ /**
102
+ * Get the end point of this path segment.
103
+ *
104
+ * @method getEndPoint
105
+ * @memberof PathSegment
106
+ * @return {Vertex} The end point of this path segment.
107
+ */
108
+ getEndPoint(): Vertex {
109
+ return this.b;
110
+ }
111
+
112
+ /**
113
+ * Get the tangent's end point at the start point of this segment.
114
+ *
115
+ * @method getStartTangent
116
+ * @memberof PathSegment
117
+ * @return {Vertex} The end point of the starting point's tangent.
118
+ */
119
+ getStartTangent(): Vertex {
120
+ return this.b;
121
+ }
122
+
123
+ /**
124
+ * Get the tangent's end point at the end point of this segment.
125
+ *
126
+ * @method getEndTangent
127
+ * @memberof PathSegment
128
+ * @return {Vertex} The end point of the ending point's tangent.
129
+ */
130
+ getEndTangent(): Vertex {
131
+ return this.a;
132
+ }
133
+
134
+ /**
135
+ * Inverse this path segment (in-place) and return this same instance (useful for chaining).
136
+ *
137
+ * @method reverse
138
+ * @memberof PathSegment
139
+ * @return {PathSegment} This path segment instance (for chaining).
140
+ */
141
+ reverse(): Line {
142
+ var tmp = this.a;
143
+ this.a = this.b;
144
+ this.b = tmp;
145
+ return this;
146
+ }
147
+ //--- END Implement PathSegment ---
84
148
  }