|
@@ -25,6 +25,7 @@
|
|
|
*/
|
|
|
|
|
|
import { SPathCommand } from "./SPathCommand";
|
|
|
+import { SPoint } from "./types/SPoint";
|
|
|
|
|
|
/**
|
|
|
* Path对象
|
|
@@ -32,6 +33,7 @@ import { SPathCommand } from "./SPathCommand";
|
|
|
* @author 庞利祥 <sybotan@126.com>
|
|
|
*/
|
|
|
export class SPath {
|
|
|
+ /** 命令集合 */
|
|
|
cmdList: SPathCommand[] = [];
|
|
|
|
|
|
/**
|
|
@@ -42,7 +44,7 @@ export class SPath {
|
|
|
*/
|
|
|
private addCommand(cmd: string, ...args: number[]): void {
|
|
|
this.cmdList.push({ command: cmd, args: args });
|
|
|
- }
|
|
|
+ } // Function addCommand()
|
|
|
|
|
|
/**
|
|
|
* 添加一条新路径到对当前路径。
|
|
@@ -50,15 +52,16 @@ export class SPath {
|
|
|
* @param path
|
|
|
*/
|
|
|
addPath(path: SPath): void {
|
|
|
+ // todo
|
|
|
this.cmdList.concat(path.cmdList);
|
|
|
- }
|
|
|
+ } // Function addPath()
|
|
|
|
|
|
/**
|
|
|
* 使笔点返回到当前子路径的起始点。它尝试从当前点到起始点绘制一条直线。 如果图形已经是封闭的或者只有一个点,那么此函数不会做任何操作。
|
|
|
*/
|
|
|
closePath(): void {
|
|
|
this.addCommand("Z");
|
|
|
- }
|
|
|
+ } // Function closePath()
|
|
|
|
|
|
/**
|
|
|
* 移动当前点到指定位置
|
|
@@ -68,7 +71,7 @@ export class SPath {
|
|
|
*/
|
|
|
moveTo(x: number, y: number): void {
|
|
|
this.addCommand("M", x, y);
|
|
|
- }
|
|
|
+ } // Function moveTo()
|
|
|
|
|
|
/**
|
|
|
* 从当前点向指定点画线
|
|
@@ -78,7 +81,7 @@ export class SPath {
|
|
|
*/
|
|
|
lineTo(x: number, y: number): void {
|
|
|
this.addCommand("L", x, y);
|
|
|
- }
|
|
|
+ } // Function lineTo()
|
|
|
|
|
|
/**
|
|
|
* 添加一条圆弧路径。
|
|
@@ -107,7 +110,7 @@ export class SPath {
|
|
|
endAngle,
|
|
|
anticlockwise
|
|
|
);
|
|
|
- }
|
|
|
+ } // Function arc()
|
|
|
|
|
|
/**
|
|
|
* 根据控制点和半径添加一条圆弧路径,使用直线连接前一个点。
|
|
@@ -126,7 +129,7 @@ export class SPath {
|
|
|
radius: number
|
|
|
): void {
|
|
|
this.addCommand("ArcTo", x1, y1, x2, y2, radius);
|
|
|
- }
|
|
|
+ } // Function arcTo()
|
|
|
|
|
|
/**
|
|
|
* 添加二次贝塞尔曲线
|
|
@@ -138,7 +141,7 @@ export class SPath {
|
|
|
*/
|
|
|
quadraticCurveTo(cp1x: number, cp1y: number, x: number, y: number): void {
|
|
|
this.addCommand("Q", cp1x, cp1y, x, y);
|
|
|
- }
|
|
|
+ } // Function quadraticCurveTo()
|
|
|
|
|
|
/**
|
|
|
* 添加三次贝塞尔曲线
|
|
@@ -159,7 +162,7 @@ export class SPath {
|
|
|
y: number
|
|
|
): void {
|
|
|
this.addCommand("C", cp1x, cp1y, cp2x, cp2y, x, y);
|
|
|
- }
|
|
|
+ } // Function bezierCurveTo()
|
|
|
|
|
|
/**
|
|
|
* 添加椭圆
|
|
@@ -171,7 +174,7 @@ export class SPath {
|
|
|
*/
|
|
|
ellipse(cx: number, cy: number, rx: number, ry: number): void {
|
|
|
this.addCommand("Ellipse", cx, cy, rx, ry);
|
|
|
- }
|
|
|
+ } // Function ellipse()
|
|
|
|
|
|
/**
|
|
|
* 添加矩形
|
|
@@ -187,5 +190,20 @@ export class SPath {
|
|
|
this.addCommand("L", x + w, y + h);
|
|
|
this.addCommand("L", x, y + h);
|
|
|
this.addCommand("Z");
|
|
|
- }
|
|
|
-}
|
|
|
+ } // Function rect()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加多边形
|
|
|
+ *
|
|
|
+ * @param pList 点集数组
|
|
|
+ */
|
|
|
+ polygon(pList: SPoint[]): void {
|
|
|
+ if (pList.length > 3) {
|
|
|
+ this.addCommand("M", pList[0].x, pList[0].y);
|
|
|
+ for (let i = 1; i < pList.length; i++) {
|
|
|
+ this.addCommand("L", pList[i].x, pList[i].y);
|
|
|
+ }
|
|
|
+ this.addCommand("Z");
|
|
|
+ }
|
|
|
+ } // Function polygon()
|
|
|
+} // Class SPath
|