diff --git a/src/graphics/slope/Slope.ts b/src/graphics/slope/Slope.ts index 624106e..74f6f31 100644 --- a/src/graphics/slope/Slope.ts +++ b/src/graphics/slope/Slope.ts @@ -30,6 +30,7 @@ export class Slope extends JlGraphic { lineGraphic: Graphics; slopeNumber: VectorText; slopeLong: VectorText; + changePoints: IPointData[] = []; constructor() { super(Slope.Type); this.lineGraphic = new Graphics(); @@ -69,8 +70,10 @@ export class Slope extends JlGraphic { this.datas.points.forEach((p, i) => { if (i !== 0) { this.lineGraphic.lineTo(p.x, p.y + distanceY); + this.changePoints.push({ x: p.x, y: p.y + distanceY }); } else { this.lineGraphic.moveTo(p.x, p.y - distanceY); + this.changePoints.push({ x: p.x, y: p.y - distanceY }); } }); //坡度值 diff --git a/src/graphics/slope/SlopeAssistant.ts b/src/graphics/slope/SlopeAssistant.ts index a2199aa..519ceed 100644 --- a/src/graphics/slope/SlopeAssistant.ts +++ b/src/graphics/slope/SlopeAssistant.ts @@ -110,14 +110,11 @@ class SlopeGraphicHitArea implements IHitArea { this.slope = slope; } contains(x: number, y: number): boolean { - for (let i = 1; i < this.slope.datas.points.length; i++) { - const p1 = this.slope.datas.points[i - 1]; - const p2 = this.slope.datas.points[i]; - if (linePoint(p1, p2, { x, y }, SlopeConsts.lineWidth)) { - return true; - } - } - return false; + let contains = false; + const p1 = this.slope.changePoints[0]; + const p2 = this.slope.changePoints[1]; + contains = contains || linePoint(p1, p2, { x, y }, SlopeConsts.lineWidth); + return contains; } }