Section修改
This commit is contained in:
parent
eb7bf48ada
commit
71ee2077a3
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
|
@ -16,7 +16,6 @@ const config = {
|
|||
plugins: [
|
||||
typescript({
|
||||
tsconfig: "./tsconfig.json",
|
||||
|
||||
compilerOptions: {
|
||||
declaration: true,
|
||||
declarationDir: "components",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { GraphicData, JlGraphic } from 'jl-graphic'
|
||||
import { IPointData } from 'pixi.js'
|
||||
import { SectionGraphic } from './SectionGraphic'
|
||||
|
||||
export interface ISectionData extends GraphicData {
|
||||
code: string
|
||||
|
@ -7,10 +8,23 @@ export interface ISectionData extends GraphicData {
|
|||
|
||||
}
|
||||
|
||||
export interface SectionDisplayConfig {
|
||||
lineColor: string;
|
||||
lineWidth: number;
|
||||
}
|
||||
|
||||
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 {
|
||||
console.log('repaint')
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue