drawContour.js 601 B

123456789101112131415161718192021
  1. export function drawContour(ctx, points, isClosed) {
  2. if (isClosed === void 0) { isClosed = false; }
  3. ctx.beginPath();
  4. points.slice(1).forEach(function (_a, prevIdx) {
  5. var x = _a.x, y = _a.y;
  6. var from = points[prevIdx];
  7. ctx.moveTo(from.x, from.y);
  8. ctx.lineTo(x, y);
  9. });
  10. if (isClosed) {
  11. var from = points[points.length - 1];
  12. var to = points[0];
  13. if (!from || !to) {
  14. return;
  15. }
  16. ctx.moveTo(from.x, from.y);
  17. ctx.lineTo(to.x, to.y);
  18. }
  19. ctx.stroke();
  20. }
  21. //# sourceMappingURL=drawContour.js.map