Skip to content

Commit

Permalink
also optimize strokePolygon() for the canvas renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
obiot committed Jul 18, 2023
1 parent 21eb65d commit 861fd17
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/video/canvas/canvas_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,22 @@ export default class CanvasRenderer extends Renderer {
return;
}
let context = this.getContext();
let points = poly.points;
let pointsLength = points.length;
let firstPoint = points[0];

this.translate(poly.pos.x, poly.pos.y);

context.beginPath();
context.moveTo(poly.points[0].x, poly.points[0].y);
for (let i = 1; i < poly.points.length; i++) {
const point = poly.points[i];
context.moveTo(firstPoint.x, firstPoint.y);
for (let i = 1; i < pointsLength; i++) {
const point = points[i];
context.lineTo(point.x, point.y);
}
context.lineTo(poly.points[0].x, poly.points[0].y);
context.lineTo(firstPoint.x, firstPoint.y);
context[fill === true ? "fill" : "stroke"]();
context.closePath();

this.translate(-poly.pos.x, -poly.pos.y);
}

Expand Down

0 comments on commit 861fd17

Please sign in to comment.