Section修改

This commit is contained in:
Yuan 2023-12-25 13:54:08 +08:00
parent eb7bf48ada
commit 71ee2077a3
4 changed files with 71 additions and 2 deletions

5
.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}

View File

@ -16,7 +16,6 @@ const config = {
plugins: [ plugins: [
typescript({ typescript({
tsconfig: "./tsconfig.json", tsconfig: "./tsconfig.json",
compilerOptions: { compilerOptions: {
declaration: true, declaration: true,
declarationDir: "components", declarationDir: "components",

View File

@ -1,5 +1,6 @@
import { GraphicData, JlGraphic } from 'jl-graphic' import { GraphicData, JlGraphic } from 'jl-graphic'
import { IPointData } from 'pixi.js' import { IPointData } from 'pixi.js'
import { SectionGraphic } from './SectionGraphic'
export interface ISectionData extends GraphicData { export interface ISectionData extends GraphicData {
code: string code: string
@ -7,10 +8,23 @@ export interface ISectionData extends GraphicData {
} }
export interface SectionDisplayConfig {
lineColor: string;
lineWidth: number;
}
export class Section extends JlGraphic { export class Section extends JlGraphic {
static Type = 'Section'
lineGraphic: SectionGraphic
constructor() {
super(Section.Type)
this.lineGraphic = new SectionGraphic();
// this.transformSave = true;
this.addChild(this.lineGraphic);
}
doRepaint(): void { doRepaint(): void {
console.log('repaint') console.log('repaint')
} }
} }

View File

@ -0,0 +1,51 @@
import { Graphics, IPointData } from 'pixi.js';
import { assertBezierPoints, convertToBezierParams } from 'jl-graphic';
export class SectionGraphic extends Graphics {
static Type = 'SectionGraphic';
private _points: IPointData[] = [];
public get points(): IPointData[] {
return this._points;
}
public set points(value: IPointData[]) {
if (!this.isCurve) {
if (value.length < 2) {
throw Error('Polyline must have at least 2 points');
}
} else {
assertBezierPoints(value);
}
this._points = value;
}
private _segmentsCount = 10;
public get segmentsCount(): number {
return this._segmentsCount;
}
public set segmentsCount(value: number) {
if (value < 1) {
throw Error('segmentsCount must be at least 1');
}
this._segmentsCount = value;
}
isCurve = false;
constructor() {
super();
}
paint() {
if (this.isCurve) {
const bps = convertToBezierParams(this.points);
bps.forEach((bp) => {
this.drawBezierCurve(bp.p1, bp.p2, bp.cp1, bp.cp2, this.segmentsCount);
});
} else {
this.moveTo(this.points[0].x, this.points[0].y);
for (let i = 1; i < this.points.length; i++) {
this.lineTo(this.points[i].x, this.points[i].y);
}
}
}
}