@luceosports/play-rendering 1.10.11 → 1.10.12
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/dist/play-rendering.js +3 -3
- package/dist/play-rendering.js.map +1 -1
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/layers/ShapeControlPointLayer.js +2 -4
- package/src/layers/shape/base/InternalShapeLayer.js +3 -4
- package/src/models/Shape.js +52 -0
- package/src/models/ShapeModels/TriangleShape.js +14 -0
package/index.js
CHANGED
|
@@ -3,5 +3,7 @@ module.exports.Frame = require('./src/models/Frame');
|
|
|
3
3
|
module.exports.Animation = require('./src/models/Animation');
|
|
4
4
|
module.exports.Line = require('./src/models/Line');
|
|
5
5
|
module.exports.Player = require('./src/models/Player');
|
|
6
|
+
module.exports.Shape = require('./src/models/Shape');
|
|
7
|
+
module.exports.ShapeModels = require('./src/models/ShapeModels');
|
|
6
8
|
module.exports.LineDrawingMath = require('./src/math/LineDrawingMath');
|
|
7
9
|
module.exports.Bezier = require('./src/math/Bezier').Bezier;
|
package/package.json
CHANGED
|
@@ -6,13 +6,11 @@ class ShapeControlPointLayer extends BaseLayer {
|
|
|
6
6
|
|
|
7
7
|
this.ctx.fillStyle = 'blue';
|
|
8
8
|
|
|
9
|
-
this.playData.shapes.forEach(({ id, color,
|
|
9
|
+
this.playData.shapes.forEach(({ id, color, rectWrapPointsTranslated }) => {
|
|
10
10
|
if (this.options.shapeSelectedId !== id) return;
|
|
11
11
|
if (color.alpha === 0) return;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
rectWrapPoints.forEach(point => {
|
|
13
|
+
rectWrapPointsTranslated.forEach(point => {
|
|
16
14
|
this.ctx.beginPath();
|
|
17
15
|
this.ctx.arc(point.x, point.y, 0.4, 0, Math.PI * 2, true);
|
|
18
16
|
this.ctx.fill();
|
|
@@ -34,13 +34,12 @@ class InternalShapeLayer extends InternalBaseLayer {
|
|
|
34
34
|
drawShapeWrapPoints() {
|
|
35
35
|
if (!DEBUG_WRAP_POINTS) return;
|
|
36
36
|
|
|
37
|
-
const {
|
|
37
|
+
const { rectWrapPointsTranslated } = this.shape;
|
|
38
|
+
const rectWrapCenter = this.shape.rectWrapCenterTranslated(rectWrapPointsTranslated);
|
|
38
39
|
|
|
39
40
|
this.ctx.fillStyle = 'red';
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
rectWrapPoints.forEach(point => {
|
|
42
|
+
[...rectWrapPointsTranslated, rectWrapCenter].forEach(point => {
|
|
44
43
|
this.ctx.beginPath();
|
|
45
44
|
this.ctx.arc(point.x, point.y, 0.4, 0, Math.PI * 2);
|
|
46
45
|
this.ctx.fill();
|
package/src/models/Shape.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
const Model = require('./Base/InternalFrameModel');
|
|
2
2
|
|
|
3
|
+
const WRAP_POINT_TOP_LEFT_INDEX = 0;
|
|
4
|
+
const WRAP_POINT_TOP_RIGHT_INDEX = 1;
|
|
5
|
+
const WRAP_POINT_BOT_RIGHT_INDEX = 2;
|
|
6
|
+
const WRAP_POINT_BOT_LEFT_INDEX = 3;
|
|
7
|
+
|
|
3
8
|
class Shape extends Model {
|
|
4
9
|
get id() {
|
|
5
10
|
return this._getAttr('id');
|
|
@@ -54,10 +59,57 @@ class Shape extends Model {
|
|
|
54
59
|
return [];
|
|
55
60
|
}
|
|
56
61
|
|
|
62
|
+
rectWrapCenterTranslated([topLeft, topRight, botRight]) {
|
|
63
|
+
return {
|
|
64
|
+
x: (topLeft.x + topRight.x) / 2,
|
|
65
|
+
y: (topRight.y + botRight.y) / 2
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
rectWrapperContains({ x, y }) {
|
|
58
70
|
const [topLeft, topRight, botRight] = this.rectWrapPointsTranslated;
|
|
59
71
|
return topLeft.x <= x && x <= topRight.x && topLeft.y <= y && y <= botRight.y;
|
|
60
72
|
}
|
|
73
|
+
|
|
74
|
+
computeShapeAreaForPointAtIndex(newPoint, newIndex) {
|
|
75
|
+
const [topLeftOrig, topRightOrig, botRightOrig] = this.rectWrapPointsTranslated;
|
|
76
|
+
const [topLeft, topRight, botRight] = this.computeRectWrapPointsTranslatedForPointAtIndex(newPoint, newIndex);
|
|
77
|
+
|
|
78
|
+
const scale = {
|
|
79
|
+
x: (Math.abs(topLeft.x - topRight.x) * this.scale.x) / Math.abs(topLeftOrig.x - topRightOrig.x),
|
|
80
|
+
y: (Math.abs(topRight.y - botRight.y) * this.scale.y) / Math.abs(topRightOrig.y - botRightOrig.y)
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return { scale, location: this.rectWrapCenterTranslated([topLeft, topRight, botRight]) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
computeRectWrapPointsTranslatedForPointAtIndex(newPoint, newIndex) {
|
|
87
|
+
const newWrapPointsTranslated = this.rectWrapPointsTranslated.map((point, index) =>
|
|
88
|
+
newIndex === index ? newPoint : point
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
if (newIndex === WRAP_POINT_TOP_LEFT_INDEX) {
|
|
92
|
+
newWrapPointsTranslated[WRAP_POINT_TOP_RIGHT_INDEX].y = newPoint.y;
|
|
93
|
+
newWrapPointsTranslated[WRAP_POINT_BOT_LEFT_INDEX].x = newPoint.x;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (newIndex === WRAP_POINT_TOP_RIGHT_INDEX) {
|
|
97
|
+
newWrapPointsTranslated[WRAP_POINT_TOP_LEFT_INDEX].y = newPoint.y;
|
|
98
|
+
newWrapPointsTranslated[WRAP_POINT_BOT_RIGHT_INDEX].x = newPoint.x;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (newIndex === WRAP_POINT_BOT_RIGHT_INDEX) {
|
|
102
|
+
newWrapPointsTranslated[WRAP_POINT_TOP_RIGHT_INDEX].x = newPoint.x;
|
|
103
|
+
newWrapPointsTranslated[WRAP_POINT_BOT_LEFT_INDEX].y = newPoint.y;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (newIndex === WRAP_POINT_BOT_LEFT_INDEX) {
|
|
107
|
+
newWrapPointsTranslated[WRAP_POINT_TOP_LEFT_INDEX].x = newPoint.x;
|
|
108
|
+
newWrapPointsTranslated[WRAP_POINT_BOT_RIGHT_INDEX].y = newPoint.y;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return newWrapPointsTranslated;
|
|
112
|
+
}
|
|
61
113
|
}
|
|
62
114
|
|
|
63
115
|
module.exports = Shape;
|
|
@@ -20,6 +20,20 @@ class TriangleShape extends Shape {
|
|
|
20
20
|
const topRight = { x: botRight.x, y: topPoint.y };
|
|
21
21
|
return [topLeft, topRight, botRight, botLeft];
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
rectWrapCenterTranslated([topLeft, topRight]) {
|
|
25
|
+
const [topPoint] = this.shapeControlPoints;
|
|
26
|
+
|
|
27
|
+
const topPointTranslated = {
|
|
28
|
+
x: topPoint.x + this.location.x,
|
|
29
|
+
y: topPoint.y + this.location.y
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
x: (topLeft.x + topRight.x) / 2,
|
|
34
|
+
y: topPointTranslated.y + this.outerCircleRadius
|
|
35
|
+
};
|
|
36
|
+
}
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
module.exports = TriangleShape;
|