drawContour.js 706 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. function drawContour(ctx, points, isClosed) {
  4. if (isClosed === void 0) { isClosed = false; }
  5. ctx.beginPath();
  6. points.slice(1).forEach(function (_a, prevIdx) {
  7. var x = _a.x, y = _a.y;
  8. var from = points[prevIdx];
  9. ctx.moveTo(from.x, from.y);
  10. ctx.lineTo(x, y);
  11. });
  12. if (isClosed) {
  13. var from = points[points.length - 1];
  14. var to = points[0];
  15. if (!from || !to) {
  16. return;
  17. }
  18. ctx.moveTo(from.x, from.y);
  19. ctx.lineTo(to.x, to.y);
  20. }
  21. ctx.stroke();
  22. }
  23. exports.drawContour = drawContour;
  24. //# sourceMappingURL=drawContour.js.map