UNPKG

@visactor/vrender-core

Version:
50 lines (45 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.CurveContext = void 0; const vutils_1 = require("@visactor/vutils"), line_1 = require("./line"), cubic_bezier_1 = require("./cubic-bezier"), quadratic_bezier_1 = require("./quadratic-bezier"); class CurveContext { constructor(path) { this.path = path, this._lastX = this._lastY = this._startX = this._startY = 0; } moveTo(x, y) { return this._lastX = this._startX = x, this._lastY = this._startY = y, this; } lineTo(x, y) { const curve = this.addLinearCurve(x, y); this.path.addCurve(curve), this._lastX = x, this._lastY = y; } addLinearCurve(x, y) { return new line_1.LineCurve(new vutils_1.Point(this._lastX, this._lastY), new vutils_1.Point(x, y)); } quadraticCurveTo(aCPx, aCPy, aX, aY) { const curve = new quadratic_bezier_1.QuadraticBezierCurve(new vutils_1.Point(this._lastX, this._lastY), new vutils_1.Point(aCPx, aCPy), new vutils_1.Point(aX, aY)); this.path.addCurve(curve), this._lastX = aX, this._lastY = aY; } bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) { const curve = new cubic_bezier_1.CubicBezierCurve(new vutils_1.Point(this._lastX, this._lastY), new vutils_1.Point(cp1x, cp1y), new vutils_1.Point(cp2x, cp2y), new vutils_1.Point(x, y)); this.path.addCurve(curve), this._lastX = x, this._lastY = y; } arcTo(aX1, aY1, aX2, aY2, aRadius) { throw new Error("CurveContext不支持调用arcTo"); } ellipse(aX, aY, xRadius, yRadius, aRotation, aStartAngle, aEndAngle, aClockwise) { throw new Error("CurveContext不支持调用ellipse"); } rect(x, y, w, h) { throw new Error("CurveContext不支持调用rect"); } arc(x, y, radius, startAngle, endAngle, counterclockwise) { throw new Error("CurveContext不支持调用arc"); } closePath() { this.path.curves.length < 2 || this.lineTo(this._startX, this._startY); } } exports.CurveContext = CurveContext; //# sourceMappingURL=curve-context.js.map