坡度碰撞检测修改

This commit is contained in:
joylink_zhaoerwei 2023-08-08 15:07:13 +08:00
parent b365fc4dc7
commit ddb03f379d
2 changed files with 8 additions and 8 deletions

View File

@ -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 });
}
});
//坡度值

View File

@ -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;
}
}