@luceosports/play-rendering 1.10.9 → 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 +16 -6
- package/src/models/Shape.js +60 -2
- package/src/models/ShapeModels/CircleShape.js +1 -1
- package/src/models/ShapeModels/ConeShape.js +1 -1
- package/src/models/ShapeModels/SquareShape.js +1 -1
- package/src/models/ShapeModels/TriangleShape.js +15 -1
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();
|
|
@@ -28,25 +28,35 @@ class InternalShapeLayer extends InternalBaseLayer {
|
|
|
28
28
|
const b = Math.ceil(blue * 255);
|
|
29
29
|
|
|
30
30
|
this.ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
31
|
-
this.ctx.strokeStyle = `rgba(${r}, ${g}, ${b}, 1)`;
|
|
31
|
+
this.ctx.strokeStyle = `rgba(${r}, ${g}, ${b}, ${alpha ? 1 : 0})`;
|
|
32
32
|
}
|
|
33
33
|
|
|
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';
|
|
41
|
+
|
|
42
|
+
[...rectWrapPointsTranslated, rectWrapCenter].forEach(point => {
|
|
40
43
|
this.ctx.beginPath();
|
|
41
|
-
this.ctx.arc(point.x, point.y, 0.
|
|
42
|
-
this.ctx.stroke();
|
|
44
|
+
this.ctx.arc(point.x, point.y, 0.4, 0, Math.PI * 2);
|
|
43
45
|
this.ctx.fill();
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
drawShape() {
|
|
50
|
+
this.ctx.save();
|
|
48
51
|
this.drawShapeLogic();
|
|
49
|
-
|
|
52
|
+
this.drawShapeBorder();
|
|
53
|
+
this.ctx.restore();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
drawShapeBorder() {
|
|
57
|
+
if (this.shape.showBorder) {
|
|
58
|
+
this.ctx.stroke();
|
|
59
|
+
}
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
drawShapeLogic() {
|
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');
|
|
@@ -29,7 +34,7 @@ class Shape extends Model {
|
|
|
29
34
|
return 10;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
get
|
|
37
|
+
get rectWrapPointsPure() {
|
|
33
38
|
const topLeft = { x: -this.outerCircleRadius / 2, y: -this.outerCircleRadius / 2 };
|
|
34
39
|
const topRight = { x: this.outerCircleRadius / 2, y: -this.outerCircleRadius / 2 };
|
|
35
40
|
const botRight = { x: this.outerCircleRadius / 2, y: this.outerCircleRadius / 2 };
|
|
@@ -37,9 +42,15 @@ class Shape extends Model {
|
|
|
37
42
|
return [topLeft, topRight, botRight, botLeft];
|
|
38
43
|
}
|
|
39
44
|
|
|
45
|
+
get rectWrapPoints() {
|
|
46
|
+
return this.rectWrapPointsPure.map(point => {
|
|
47
|
+
return { x: point.x * this.scale.x, y: point.y * this.scale.y };
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
get rectWrapPointsTranslated() {
|
|
41
52
|
return this.rectWrapPoints.map(point => {
|
|
42
|
-
return { x: point.x
|
|
53
|
+
return { x: point.x + this.location.x, y: point.y + this.location.y };
|
|
43
54
|
});
|
|
44
55
|
}
|
|
45
56
|
|
|
@@ -48,10 +59,57 @@ class Shape extends Model {
|
|
|
48
59
|
return [];
|
|
49
60
|
}
|
|
50
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
|
+
|
|
51
69
|
rectWrapperContains({ x, y }) {
|
|
52
70
|
const [topLeft, topRight, botRight] = this.rectWrapPointsTranslated;
|
|
53
71
|
return topLeft.x <= x && x <= topRight.x && topLeft.y <= y && y <= botRight.y;
|
|
54
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
|
+
}
|
|
55
113
|
}
|
|
56
114
|
|
|
57
115
|
module.exports = Shape;
|
|
@@ -5,7 +5,7 @@ class CircleShape extends Shape {
|
|
|
5
5
|
return 5;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
get
|
|
8
|
+
get rectWrapPointsPure() {
|
|
9
9
|
const topLeft = { x: -this.outerCircleRadius, y: -this.outerCircleRadius };
|
|
10
10
|
const topRight = { x: this.outerCircleRadius, y: -this.outerCircleRadius };
|
|
11
11
|
const botRight = { x: this.outerCircleRadius, y: this.outerCircleRadius };
|
|
@@ -14,12 +14,26 @@ class TriangleShape extends Shape {
|
|
|
14
14
|
];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
get
|
|
17
|
+
get rectWrapPointsPure() {
|
|
18
18
|
const [topPoint, botLeft, botRight] = this.shapeControlPoints;
|
|
19
19
|
const topLeft = { x: botLeft.x, y: topPoint.y };
|
|
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;
|