|
@@ -24,7 +24,7 @@ export default class MoveRoad {
|
|
|
|
|
|
// 测试要考虑pointId拖拽到包含他的所有墙的另一头
|
|
|
// 这个函数不会删除/拆分/合并墙或者点
|
|
|
- movePoint(pointId, position, modifyPoint) {
|
|
|
+ moveingRoadPoint(pointId, position, modifyPoint) {
|
|
|
let point = dataService.getPoint(pointId);
|
|
|
let linkedPointId = null;
|
|
|
let linkedRoadId = null;
|
|
@@ -114,6 +114,11 @@ export default class MoveRoad {
|
|
|
}
|
|
|
|
|
|
edgeService.updateEdgeForMovePoint(pointId);
|
|
|
+ let parent = point.getParent();
|
|
|
+ for (let key in parent) {
|
|
|
+ roadService.setLanes(key);
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -954,7 +959,7 @@ export default class MoveRoad {
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
- moveTo(roadId, dx, dy) {
|
|
|
+ moveRoad(roadId, dx, dy) {
|
|
|
dx = dx;
|
|
|
dy = -dy;
|
|
|
|
|
@@ -983,82 +988,88 @@ export default class MoveRoad {
|
|
|
rightEdge.start.y += dy;
|
|
|
rightEdge.end.x += dx;
|
|
|
rightEdge.end.y += dy;
|
|
|
+
|
|
|
+ roadService.setLanes(roadId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 更新pointId的坐标
|
|
|
- updatePointForMoveRoad(roadId, pointId, virtualInfo, limitRoadId, needNew) {
|
|
|
- const point = dataService.getPoint(pointId);
|
|
|
- const road = dataService.getRoad(roadId);
|
|
|
- // 如果没有约束墙,只有两种情况:一种是不新建墙,另一种是需要新建墙
|
|
|
- if (limitRoadId == null) {
|
|
|
- // 不需要新建墙,这种情况一般是pointId的parent只有一个
|
|
|
- if (!needNew) {
|
|
|
- point.setPosition(virtualInfo.virtualPosition);
|
|
|
- }
|
|
|
- // 新建墙
|
|
|
- else {
|
|
|
- this.createRoadForMoveRoad(
|
|
|
- pointId,
|
|
|
- roadId,
|
|
|
- virtualInfo.virtualPosition
|
|
|
- );
|
|
|
+ // pointId1移动到pointId2
|
|
|
+ // 如果有一堵墙(roadId)的两头是pointId1和pointId2,那么这堵墙会被删除
|
|
|
+ moveTo(pointId1, pointId2) {
|
|
|
+ const roadId = roadService.getRoadId(pointId1, pointId2);
|
|
|
+ // 不能重合
|
|
|
+ let point1 = dataService.getPoint(pointId1);
|
|
|
+ let point2 = dataService.getPoint(pointId2);
|
|
|
+ if (!point2) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ let parent1 = point1.getParent();
|
|
|
+ const parent2 = point2.getParent();
|
|
|
+ //确保pointId1与pointId2重合后,墙的角度不能太小
|
|
|
+ for (const roadId1 in parent1) {
|
|
|
+ if (roadId1 == roadId) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- } else {
|
|
|
- /*
|
|
|
- 不新建墙:
|
|
|
- 1. 更新坐标(一种是当pointId的parent是2个,另一种是三个,但是roadId对应的两堵墙接近180°)
|
|
|
- 2. 拆分墙
|
|
|
- 3. 吸附邻居墙的另一个端点
|
|
|
- 新建墙:
|
|
|
- */
|
|
|
- // 不新建墙
|
|
|
- if (!needNew) {
|
|
|
- if (!virtualInfo.adsorb) {
|
|
|
- // 只更新坐标
|
|
|
- if (Object.keys(point.parent).length == 2) {
|
|
|
- point.setPosition(virtualInfo.virtualPosition);
|
|
|
- } else {
|
|
|
- const info = roadService.roadIdForMinAngle(pointId, roadId);
|
|
|
- const angle = roadService.AngleForRoad(
|
|
|
- info.min0.roadId,
|
|
|
- info.min1.roadId
|
|
|
- );
|
|
|
- // 只更新坐标
|
|
|
- if (
|
|
|
- Object.keys(point.parent).length == 3 &&
|
|
|
- angle > Constant.maxAngle
|
|
|
- ) {
|
|
|
- point.setPosition(virtualInfo.virtualPosition);
|
|
|
- }
|
|
|
- // 拆分墙
|
|
|
- else {
|
|
|
- const dir = roadService.getDirction(pointId, roadId);
|
|
|
- // 先断开链接
|
|
|
- roadService.subtraRoadFromIntersect(pointId, roadId);
|
|
|
- const newPointId = road.getPointId(dir);
|
|
|
- const newPoint = dataService.getPoint(newPointId);
|
|
|
- // 更新新坐标
|
|
|
- newPoint.setPosition(virtualInfo.virtualPosition);
|
|
|
- // 拆分
|
|
|
- roadService.splitRoad(limitRoadId, newPointId, dir);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ const road1 = dataService.getRoad(roadId1);
|
|
|
+ const otherPointId1 = road1.getOtherPointId(pointId1);
|
|
|
+ const otherPoint1 = dataService.getPoint(otherPointId1);
|
|
|
+
|
|
|
+ for (const roadId2 in parent2) {
|
|
|
+ if (roadId2 == roadId) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- // 吸附邻居墙的另一个端点。
|
|
|
- else {
|
|
|
- roadService.moveTo(pointId, virtualInfo.adsorbPointId);
|
|
|
+ const road2 = dataService.getRoad(roadId2);
|
|
|
+ const otherPointId2 = road2.getOtherPointId(pointId2);
|
|
|
+ const otherPoint2 = dataService.getPoint(otherPointId2);
|
|
|
+ const angle = mathUtil.Angle(point2, otherPoint1, otherPoint2);
|
|
|
+ if (Math.abs(angle) < Constant.minAngle) {
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
- // 新建墙
|
|
|
- else {
|
|
|
- this.createRoadForMoveRoad(
|
|
|
- pointId,
|
|
|
- roadId,
|
|
|
- virtualInfo.virtualPosition
|
|
|
+ }
|
|
|
+ // pointId1,pointId2属于同一堵墙
|
|
|
+ if (roadId != null) {
|
|
|
+ dataService.deleteRoad(roadId);
|
|
|
+ }
|
|
|
+
|
|
|
+ point1 = dataService.getPoint(pointId1);
|
|
|
+ point2 = dataService.getPoint(pointId2);
|
|
|
+ if (!point1 || !point2) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //准备合并
|
|
|
+ for (const roadId1 in parent1) {
|
|
|
+ const road1 = dataService.getRoad(roadId1);
|
|
|
+ const otherPointId = road1.getOtherPointId(pointId1);
|
|
|
+ const _roadId = this.getRoadId(otherPointId, pointId2);
|
|
|
+ if (_roadId != null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // road1上pointId1被pointId2取代
|
|
|
+ if (road1.startId == pointId1) {
|
|
|
+ dataService.deletePoint(road1.startId, roadId1);
|
|
|
+ road1.startId = pointId2;
|
|
|
+ point2.setPointParent(roadId1, "start");
|
|
|
+ } else if (road1.endId == pointId1) {
|
|
|
+ dataService.deletePoint(road1.endId, roadId1);
|
|
|
+ road1.endId = pointId2;
|
|
|
+ point2.setPointParent(roadId1, "end");
|
|
|
+ } else {
|
|
|
+ console.error(
|
|
|
+ "roadService.moveTo****************************************************"
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ edgeService.updateEdgeForMovePoint(pointId2);
|
|
|
+ for (let key in parent2) {
|
|
|
+ roadService.setLanes(key);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//
|