| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.bumpRadial = bumpRadial;
|
|---|
| 7 | exports.bumpX = bumpX;
|
|---|
| 8 | exports.bumpY = bumpY;
|
|---|
| 9 | var _pointRadial = _interopRequireDefault(require("../pointRadial.js"));
|
|---|
| 10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|---|
| 11 | class Bump {
|
|---|
| 12 | constructor(context, x) {
|
|---|
| 13 | this._context = context;
|
|---|
| 14 | this._x = x;
|
|---|
| 15 | }
|
|---|
| 16 | areaStart() {
|
|---|
| 17 | this._line = 0;
|
|---|
| 18 | }
|
|---|
| 19 | areaEnd() {
|
|---|
| 20 | this._line = NaN;
|
|---|
| 21 | }
|
|---|
| 22 | lineStart() {
|
|---|
| 23 | this._point = 0;
|
|---|
| 24 | }
|
|---|
| 25 | lineEnd() {
|
|---|
| 26 | if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
|
|---|
| 27 | this._line = 1 - this._line;
|
|---|
| 28 | }
|
|---|
| 29 | point(x, y) {
|
|---|
| 30 | x = +x, y = +y;
|
|---|
| 31 | switch (this._point) {
|
|---|
| 32 | case 0:
|
|---|
| 33 | {
|
|---|
| 34 | this._point = 1;
|
|---|
| 35 | if (this._line) this._context.lineTo(x, y);else this._context.moveTo(x, y);
|
|---|
| 36 | break;
|
|---|
| 37 | }
|
|---|
| 38 | case 1:
|
|---|
| 39 | this._point = 2;
|
|---|
| 40 | // falls through
|
|---|
| 41 | default:
|
|---|
| 42 | {
|
|---|
| 43 | if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
|
|---|
| 44 | break;
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | this._x0 = x, this._y0 = y;
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | class BumpRadial {
|
|---|
| 51 | constructor(context) {
|
|---|
| 52 | this._context = context;
|
|---|
| 53 | }
|
|---|
| 54 | lineStart() {
|
|---|
| 55 | this._point = 0;
|
|---|
| 56 | }
|
|---|
| 57 | lineEnd() {}
|
|---|
| 58 | point(x, y) {
|
|---|
| 59 | x = +x, y = +y;
|
|---|
| 60 | if (this._point++ === 0) {
|
|---|
| 61 | this._x0 = x, this._y0 = y;
|
|---|
| 62 | } else {
|
|---|
| 63 | const p0 = (0, _pointRadial.default)(this._x0, this._y0);
|
|---|
| 64 | const p1 = (0, _pointRadial.default)(this._x0, this._y0 = (this._y0 + y) / 2);
|
|---|
| 65 | const p2 = (0, _pointRadial.default)(x, this._y0);
|
|---|
| 66 | const p3 = (0, _pointRadial.default)(x, y);
|
|---|
| 67 | this._context.moveTo(...p0);
|
|---|
| 68 | this._context.bezierCurveTo(...p1, ...p2, ...p3);
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 | function bumpX(context) {
|
|---|
| 73 | return new Bump(context, true);
|
|---|
| 74 | }
|
|---|
| 75 | function bumpY(context) {
|
|---|
| 76 | return new Bump(context, false);
|
|---|
| 77 | }
|
|---|
| 78 | function bumpRadial(context) {
|
|---|
| 79 | return new BumpRadial(context);
|
|---|
| 80 | } |
|---|