UNPKG

@visactor/vrender-core

Version:
48 lines (43 loc) 1.85 kB
import { Point } from "@visactor/vutils"; import { LineCurve } from "./line"; import { CubicBezierCurve } from "./cubic-bezier"; import { QuadraticBezierCurve } from "./quadratic-bezier"; export 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 LineCurve(new Point(this._lastX, this._lastY), new Point(x, y)); } quadraticCurveTo(aCPx, aCPy, aX, aY) { const curve = new QuadraticBezierCurve(new Point(this._lastX, this._lastY), new Point(aCPx, aCPy), new Point(aX, aY)); this.path.addCurve(curve), this._lastX = aX, this._lastY = aY; } bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) { const curve = new CubicBezierCurve(new Point(this._lastX, this._lastY), new Point(cp1x, cp1y), new Point(cp2x, cp2y), new 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); } } //# sourceMappingURL=curve-context.js.map