@visactor/vrender-core
Version:
## Description
59 lines (50 loc) • 1.87 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.genLinearTypeSegments = exports.genLinearSegments = exports.Linear = void 0;
const common_1 = require("./common");
class Linear {
constructor(context, startPoint) {
this.context = context, startPoint && (this.startPoint = startPoint);
}
areaStart() {
this._line = 0;
}
areaEnd() {
this._line = NaN;
}
lineStart() {
this._point = 0, this.startPoint && this.point(this.startPoint);
}
lineEnd() {
(this._line || 0 !== this._line && 1 === this._point) && this.context.closePath(),
this._line = 1 - this._line;
}
point(p) {
const x = p.x, y = p.y;
switch (this._point) {
case 0:
this._point = 1, this._line ? this.context.lineTo(x, y, !1 !== this._lastDefined && !1 !== p.defined, p) : this.context.moveTo(x, y, p);
break;
case 1:
this._point = 2;
default:
this.context.lineTo(x, y, !1 !== this._lastDefined && !1 !== p.defined, p);
}
this._lastDefined = p.defined;
}
tryUpdateLength() {
return this.context.tryUpdateLength();
}
}
function genLinearSegments(points, params = {}) {
const {direction: direction, startPoint: startPoint} = params;
if (points.length < 2 - Number(!!startPoint)) return null;
const segContext = (0, common_1.genSegContext)("linear", direction, points);
return genLinearTypeSegments(new Linear(segContext, startPoint), points), segContext;
}
function genLinearTypeSegments(path, points) {
return (0, common_1.genCurveSegments)(path, points, 1);
}
exports.Linear = Linear, exports.genLinearSegments = genLinearSegments, exports.genLinearTypeSegments = genLinearTypeSegments;
//# sourceMappingURL=linear.js.map