UNPKG

1.99 kBJavaScriptView Raw
1import { __extends } from "tslib";
2import Path from '../Path.js';
3var cos = Math.cos;
4var sin = Math.sin;
5var TrochoidShape = (function () {
6 function TrochoidShape() {
7 this.cx = 0;
8 this.cy = 0;
9 this.r = 0;
10 this.r0 = 0;
11 this.d = 0;
12 this.location = 'out';
13 }
14 return TrochoidShape;
15}());
16export { TrochoidShape };
17var Trochoid = (function (_super) {
18 __extends(Trochoid, _super);
19 function Trochoid(opts) {
20 return _super.call(this, opts) || this;
21 }
22 Trochoid.prototype.getDefaultStyle = function () {
23 return {
24 stroke: '#000',
25 fill: null
26 };
27 };
28 Trochoid.prototype.getDefaultShape = function () {
29 return new TrochoidShape();
30 };
31 Trochoid.prototype.buildPath = function (ctx, shape) {
32 var R = shape.r;
33 var r = shape.r0;
34 var d = shape.d;
35 var offsetX = shape.cx;
36 var offsetY = shape.cy;
37 var delta = shape.location === 'out' ? 1 : -1;
38 var x1;
39 var y1;
40 var x2;
41 var y2;
42 if (shape.location && R <= r) {
43 return;
44 }
45 var num = 0;
46 var i = 1;
47 var theta;
48 x1 = (R + delta * r) * cos(0)
49 - delta * d * cos(0) + offsetX;
50 y1 = (R + delta * r) * sin(0)
51 - d * sin(0) + offsetY;
52 ctx.moveTo(x1, y1);
53 do {
54 num++;
55 } while ((r * num) % (R + delta * r) !== 0);
56 do {
57 theta = Math.PI / 180 * i;
58 x2 = (R + delta * r) * cos(theta)
59 - delta * d * cos((R / r + delta) * theta)
60 + offsetX;
61 y2 = (R + delta * r) * sin(theta)
62 - d * sin((R / r + delta) * theta)
63 + offsetY;
64 ctx.lineTo(x2, y2);
65 i++;
66 } while (i <= (r * num) / (R + delta * r) * 360);
67 };
68 return Trochoid;
69}(Path));
70Trochoid.prototype.type = 'trochoid';
71export default Trochoid;