|
@@ -2,6 +2,7 @@ import ControlPoint from "../Geometry/ControlPoint.js";
|
|
|
import { dataService } from "./DataService.js";
|
|
|
import { mathUtil } from "../Util/MathUtil";
|
|
|
import { edgeService } from "./EdgeService.js";
|
|
|
+import { roadService } from "./RoadService.js";
|
|
|
|
|
|
export default class ControlPointService {
|
|
|
constructor() {}
|
|
@@ -23,24 +24,24 @@ export default class ControlPointService {
|
|
|
//更新edge的坐标
|
|
|
let position1 = mathUtil.getJoinLinePoint(position, line1);
|
|
|
let position2 = mathUtil.getJoinLinePoint(position, line2);
|
|
|
+
|
|
|
//可能position1或者position2不在对应的edge上,这时候需要调换顺序
|
|
|
- if (
|
|
|
- !mathUtil.isContainForSegment(position1, edge1.start, edge1.end) ||
|
|
|
- !mathUtil.isContainForSegment(position2, edge2.start, edge2.end)
|
|
|
- ) {
|
|
|
- position = mathUtil.getPositionForExtendedLine(point2, point1);
|
|
|
- position1 = mathUtil.getJoinLinePoint(position, line1);
|
|
|
- position2 = mathUtil.getJoinLinePoint(position, line2);
|
|
|
+ if (!this.isPointOnEdgeRay(edge1, dir1, position)) {
|
|
|
+ let _position = mathUtil.getPositionForExtendedLine(point2, point1);
|
|
|
+ position1 = mathUtil.getJoinLinePoint(_position, line1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!this.isPointOnEdgeRay(edge2, dir2, position)) {
|
|
|
+ let _position = mathUtil.getPositionForExtendedLine(point2, point1);
|
|
|
+ position2 = mathUtil.getJoinLinePoint(_position, line2);
|
|
|
}
|
|
|
|
|
|
- // const realRosition = mathUtil.getPositionForExtendedLine(point2, point1);
|
|
|
- // const realRosition = {
|
|
|
- // x: (point1.x + point2.x) / 2,
|
|
|
- // y: (point1.y + point2.y) / 2,
|
|
|
- // };
|
|
|
if (controlPoint == null) {
|
|
|
//新建控制点
|
|
|
controlPoint = this.create(realRosition);
|
|
|
+ //需要删除之前的控制点
|
|
|
+ dataService.deleteControlPointForEdge(edge1.vectorId);
|
|
|
+ dataService.deleteControlPointForEdge(edge2.vectorId);
|
|
|
//设置控制点的信息
|
|
|
controlPoint.setEdgeInfo(edge1.vectorId, dir1, edge2.vectorId, dir2);
|
|
|
//添加到数据集里
|
|
@@ -53,6 +54,86 @@ export default class ControlPointService {
|
|
|
edge1.setPosition(position1, dir1);
|
|
|
edge2.setPosition(position2, dir2);
|
|
|
}
|
|
|
+
|
|
|
+ //position在直线edge.start,edge.end上
|
|
|
+ // isPointOnEdgeRay(edge, dir, position) {
|
|
|
+ // let point1, point2;
|
|
|
+ // if (dir == "start") {
|
|
|
+ // point1 = edge.start;
|
|
|
+ // point2 = edge.end;
|
|
|
+ // } else if (dir == "end") {
|
|
|
+ // point1 = edge.end;
|
|
|
+ // point2 = edge.start;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // let v1 = {
|
|
|
+ // x: position.x - point1.x,
|
|
|
+ // y: position.y - point1.y,
|
|
|
+ // };
|
|
|
+
|
|
|
+ // let v2 = {
|
|
|
+ // x: point2.x - point1.x,
|
|
|
+ // y: point2.y - point1.y,
|
|
|
+ // };
|
|
|
+
|
|
|
+ // let v = {
|
|
|
+ // x: v1.x + v2.x,
|
|
|
+ // y: v1.y + v2.y,
|
|
|
+ // };
|
|
|
+
|
|
|
+ // let d = mathUtil.getDistance(v, { x: 0, y: 0 });
|
|
|
+ // let d1 = mathUtil.getDistance(position, point1);
|
|
|
+ // let d2 = mathUtil.getDistance(point2, point1);
|
|
|
+
|
|
|
+ // if (Math.abs(d - d1 - d2) < 0.01) {
|
|
|
+ // return true;
|
|
|
+ // } else {
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ //角度小,road宽的时候,可能edge顺序会倒,但是road的顺序不会
|
|
|
+ isPointOnEdgeRay(edge, dir, position) {
|
|
|
+ let road = dataService.getRoad(edge.parent);
|
|
|
+ let point1, point2;
|
|
|
+ if (dir == "start") {
|
|
|
+ point1 = dataService.getPoint(road.startId);
|
|
|
+ point2 = dataService.getPoint(road.endId);
|
|
|
+ } else if (dir == "end") {
|
|
|
+ point1 = dataService.getPoint(road.endId);
|
|
|
+ point2 = dataService.getPoint(road.startId);
|
|
|
+ }
|
|
|
+
|
|
|
+ position = mathUtil.getJoinLinePoint(
|
|
|
+ position,
|
|
|
+ roadService.getMidLine(road)
|
|
|
+ );
|
|
|
+
|
|
|
+ let v1 = {
|
|
|
+ x: position.x - point1.x,
|
|
|
+ y: position.y - point1.y,
|
|
|
+ };
|
|
|
+
|
|
|
+ let v2 = {
|
|
|
+ x: point2.x - point1.x,
|
|
|
+ y: point2.y - point1.y,
|
|
|
+ };
|
|
|
+
|
|
|
+ let v = {
|
|
|
+ x: v1.x + v2.x,
|
|
|
+ y: v1.y + v2.y,
|
|
|
+ };
|
|
|
+
|
|
|
+ let d = mathUtil.getDistance(v, { x: 0, y: 0 });
|
|
|
+ let d1 = mathUtil.getDistance(position, point1);
|
|
|
+ let d2 = mathUtil.getDistance(point2, point1);
|
|
|
+
|
|
|
+ if (Math.abs(d - d1 - d2) < 0.2) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const controlPointService = new ControlPointService();
|