|
@@ -1,6 +1,6 @@
|
|
|
import { dataService } from "./DataService";
|
|
|
-import { pointService } from "./PointService";
|
|
|
-import { edgeService } from "./EdgeService";
|
|
|
+import { curvePointService } from "./CurvePointService";
|
|
|
+import { curveEdgeService } from "./CurveEdgeService";
|
|
|
import { mathUtil } from "../Util/MathUtil.js";
|
|
|
import CurveRoad from "../Geometry/CurveRoad.js";
|
|
|
import VectorType from "../enum/VectorType";
|
|
@@ -12,27 +12,26 @@ export default class CurveRoadService {
|
|
|
let curveRoad = new CurveRoad(startId, endId, vectorId);
|
|
|
dataService.addCurveRoad(curveRoad);
|
|
|
|
|
|
- let startPoint = dataService.getPoint(startId);
|
|
|
- startPoint.setPointParent(curveRoad.vectorId, "start");
|
|
|
- startPoint.setGeoType(VectorType.CurveRoadCorner);
|
|
|
-
|
|
|
- let endPoint = dataService.getPoint(endId);
|
|
|
- endPoint.setPointParent(curveRoad.vectorId, "end");
|
|
|
- endPoint.setGeoType(VectorType.CurveRoadCorner);
|
|
|
+ let startPoint = dataService.getCurvePoint(startId);
|
|
|
+ startPoint.setPointParent(curveRoad.vectorId);
|
|
|
+ startPoint.setIndex(0);
|
|
|
+ let endPoint = dataService.getCurvePoint(endId);
|
|
|
+ endPoint.setPointParent(curveRoad.vectorId);
|
|
|
+ endPoint.setIndex(2);
|
|
|
|
|
|
let edgePoints = mathUtil.RectangleVertex(
|
|
|
startPoint,
|
|
|
endPoint,
|
|
|
curveRoad.width
|
|
|
);
|
|
|
- let leftEdge = edgeService.create(
|
|
|
+ let leftEdge = curveEdgeService.create(
|
|
|
edgePoints.leftEdgeStart,
|
|
|
edgePoints.leftEdgeEnd,
|
|
|
null,
|
|
|
vectorId
|
|
|
);
|
|
|
|
|
|
- let rightEdge = edgeService.create(
|
|
|
+ let rightEdge = curveEdgeService.create(
|
|
|
edgePoints.rightEdgeStart,
|
|
|
edgePoints.rightEdgeEnd,
|
|
|
null,
|
|
@@ -48,56 +47,90 @@ export default class CurveRoadService {
|
|
|
|
|
|
curveRoad.points.push(startPoint);
|
|
|
curveRoad.points.push(endPoint);
|
|
|
- this.addCPoint(
|
|
|
- curveRoad,
|
|
|
- {
|
|
|
- x: (startPoint.x + endPoint.x) / 2,
|
|
|
- y: (startPoint.y + endPoint.y) / 2,
|
|
|
- },
|
|
|
- 0
|
|
|
- );
|
|
|
- curveRoad.leftEdgePoints.push(edgePoints.leftEdgeStart);
|
|
|
- curveRoad.leftEdgePoints.push(edgePoints.leftEdgeEnd);
|
|
|
|
|
|
- curveRoad.rightEdgePoints.push(edgePoints.rightEdgeStart);
|
|
|
- curveRoad.rightEdgePoints.push(edgePoints.rightEdgeEnd);
|
|
|
+ leftEdge.points.push(edgePoints.leftEdgeStart);
|
|
|
+ leftEdge.points.push(edgePoints.leftEdgeEnd);
|
|
|
+
|
|
|
+ rightEdge.points.push(edgePoints.rightEdgeStart);
|
|
|
+ rightEdge.points.push(edgePoints.rightEdgeEnd);
|
|
|
|
|
|
let lanes = this.setLanes(
|
|
|
curveRoad.points,
|
|
|
- curveRoad.leftEdgePoints,
|
|
|
- curveRoad.rightEdgePoints,
|
|
|
+ leftEdge.points,
|
|
|
+ rightEdge.points,
|
|
|
curveRoad.leftDrivewayCount,
|
|
|
curveRoad.rightDrivewayCount
|
|
|
);
|
|
|
curveRoad.leftLanes = lanes.leftLanes;
|
|
|
curveRoad.rightLanes = lanes.rightLanes;
|
|
|
+
|
|
|
+ this.addCPoint(
|
|
|
+ curveRoad,
|
|
|
+ {
|
|
|
+ x: (startPoint.x + endPoint.x) / 2,
|
|
|
+ y: (startPoint.y + endPoint.y) / 2,
|
|
|
+ },
|
|
|
+ 0
|
|
|
+ );
|
|
|
+
|
|
|
return curveRoad;
|
|
|
}
|
|
|
|
|
|
+ //不能加首尾,只能加中间
|
|
|
addCPoint(curveRoad, position, startIndex) {
|
|
|
- let point = pointService.create(position);
|
|
|
+ let point = curvePointService.create(position);
|
|
|
curveRoad.points.splice(startIndex + 1, 0, point);
|
|
|
- point.setGeoType(VectorType.CurveRoadCorner);
|
|
|
point.setPointParent(curveRoad.vectorId, startIndex + 1);
|
|
|
+ point.setIndex(startIndex + 1);
|
|
|
for (let i = startIndex + 2; i < curveRoad.points.length; ++i) {
|
|
|
- let parent = curveRoad.points[i].getParent();
|
|
|
- if (
|
|
|
- parent[curveRoad.vectorId] != "start" &&
|
|
|
- parent[curveRoad.vectorId] != "end"
|
|
|
- ) {
|
|
|
- ++parent[curveRoad.vectorId];
|
|
|
- }
|
|
|
+ curveRoad.points[i].setIndex(i);
|
|
|
}
|
|
|
+
|
|
|
+ const leftCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
|
|
|
+ let leftLine = mathUtil.createLine1(
|
|
|
+ leftCurveEdge.points[startIndex],
|
|
|
+ leftCurveEdge.points[startIndex + 1]
|
|
|
+ );
|
|
|
+ const leftJoin = mathUtil.getLineForPoint(leftLine, position);
|
|
|
+ leftCurveEdge.points.splice(startIndex + 1, 0, leftJoin);
|
|
|
+
|
|
|
+ const rightCurveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
|
|
|
+ let rightLine = mathUtil.createLine1(
|
|
|
+ rightCurveEdge.points[startIndex],
|
|
|
+ rightCurveEdge.points[startIndex + 1]
|
|
|
+ );
|
|
|
+ const rightJoin = mathUtil.getLineForPoint(rightLine, position);
|
|
|
+ rightCurveEdge.points.splice(startIndex + 1, 0, rightJoin);
|
|
|
+
|
|
|
+ this.insertCPointToLanes(curveRoad, position, startIndex);
|
|
|
}
|
|
|
|
|
|
- moveCPoint(position) {}
|
|
|
+ insertCPointToLanes(curveRoad, position, index) {
|
|
|
+ for (let i = 0; i < curveRoad.leftLanes.length; ++i) {
|
|
|
+ let leftLine = mathUtil.createLine1(
|
|
|
+ curveRoad.leftLanes[i][index],
|
|
|
+ curveRoad.leftLanes[i][index + 1]
|
|
|
+ );
|
|
|
+ const leftJoin = mathUtil.getLineForPoint(leftLine, position);
|
|
|
+ curveRoad.leftLanes[i].splice(index + 1, 0, leftJoin);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let i = 0; i < curveRoad.rightLanes.length; ++i) {
|
|
|
+ let rightLine = mathUtil.createLine1(
|
|
|
+ curveRoad.rightLanes[i][index],
|
|
|
+ curveRoad.rightLanes[i][index + 1]
|
|
|
+ );
|
|
|
+ const rightJoin = mathUtil.getLineForPoint(rightLine, position);
|
|
|
+ curveRoad.rightLanes[i].splice(index + 1, 0, rightJoin);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
setLanesPoints(curveRoadId) {
|
|
|
let curveRoad = dataService.getCurveRoad(curveRoadId);
|
|
|
let startPoint = dataService.getPoint(curveRoad.startId);
|
|
|
let endPoint = dataService.getPoint(curveRoad.endId);
|
|
|
|
|
|
- let midPoint = pointService.create({
|
|
|
+ let midPoint = curvePointService.create({
|
|
|
x: (startPoint.x + endPoint.x) / 2,
|
|
|
y: (startPoint.y + endPoint.y) / 2,
|
|
|
});
|
|
@@ -131,7 +164,9 @@ export default class CurveRoadService {
|
|
|
|
|
|
for (let i = 0; i < leftCount - 1; ++i) {
|
|
|
for (let j = 0; j < points.length; ++j) {
|
|
|
- leftLanes[i] = [];
|
|
|
+ if (!leftLanes[i]) {
|
|
|
+ leftLanes[i] = [];
|
|
|
+ }
|
|
|
leftLanes[i][j] = {};
|
|
|
if (j == 0) {
|
|
|
leftLanes[i][j].x = points[j].x + leftdx1 * (i + 1);
|
|
@@ -186,7 +221,9 @@ export default class CurveRoadService {
|
|
|
|
|
|
for (let i = 0; i < rightCount - 1; ++i) {
|
|
|
for (let j = 0; j < points.length; ++j) {
|
|
|
- rightLanes[i] = [];
|
|
|
+ if (!rightLanes[i]) {
|
|
|
+ rightLanes[i] = [];
|
|
|
+ }
|
|
|
rightLanes[i][j] = {};
|
|
|
if (j == 0) {
|
|
|
rightLanes[i][j].x = points[j].x + rightdx1 * (i + 1);
|
|
@@ -231,107 +268,142 @@ export default class CurveRoadService {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- updateForMovePoint(curveRoad, point) {
|
|
|
- let index = -1;
|
|
|
- for (let i = 0; i < curveRoad.points.length; ++i) {
|
|
|
- if (curveRoad.points[i].vectorId == point.vectorId) {
|
|
|
- index = i;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const len = points.length;
|
|
|
- let leftdx1 = leftEdgePoints[0].x - points[0].x;
|
|
|
- leftdx1 = leftdx1 / leftCount;
|
|
|
+ updateForMovePoint(pointId, position) {
|
|
|
+ let curvePoint = dataService.getCurvePoint(pointId);
|
|
|
+ let curveRoadId = curvePoint.getParent();
|
|
|
+ let curveRoad = dataService.getCurveRoad(curveRoadId);
|
|
|
|
|
|
- let leftdy1 = leftEdgePoints[0].y - points[0].y;
|
|
|
- leftdy1 = leftdy1 / leftCount;
|
|
|
+ let dx = position.x - curvePoint.x;
|
|
|
+ let dy = position.y - curvePoint.y;
|
|
|
+ let index = curvePoint.getIndex();
|
|
|
|
|
|
- let leftdx2 = leftEdgePoints[len - 1].x - points[len - 1].x;
|
|
|
- leftdx2 = leftdx2 / leftCount;
|
|
|
+ curvePoint.setPosition(position);
|
|
|
|
|
|
- let leftdy2 = leftEdgePoints[len - 1].y - points[len - 1].y;
|
|
|
- leftdy2 = leftdy2 / leftCount;
|
|
|
-
|
|
|
- for (let i = 0; i < leftCount - 1; ++i) {
|
|
|
- if (index == 0) {
|
|
|
- curveRoad.leftLanes[i][index].x = points[index].x + leftdx1 * (i + 1);
|
|
|
- curveRoad.leftLanes[i][index].y = points[index].y + leftdy1 * (i + 1);
|
|
|
- } else if (index == points.length - 1) {
|
|
|
- curveRoad.leftLanes[i][index].x = points[index].x + leftdx2 * (i + 1);
|
|
|
- curveRoad.leftLanes[i][index].y = points[index].y + leftdy2 * (i + 1);
|
|
|
- } else {
|
|
|
- let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
- points[index],
|
|
|
- points[index - 1],
|
|
|
- leftdx1
|
|
|
- );
|
|
|
- let line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.leftEdgeStart,
|
|
|
- edgePoints1.leftEdgeEnd
|
|
|
- );
|
|
|
-
|
|
|
- let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
- points[index],
|
|
|
- points[index + 1],
|
|
|
- leftdx1
|
|
|
- );
|
|
|
- let line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.leftEdgeStart,
|
|
|
- edgePoints2.leftEdgeEnd
|
|
|
- );
|
|
|
-
|
|
|
- let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
- curveRoad.leftLanes[i][index].x = join.x;
|
|
|
- curveRoad.leftLanes[i][index].y = join.y;
|
|
|
- }
|
|
|
+ const leftCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
|
|
|
+ leftCurveEdge.points[index].x += dx;
|
|
|
+ leftCurveEdge.points[index].y += dy;
|
|
|
+ for (let i = 0; i < curveRoad.leftLanes.length; ++i) {
|
|
|
+ curveRoad.leftLanes[i][index].x += dx;
|
|
|
+ curveRoad.leftLanes[i][index].y += dy;
|
|
|
}
|
|
|
|
|
|
- let rightdx1 = rightEdgePoints[0].x - points[0].x;
|
|
|
- rightdx1 = rightdx1 / rightCount;
|
|
|
-
|
|
|
- let rightdy1 = rightEdgePoints[0].y - points[0].y;
|
|
|
- rightdy1 = rightdy1 / rightCount;
|
|
|
-
|
|
|
- let rightdx2 = rightEdgePoints[len - 1].x - points[len - 1].x;
|
|
|
- rightdx2 = rightdx2 / rightCount;
|
|
|
-
|
|
|
- let rightdy2 = rightEdgePoints[len - 1].y - points[len - 1].y;
|
|
|
- rightdy2 = rightdy2 / rightCount;
|
|
|
-
|
|
|
- for (let i = 0; i < rightCount - 1; ++i) {
|
|
|
- if (index == 0) {
|
|
|
- curveRoad.rightLanes[i][index].x = points[index].x + rightdx1 * (i + 1);
|
|
|
- curveRoad.rightLanes[i][index].y = points[index].y + rightdy1 * (i + 1);
|
|
|
- } else if (index == points.length - 1) {
|
|
|
- curveRoad.rightLanes[i][index].x = points[index].x + rightdy2 * (i + 1);
|
|
|
- curveRoad.rightLanes[i][index].y = points[index].y + rightdy2 * (i + 1);
|
|
|
- } else {
|
|
|
- let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
- points[index],
|
|
|
- points[index - 1],
|
|
|
- rightdx1
|
|
|
- );
|
|
|
- let line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.rightEdgeStart,
|
|
|
- edgePoints1.rightEdgeEnd
|
|
|
- );
|
|
|
-
|
|
|
- let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
- points[index],
|
|
|
- points[index + 1],
|
|
|
- rightdx1
|
|
|
- );
|
|
|
- let line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.rightEdgeStart,
|
|
|
- edgePoints2.rightEdgeEnd
|
|
|
- );
|
|
|
-
|
|
|
- let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
- curveRoad.rightLanes[i][index].x = join.x;
|
|
|
- curveRoad.rightLanes[i][index].y = join.y;
|
|
|
- }
|
|
|
+ const rightCurveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
|
|
|
+ rightCurveEdge.points[index].x += dx;
|
|
|
+ rightCurveEdge.points[index].y += dy;
|
|
|
+ for (let i = 0; i < curveRoad.rightLanes.length; ++i) {
|
|
|
+ curveRoad.rightLanes[i][index].x += dx;
|
|
|
+ curveRoad.rightLanes[i][index].y += dy;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // updateForMovePoint(curveRoad, index) {
|
|
|
+ // let points = curveRoad.points;
|
|
|
+ // let leftEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
|
|
|
+ // let rightEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
|
|
|
+ // let leftEdgePoints = leftEdge.points;
|
|
|
+ // let rightEdgePoints = rightEdge.points;
|
|
|
+ // let leftCount = curveRoad.leftDrivewayCount;
|
|
|
+ // let rightCount = curveRoad.rightDrivewayCount;
|
|
|
+
|
|
|
+ // const len = points.length;
|
|
|
+ // let leftdx1 = leftEdgePoints[0].x - points[0].x;
|
|
|
+ // leftdx1 = leftdx1 / leftCount;
|
|
|
+
|
|
|
+ // let leftdy1 = leftEdgePoints[0].y - points[0].y;
|
|
|
+ // leftdy1 = leftdy1 / leftCount;
|
|
|
+
|
|
|
+ // let leftdx2 = leftEdgePoints[len - 1].x - points[len - 1].x;
|
|
|
+ // leftdx2 = leftdx2 / leftCount;
|
|
|
+
|
|
|
+ // let leftdy2 = leftEdgePoints[len - 1].y - points[len - 1].y;
|
|
|
+ // leftdy2 = leftdy2 / leftCount;
|
|
|
+
|
|
|
+ // for (let i = 0; i < leftCount - 1; ++i) {
|
|
|
+ // if (index == 0) {
|
|
|
+ // curveRoad.leftLanes[i][index].x = points[index].x + leftdx1 * (i + 1);
|
|
|
+ // curveRoad.leftLanes[i][index].y = points[index].y + leftdy1 * (i + 1);
|
|
|
+ // } else if (index == points.length - 1) {
|
|
|
+ // curveRoad.leftLanes[i][index].x = points[index].x + leftdx2 * (i + 1);
|
|
|
+ // curveRoad.leftLanes[i][index].y = points[index].y + leftdy2 * (i + 1);
|
|
|
+ // } else {
|
|
|
+ // let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
+ // points[index],
|
|
|
+ // points[index - 1],
|
|
|
+ // leftdx1
|
|
|
+ // );
|
|
|
+ // let line1 = mathUtil.createLine1(
|
|
|
+ // edgePoints1.leftEdgeStart,
|
|
|
+ // edgePoints1.leftEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
+ // points[index],
|
|
|
+ // points[index + 1],
|
|
|
+ // leftdx1
|
|
|
+ // );
|
|
|
+ // let line2 = mathUtil.createLine1(
|
|
|
+ // edgePoints2.leftEdgeStart,
|
|
|
+ // edgePoints2.leftEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
+ // if (join == null) {
|
|
|
+ // join = mathUtil.getLineForPoint(line1, points[index]);
|
|
|
+ // }
|
|
|
+ // curveRoad.leftLanes[i][index].x = join.x;
|
|
|
+ // curveRoad.leftLanes[i][index].y = join.y;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // let rightdx1 = rightEdgePoints[0].x - points[0].x;
|
|
|
+ // rightdx1 = rightdx1 / rightCount;
|
|
|
+
|
|
|
+ // let rightdy1 = rightEdgePoints[0].y - points[0].y;
|
|
|
+ // rightdy1 = rightdy1 / rightCount;
|
|
|
+
|
|
|
+ // let rightdx2 = rightEdgePoints[len - 1].x - points[len - 1].x;
|
|
|
+ // rightdx2 = rightdx2 / rightCount;
|
|
|
+
|
|
|
+ // let rightdy2 = rightEdgePoints[len - 1].y - points[len - 1].y;
|
|
|
+ // rightdy2 = rightdy2 / rightCount;
|
|
|
+
|
|
|
+ // for (let i = 0; i < rightCount - 1; ++i) {
|
|
|
+ // if (index == 0) {
|
|
|
+ // curveRoad.rightLanes[i][index].x = points[index].x + rightdx1 * (i + 1);
|
|
|
+ // curveRoad.rightLanes[i][index].y = points[index].y + rightdy1 * (i + 1);
|
|
|
+ // } else if (index == points.length - 1) {
|
|
|
+ // curveRoad.rightLanes[i][index].x = points[index].x + rightdy2 * (i + 1);
|
|
|
+ // curveRoad.rightLanes[i][index].y = points[index].y + rightdy2 * (i + 1);
|
|
|
+ // } else {
|
|
|
+ // let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
+ // points[index],
|
|
|
+ // points[index - 1],
|
|
|
+ // rightdx1
|
|
|
+ // );
|
|
|
+ // let line1 = mathUtil.createLine1(
|
|
|
+ // edgePoints1.rightEdgeStart,
|
|
|
+ // edgePoints1.rightEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
+ // points[index],
|
|
|
+ // points[index + 1],
|
|
|
+ // rightdx1
|
|
|
+ // );
|
|
|
+ // let line2 = mathUtil.createLine1(
|
|
|
+ // edgePoints2.rightEdgeStart,
|
|
|
+ // edgePoints2.rightEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
+ // if (join == null) {
|
|
|
+ // join = mathUtil.getLineForPoint(line1, points[index]);
|
|
|
+ // }
|
|
|
+ // curveRoad.rightLanes[i][index].x = join.x;
|
|
|
+ // curveRoad.rightLanes[i][index].y = join.y;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
const curveRoadService = new CurveRoadService();
|