Isogon.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { __extends } from "tslib";
  2. import Path from '../Path.js';
  3. var PI = Math.PI;
  4. var sin = Math.sin;
  5. var cos = Math.cos;
  6. var IsogonShape = (function () {
  7. function IsogonShape() {
  8. this.x = 0;
  9. this.y = 0;
  10. this.r = 0;
  11. this.n = 0;
  12. }
  13. return IsogonShape;
  14. }());
  15. export { IsogonShape };
  16. var Isogon = (function (_super) {
  17. __extends(Isogon, _super);
  18. function Isogon(opts) {
  19. return _super.call(this, opts) || this;
  20. }
  21. Isogon.prototype.getDefaultShape = function () {
  22. return new IsogonShape();
  23. };
  24. Isogon.prototype.buildPath = function (ctx, shape) {
  25. var n = shape.n;
  26. if (!n || n < 2) {
  27. return;
  28. }
  29. var x = shape.x;
  30. var y = shape.y;
  31. var r = shape.r;
  32. var dStep = 2 * PI / n;
  33. var deg = -PI / 2;
  34. ctx.moveTo(x + r * cos(deg), y + r * sin(deg));
  35. for (var i = 0, end = n - 1; i < end; i++) {
  36. deg += dStep;
  37. ctx.lineTo(x + r * cos(deg), y + r * sin(deg));
  38. }
  39. ctx.closePath();
  40. return;
  41. };
  42. return Isogon;
  43. }(Path));
  44. Isogon.prototype.type = 'isogon';
  45. export default Isogon;