plotboilerplate 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/changelog.md +8 -0
- package/dist/index.esm.js +144 -42
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +144 -42
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/PlotBoilerplate.js +2 -1
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +22 -1
- package/src/cjs/Polygon.js +102 -39
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Vertex.d.ts +25 -1
- package/src/cjs/Vertex.js +39 -1
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/utils/findInVertexArray.d.ts +19 -0
- package/src/cjs/utils/findInVertexArray.js +29 -0
- package/src/cjs/utils/findInVertexArray.js.map +1 -0
- package/src/esm/PlotBoilerplate.js +2 -1
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +22 -1
- package/src/esm/Polygon.js +102 -39
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Vertex.d.ts +25 -1
- package/src/esm/Vertex.js +39 -1
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/utils/findInVertexArray.d.ts +19 -0
- package/src/esm/utils/findInVertexArray.js +25 -0
- package/src/esm/utils/findInVertexArray.js.map +1 -0
- package/src/ts/PlotBoilerplate.ts +3 -1
- package/src/ts/Polygon.ts +493 -451
- package/src/ts/Vertex.ts +41 -1
- package/src/ts/utils/findInVertexArray.ts +28 -0
- package/src/ts/utils/algorithms/sh-tmp.ts~ +0 -59
package/src/ts/Vertex.ts
CHANGED
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
* @modified 2021-03-01 Changed the second param `center` in the `rotate` function from Vertex to XYCoords.
|
|
25
25
|
* @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
|
|
26
26
|
* @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
|
|
27
|
-
* @
|
|
27
|
+
* @modified 2021-12-17 Added the functions `lerp` and `lerpAbs` for linear interpolations.
|
|
28
|
+
* @version 2.6.0
|
|
28
29
|
*
|
|
29
30
|
* @file Vertex
|
|
30
31
|
* @public
|
|
@@ -421,6 +422,45 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
421
422
|
return this.scaleXY({ x: factor, y: factor }, center);
|
|
422
423
|
}
|
|
423
424
|
|
|
425
|
+
/**
|
|
426
|
+
* Perform a linear interpolation towards the given target vertex.
|
|
427
|
+
* The amount value `t` is relative, `t=0.0` means no change, `t=1.0`
|
|
428
|
+
* means this point will be moved to the exact target position.
|
|
429
|
+
*
|
|
430
|
+
* `t=0.5` will move this point to the middle of the connecting
|
|
431
|
+
* linear segment.
|
|
432
|
+
*
|
|
433
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
434
|
+
* @param {number} t - The relative amount, usually in [0..1], but other values will work, too.
|
|
435
|
+
* @returns
|
|
436
|
+
*/
|
|
437
|
+
lerp(target: XYCoords, t: number): Vertex {
|
|
438
|
+
var diff = this.difference(target);
|
|
439
|
+
// return new Vertex(this.x + diff.x * t, this.y + diff.y * t);
|
|
440
|
+
this.x += diff.x * t;
|
|
441
|
+
this.y += diff.y * t;
|
|
442
|
+
return this;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Perform a linear interpolation towards the given target vertex (absolute variant).
|
|
447
|
+
* The amount value `t` is absolute, which means the lerp amount is a direct distance
|
|
448
|
+
* value. This point will have move the amount of the passed distance `u`.
|
|
449
|
+
*
|
|
450
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
451
|
+
* @param {number} t - The absolute move amount to use to lerping.
|
|
452
|
+
* @returns
|
|
453
|
+
*/
|
|
454
|
+
lerpAbs(target: XYCoords, u: number): Vertex {
|
|
455
|
+
var dist = this.distance(target);
|
|
456
|
+
var diff = this.difference(target);
|
|
457
|
+
var step = { x: diff.x / dist, y: diff.y / dist };
|
|
458
|
+
// return new Vertex(this.x + step.x * u, this.y + step.y * u);
|
|
459
|
+
this.x += step.x * u;
|
|
460
|
+
this.y += step.y * u;
|
|
461
|
+
return this;
|
|
462
|
+
}
|
|
463
|
+
|
|
424
464
|
/**
|
|
425
465
|
* This is a vector-like behavior and 'scales' this vertex
|
|
426
466
|
* towards/from a given center by two independent x- and y- scale factors.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Ikaros Kappler
|
|
3
|
+
* @date 2022-01-10
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Vertex } from "../Vertex";
|
|
8
|
+
import { XYCoords } from "../interfaces";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* In an array of vertices find the first occurence of a specific vertex, using
|
|
12
|
+
* and epsilon tolerance.
|
|
13
|
+
*
|
|
14
|
+
* @param {Array<Vertex>} vertexList - The vertex array to search in.
|
|
15
|
+
* @param {XYCoords} vertex - A vertex/position to search for. This can be any x-y-tuple and does not
|
|
16
|
+
* necessarily need to be an instance of Vertex.
|
|
17
|
+
* @param {number} epsilon - The epsilon tolerance to use (should be >= 0). This is a required param to avoid excessive
|
|
18
|
+
* is-undef checking if this function runs in a loop.
|
|
19
|
+
* @returns {boolean} - The first index of a vertex that matched or -1 if no such vertex could be found.
|
|
20
|
+
*/
|
|
21
|
+
export const findInVertexArray = (vertexList: Array<Vertex>, vertex: XYCoords, epsilon: number): number => {
|
|
22
|
+
for (var i = 0; i < vertexList.length; i++) {
|
|
23
|
+
if (vertexList[i].distance(vertex) < epsilon) {
|
|
24
|
+
return i;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return -1;
|
|
28
|
+
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
interface XYCoords {
|
|
3
|
-
x : number;
|
|
4
|
-
y : number;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const inside = ( cp1 : XYCoords, cp2 : XYCoords, p : XYCoords) : boolean => {
|
|
8
|
-
return (cp2.x-cp1.x)*(p.y-cp1.y) > (cp2.y-cp1.y)*(p.x-cp1.x);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const intersection = ( cp1 : XYCoords ,cp2 : XYCoords ,s : XYCoords, e : XYCoords ) : XYCoords => {
|
|
12
|
-
const dc = {
|
|
13
|
-
x: cp1.x - cp2.x,
|
|
14
|
-
y : cp1.y - cp2.y
|
|
15
|
-
},
|
|
16
|
-
dp = { x: s.x - e.x,
|
|
17
|
-
y : s.y - e.y
|
|
18
|
-
},
|
|
19
|
-
n1 = cp1.x * cp2.y - cp1.y * cp2.x,
|
|
20
|
-
n2 = s.x * e.y - s.y * e.x,
|
|
21
|
-
n3 = 1.0 / (dc.x * dp.y - dc.y * dp.x);
|
|
22
|
-
return { x : (n1*dp.x - n2*dc.x) * n3,
|
|
23
|
-
y : (n1*dp.y - n2*dc.y) * n3
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const sutherlandHodgman = ( subjectPolygon : Array<XYCoords>,
|
|
28
|
-
clipPolygon : Array<XYCoords> ) : Array<XYCoords> => {
|
|
29
|
-
|
|
30
|
-
let cp1 : XYCoords = clipPolygon[clipPolygon.length-1];
|
|
31
|
-
let cp2 : XYCoords;
|
|
32
|
-
let s : XYCoords;
|
|
33
|
-
let e : XYCoords;
|
|
34
|
-
|
|
35
|
-
let outputList : Array<XYCoords> = subjectPolygon;
|
|
36
|
-
|
|
37
|
-
for( var j in clipPolygon ) {
|
|
38
|
-
cp2 = clipPolygon[j];
|
|
39
|
-
var inputList = outputList;
|
|
40
|
-
outputList = [];
|
|
41
|
-
s = inputList[inputList.length - 1]; // last on the input list
|
|
42
|
-
for (var i in inputList) {
|
|
43
|
-
e = inputList[i];
|
|
44
|
-
if (inside(cp1,cp2,e)) {
|
|
45
|
-
if (!inside(cp1,cp2,s)) {
|
|
46
|
-
outputList.push(intersection(cp1,cp2,s,e));
|
|
47
|
-
}
|
|
48
|
-
outputList.push(e);
|
|
49
|
-
}
|
|
50
|
-
else if (inside(cp1,cp2,s)) {
|
|
51
|
-
outputList.push(intersection(cp1,cp2,s,e));
|
|
52
|
-
}
|
|
53
|
-
s = e;
|
|
54
|
-
}
|
|
55
|
-
cp1 = cp2;
|
|
56
|
-
}
|
|
57
|
-
return outputList
|
|
58
|
-
}
|
|
59
|
-
|