|
@@ -4,6 +4,7 @@ import { curveEdgeService } from "./CurveEdgeService";
|
|
|
import { mathUtil } from "../Util/MathUtil.js";
|
|
|
import CurveRoad from "../Geometry/CurveRoad.js";
|
|
|
import VectorType from "../enum/VectorType";
|
|
|
+import Constant from "../Constant";
|
|
|
import RoadService from "./RoadService";
|
|
|
|
|
|
export default class CurveRoadService extends RoadService {
|
|
@@ -57,17 +58,7 @@ export default class CurveRoadService extends RoadService {
|
|
|
rightEdge.points.push(edgePoints.rightEdgeStart);
|
|
|
rightEdge.points.push(edgePoints.rightEdgeEnd);
|
|
|
|
|
|
- let lanes = this.setLanes(
|
|
|
- curveRoad.points,
|
|
|
- leftEdge.points,
|
|
|
- rightEdge.points,
|
|
|
- curveRoad.leftDrivewayCount,
|
|
|
- curveRoad.rightDrivewayCount
|
|
|
- );
|
|
|
- curveRoad.leftLanes = lanes.leftLanes;
|
|
|
- curveRoad.rightLanes = lanes.rightLanes;
|
|
|
- curveRoad.leftLanesCurves = lanes.leftLanesCurves;
|
|
|
- curveRoad.rightLanesCurves = lanes.rightLanesCurves;
|
|
|
+ this.setLanes(curveRoad);
|
|
|
|
|
|
this.addCPoint(
|
|
|
curveRoad,
|
|
@@ -77,7 +68,6 @@ export default class CurveRoadService extends RoadService {
|
|
|
},
|
|
|
0
|
|
|
);
|
|
|
- this.setCurves(curveRoad);
|
|
|
return curveRoad;
|
|
|
}
|
|
|
|
|
@@ -85,38 +75,142 @@ export default class CurveRoadService extends RoadService {
|
|
|
addCPoint(curveRoad, position, startIndex) {
|
|
|
let point = curvePointService.create(position);
|
|
|
curveRoad.points.splice(startIndex + 1, 0, point);
|
|
|
- point.setPointParent(curveRoad.vectorId, startIndex + 1);
|
|
|
+ point.setPointParent(curveRoad.vectorId, startIndex);
|
|
|
point.setIndex(startIndex + 1);
|
|
|
for (let i = startIndex + 2; i < curveRoad.points.length; ++i) {
|
|
|
curveRoad.points[i].setIndex(i);
|
|
|
}
|
|
|
|
|
|
+ let leftCount = curveRoad.leftDrivewayCount;
|
|
|
+ let rightCount = curveRoad.rightDrivewayCount;
|
|
|
+ let leftJoin = null;
|
|
|
+ let rightJoin = null;
|
|
|
const leftCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
|
|
|
- let leftLine = mathUtil.createLine1(
|
|
|
+ const rightCurveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
|
|
|
+ let line1 = mathUtil.createLine1(
|
|
|
+ curveRoad.points[startIndex],
|
|
|
+ curveRoad.points[startIndex + 1]
|
|
|
+ );
|
|
|
+ let line2 = mathUtil.createLine1(
|
|
|
+ curveRoad.points[startIndex + 1],
|
|
|
+ curveRoad.points[startIndex + 2]
|
|
|
+ );
|
|
|
+
|
|
|
+ const leftLine = mathUtil.createLine1(
|
|
|
leftCurveEdge.points[startIndex],
|
|
|
leftCurveEdge.points[startIndex + 1]
|
|
|
);
|
|
|
- const leftJoin = mathUtil.getJoinLinePoint(position, leftLine);
|
|
|
- leftCurveEdge.points.splice(startIndex + 1, 0, leftJoin);
|
|
|
- curveEdgeService.setCurves(leftCurveEdge);
|
|
|
+ let leftLine1 = mathUtil.createLine3(
|
|
|
+ line1,
|
|
|
+ leftCurveEdge.points[startIndex]
|
|
|
+ );
|
|
|
+ let leftLine2 = mathUtil.createLine3(
|
|
|
+ line2,
|
|
|
+ leftCurveEdge.points[startIndex + 1]
|
|
|
+ );
|
|
|
|
|
|
- const rightCurveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
|
|
|
- let rightLine = mathUtil.createLine1(
|
|
|
+ const rightLine = mathUtil.createLine1(
|
|
|
rightCurveEdge.points[startIndex],
|
|
|
rightCurveEdge.points[startIndex + 1]
|
|
|
);
|
|
|
- const rightJoin = mathUtil.getJoinLinePoint(position, rightLine);
|
|
|
- rightCurveEdge.points.splice(startIndex + 1, 0, rightJoin);
|
|
|
- curveEdgeService.setCurves(rightCurveEdge);
|
|
|
+ let rightLine1 = mathUtil.createLine3(
|
|
|
+ line1,
|
|
|
+ rightCurveEdge.points[startIndex]
|
|
|
+ );
|
|
|
+ let rightLine2 = mathUtil.createLine3(
|
|
|
+ line2,
|
|
|
+ rightCurveEdge.points[startIndex + 1]
|
|
|
+ );
|
|
|
+
|
|
|
+ if (
|
|
|
+ mathUtil.Angle(
|
|
|
+ curveRoad.points[startIndex + 1],
|
|
|
+ curveRoad.points[startIndex],
|
|
|
+ curveRoad.points[startIndex + 2]
|
|
|
+ ) > Constant.maxAngle
|
|
|
+ ) {
|
|
|
+ leftJoin = mathUtil.getJoinLinePoint(position, leftLine);
|
|
|
+ leftCurveEdge.points.splice(startIndex + 1, 0, leftJoin);
|
|
|
+ curveEdgeService.setCurves(leftCurveEdge);
|
|
|
+
|
|
|
+ rightJoin = mathUtil.getJoinLinePoint(position, rightLine);
|
|
|
+ rightCurveEdge.points.splice(startIndex + 1, 0, rightJoin);
|
|
|
+ curveEdgeService.setCurves(rightCurveEdge);
|
|
|
+
|
|
|
+ for (let i = 0; i < leftCount; ++i) {
|
|
|
+ const leftLaneLine = mathUtil.createLine1(
|
|
|
+ curveRoad.leftLanes[i][startIndex],
|
|
|
+ curveRoad.leftLanes[i][startIndex + 1]
|
|
|
+ );
|
|
|
+ leftJoin = mathUtil.getJoinLinePoint(position, leftLaneLine);
|
|
|
+ curveRoad.leftLanes[i].splice(startIndex + 1, 0, leftJoin);
|
|
|
+ curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
|
|
|
+ curveRoad.leftLanes[i]
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let i = 0; i < rightCount; ++i) {
|
|
|
+ const rightLaneLine = mathUtil.createLine1(
|
|
|
+ curveRoad.rightLanes[i][startIndex],
|
|
|
+ curveRoad.rightLanes[i][startIndex + 1]
|
|
|
+ );
|
|
|
+ rightJoin = mathUtil.getJoinLinePoint(position, rightLaneLine);
|
|
|
+ curveRoad.rightLanes[i].splice(startIndex + 1, 0, rightJoin);
|
|
|
+ curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
|
|
|
+ curveRoad.rightLanes[i]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ leftJoin = mathUtil.getIntersectionPoint(leftLine1, leftLine2);
|
|
|
+ leftCurveEdge.points.splice(startIndex + 1, 0, leftJoin);
|
|
|
+ curveEdgeService.setCurves(leftCurveEdge);
|
|
|
+
|
|
|
+ for (let i = 0; i < leftCount; ++i) {
|
|
|
+ leftLine1 = mathUtil.createLine3(
|
|
|
+ line1,
|
|
|
+ curveRoad.leftLanes[i][startIndex]
|
|
|
+ );
|
|
|
+ leftLine2 = mathUtil.createLine3(
|
|
|
+ line2,
|
|
|
+ curveRoad.leftLanes[i][startIndex + 1]
|
|
|
+ );
|
|
|
+ leftJoin = mathUtil.getIntersectionPoint(leftLine1, leftLine2);
|
|
|
+ curveRoad.leftLanes[i].splice(startIndex + 1, 0, leftJoin);
|
|
|
+ curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
|
|
|
+ curveRoad.leftLanes[i]
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
- this.insertCPointToLanes(curveRoad, position, startIndex);
|
|
|
+ rightJoin = mathUtil.getIntersectionPoint(rightLine1, rightLine2);
|
|
|
+ rightCurveEdge.points.splice(startIndex + 1, 0, rightJoin);
|
|
|
+ curveEdgeService.setCurves(rightCurveEdge);
|
|
|
+
|
|
|
+ for (let i = 0; i < rightCount; ++i) {
|
|
|
+ rightLine1 = mathUtil.createLine3(
|
|
|
+ line1,
|
|
|
+ curveRoad.rightLanes[i][startIndex]
|
|
|
+ );
|
|
|
+ rightLine2 = mathUtil.createLine3(
|
|
|
+ line2,
|
|
|
+ curveRoad.rightLanes[i][startIndex + 1]
|
|
|
+ );
|
|
|
+ rightJoin = mathUtil.getIntersectionPoint(rightLine1, rightLine2);
|
|
|
+ curveRoad.rightLanes[i].splice(startIndex + 1, 0, rightJoin);
|
|
|
+ curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
|
|
|
+ curveRoad.rightLanes[i]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.setCurves(curveRoad);
|
|
|
}
|
|
|
|
|
|
subCPoint(curveRoad, index) {
|
|
|
+ dataService.deleteCurvePoint(curveRoad.points[index].vectorId);
|
|
|
curveRoad.points.splice(index, 1);
|
|
|
for (let i = index; i < curveRoad.points.length; ++i) {
|
|
|
curveRoad.points[i].setIndex(i);
|
|
|
}
|
|
|
+ this.setCurves(curveRoad);
|
|
|
|
|
|
const leftCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
|
|
|
leftCurveEdge.points.splice(index, 1);
|
|
@@ -129,41 +223,21 @@ export default class CurveRoadService extends RoadService {
|
|
|
this.removeCPointToLanes(curveRoad, index);
|
|
|
}
|
|
|
|
|
|
- insertCPointToLanes(curveRoad, position, index) {
|
|
|
+ removeCPointToLanes(curveRoad, 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.getJoinLinePoint(position, leftLine);
|
|
|
- curveRoad.leftLanes[i].splice(index + 1, 0, leftJoin);
|
|
|
+ curveRoad.leftLanes[i].splice(index, 1);
|
|
|
curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
|
|
|
curveRoad.leftLanes[i]
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
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.getJoinLinePoint(position, rightLine);
|
|
|
- curveRoad.rightLanes[i].splice(index + 1, 0, rightJoin);
|
|
|
+ curveRoad.rightLanes[i].splice(index, 1);
|
|
|
curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
|
|
|
curveRoad.rightLanes[i]
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- removeCPointToLanes(curveRoad, index) {
|
|
|
- for (let i = 0; i < curveRoad.leftLanes.length; ++i) {
|
|
|
- curveRoad.leftLanes[i].splice(index, 1);
|
|
|
- }
|
|
|
- for (let i = 0; i < curveRoad.rightLanes.length; ++i) {
|
|
|
- curveRoad.rightLanes[i].splice(index, 1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
setLanesPoints(curveRoadId) {
|
|
|
let curveRoad = dataService.getCurveRoad(curveRoadId);
|
|
|
let startPoint = dataService.getPoint(curveRoad.startId);
|
|
@@ -182,135 +256,156 @@ export default class CurveRoadService extends RoadService {
|
|
|
|
|
|
//车道
|
|
|
//points的第一个元素是start,最后一个是end
|
|
|
- setLanes(points, leftEdgePoints, rightEdgePoints, leftCount, rightCount) {
|
|
|
+ setLanes(curveRoad, dir) {
|
|
|
+ let points = curveRoad.points;
|
|
|
+ const leftEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
|
|
|
+ const rightEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
|
|
|
+ const leftEdgePoints = leftEdge.points;
|
|
|
+ const rightEdgePoints = rightEdge.points;
|
|
|
+ const leftCount = curveRoad.leftDrivewayCount;
|
|
|
+ const rightCount = curveRoad.rightDrivewayCount;
|
|
|
+
|
|
|
let leftLanes = [];
|
|
|
let leftLanesCurves = [];
|
|
|
let rightLanes = [];
|
|
|
let rightLanesCurves = [];
|
|
|
|
|
|
const len = points.length;
|
|
|
- let leftdx1 = leftEdgePoints[0].x - points[0].x;
|
|
|
- leftdx1 = leftdx1 / (leftCount + 1);
|
|
|
-
|
|
|
- let leftdy1 = leftEdgePoints[0].y - points[0].y;
|
|
|
- leftdy1 = leftdy1 / (leftCount + 1);
|
|
|
-
|
|
|
- let leftdx2 =
|
|
|
- leftEdgePoints[leftEdgePoints.length - 1].x - points[len - 1].x;
|
|
|
- leftdx2 = leftdx2 / (leftCount + 1);
|
|
|
+ // let leftdx1 = leftEdgePoints[0].x - points[0].x;
|
|
|
+ // leftdx1 = leftdx1 / (leftCount + 1);
|
|
|
|
|
|
- let leftdy2 =
|
|
|
- leftEdgePoints[leftEdgePoints.length - 1].y - points[len - 1].y;
|
|
|
- leftdy2 = leftdy2 / (leftCount + 1);
|
|
|
+ // let leftdy1 = leftEdgePoints[0].y - points[0].y;
|
|
|
+ // leftdy1 = leftdy1 / (leftCount + 1);
|
|
|
|
|
|
- for (let i = 0; i < leftCount; ++i) {
|
|
|
- for (let j = 0; j < points.length; ++j) {
|
|
|
- if (!leftLanes[i]) {
|
|
|
- leftLanes[i] = [];
|
|
|
- }
|
|
|
- leftLanes[i][j] = {};
|
|
|
- if (j == 0) {
|
|
|
- leftLanes[i][j].x = points[j].x + leftdx1 * (i + 1);
|
|
|
- leftLanes[i][j].y = points[j].y + leftdy1 * (i + 1);
|
|
|
- } else if (j == points.length - 1) {
|
|
|
- leftLanes[i][j].x = points[j].x + leftdx2 * (i + 1);
|
|
|
- leftLanes[i][j].y = points[j].y + leftdy2 * (i + 1);
|
|
|
- } else {
|
|
|
- let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
- points[j],
|
|
|
- points[j - 1],
|
|
|
- ((leftEdgePoints[j].x - points[j].x) / (leftCount + 1)) * (i + 1)
|
|
|
- );
|
|
|
- let line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.leftEdgeStart,
|
|
|
- edgePoints1.leftEdgeEnd
|
|
|
- );
|
|
|
+ // let leftdx2 =
|
|
|
+ // leftEdgePoints[leftEdgePoints.length - 1].x - points[len - 1].x;
|
|
|
+ // leftdx2 = leftdx2 / (leftCount + 1);
|
|
|
|
|
|
- let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
- points[j],
|
|
|
- points[j + 1],
|
|
|
- ((leftEdgePoints[j].x - points[j].x) / (leftCount + 1)) * (i + 1)
|
|
|
- );
|
|
|
- let line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.leftEdgeStart,
|
|
|
- edgePoints2.leftEdgeEnd
|
|
|
- );
|
|
|
+ // let leftdy2 =
|
|
|
+ // leftEdgePoints[leftEdgePoints.length - 1].y - points[len - 1].y;
|
|
|
+ // leftdy2 = leftdy2 / (leftCount + 1);
|
|
|
|
|
|
- let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
- if (join == null) {
|
|
|
- join = mathUtil.getJoinLinePoint(points[j], line1);
|
|
|
+ if (dir == "left" || !dir) {
|
|
|
+ for (let i = 0; i < leftCount; ++i) {
|
|
|
+ for (let j = 0; j < points.length; ++j) {
|
|
|
+ if (!leftLanes[i]) {
|
|
|
+ leftLanes[i] = [];
|
|
|
}
|
|
|
- leftLanes[i][j].x = join.x;
|
|
|
- leftLanes[i][j].y = join.y;
|
|
|
+ const leftdx = (leftEdgePoints[j].x - points[j].x) / (leftCount + 1);
|
|
|
+ const leftdy = (leftEdgePoints[j].y - points[j].y) / (leftCount + 1);
|
|
|
+ leftLanes[i][j] = {};
|
|
|
+ leftLanes[i][j].x = points[j].x + leftdx * (i + 1);
|
|
|
+ leftLanes[i][j].y = points[j].y + leftdy * (i + 1);
|
|
|
+ // if (j == 0) {
|
|
|
+ // leftLanes[i][j].x = points[j].x + leftdx1 * (i + 1);
|
|
|
+ // leftLanes[i][j].y = points[j].y + leftdy1 * (i + 1);
|
|
|
+ // } else if (j == points.length - 1) {
|
|
|
+ // leftLanes[i][j].x = points[j].x + leftdx2 * (i + 1);
|
|
|
+ // leftLanes[i][j].y = points[j].y + leftdy2 * (i + 1);
|
|
|
+ // } else {
|
|
|
+ // let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
+ // points[j],
|
|
|
+ // points[j - 1],
|
|
|
+ // ((leftEdgePoints[j].x - points[j].x) / (leftCount + 1)) * (i + 1)
|
|
|
+ // );
|
|
|
+ // let line1 = mathUtil.createLine1(
|
|
|
+ // edgePoints1.leftEdgeStart,
|
|
|
+ // edgePoints1.leftEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
+ // points[j],
|
|
|
+ // points[j + 1],
|
|
|
+ // ((leftEdgePoints[j].x - points[j].x) / (leftCount + 1)) * (i + 1)
|
|
|
+ // );
|
|
|
+ // let line2 = mathUtil.createLine1(
|
|
|
+ // edgePoints2.leftEdgeStart,
|
|
|
+ // edgePoints2.leftEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
+ // if (join == null) {
|
|
|
+ // join = mathUtil.getJoinLinePoint(points[j], line1);
|
|
|
+ // }
|
|
|
+ // leftLanes[i][j].x = join.x;
|
|
|
+ // leftLanes[i][j].y = join.y;
|
|
|
+ // }
|
|
|
}
|
|
|
+ leftLanesCurves[i] = mathUtil.getCurvesByPoints(leftLanes[i]);
|
|
|
}
|
|
|
- leftLanesCurves[i] = mathUtil.getCurvesByPoints(leftLanes[i]);
|
|
|
+ curveRoad.leftLanes = leftLanes;
|
|
|
+ curveRoad.leftLanesCurves = leftLanesCurves;
|
|
|
}
|
|
|
|
|
|
- let rightdx1 = rightEdgePoints[0].x - points[0].x;
|
|
|
- rightdx1 = rightdx1 / (rightCount + 1);
|
|
|
-
|
|
|
- let rightdy1 = rightEdgePoints[0].y - points[0].y;
|
|
|
- rightdy1 = rightdy1 / (rightCount + 1);
|
|
|
+ // let rightdx1 = rightEdgePoints[0].x - points[0].x;
|
|
|
+ // rightdx1 = rightdx1 / (rightCount + 1);
|
|
|
|
|
|
- let rightdx2 =
|
|
|
- rightEdgePoints[rightEdgePoints.length - 1].x - points[len - 1].x;
|
|
|
- rightdx2 = rightdx2 / (rightCount + 1);
|
|
|
+ // let rightdy1 = rightEdgePoints[0].y - points[0].y;
|
|
|
+ // rightdy1 = rightdy1 / (rightCount + 1);
|
|
|
|
|
|
- let rightdy2 =
|
|
|
- rightEdgePoints[rightEdgePoints.length - 1].y - points[len - 1].y;
|
|
|
- rightdy2 = rightdy2 / (rightCount + 1);
|
|
|
+ // let rightdx2 =
|
|
|
+ // rightEdgePoints[rightEdgePoints.length - 1].x - points[len - 1].x;
|
|
|
+ // rightdx2 = rightdx2 / (rightCount + 1);
|
|
|
|
|
|
- for (let i = 0; i < rightCount; ++i) {
|
|
|
- for (let j = 0; j < points.length; ++j) {
|
|
|
- if (!rightLanes[i]) {
|
|
|
- rightLanes[i] = [];
|
|
|
- }
|
|
|
- rightLanes[i][j] = {};
|
|
|
- if (j == 0) {
|
|
|
- rightLanes[i][j].x = points[j].x + rightdx1 * (i + 1);
|
|
|
- rightLanes[i][j].y = points[j].y + rightdy1 * (i + 1);
|
|
|
- } else if (j == points.length - 1) {
|
|
|
- rightLanes[i][j].x = points[j].x + rightdx2 * (i + 1);
|
|
|
- rightLanes[i][j].y = points[j].y + rightdy2 * (i + 1);
|
|
|
- } else {
|
|
|
- let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
- points[j],
|
|
|
- points[j - 1],
|
|
|
- ((rightEdgePoints[j].x - points[j].x) / (rightCount + 1)) * (i + 1)
|
|
|
- );
|
|
|
- let line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.rightEdgeStart,
|
|
|
- edgePoints1.rightEdgeEnd
|
|
|
- );
|
|
|
-
|
|
|
- let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
- points[j],
|
|
|
- points[j + 1],
|
|
|
- ((rightEdgePoints[j].x - points[j].x) / (rightCount + 1)) * (i + 1)
|
|
|
- );
|
|
|
- let line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.rightEdgeStart,
|
|
|
- edgePoints2.rightEdgeEnd
|
|
|
- );
|
|
|
+ // let rightdy2 =
|
|
|
+ // rightEdgePoints[rightEdgePoints.length - 1].y - points[len - 1].y;
|
|
|
+ // rightdy2 = rightdy2 / (rightCount + 1);
|
|
|
|
|
|
- let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
- if (join == null) {
|
|
|
- join = mathUtil.getJoinLinePoint(points[j], line1);
|
|
|
+ if (dir == "right" || !dir) {
|
|
|
+ for (let i = 0; i < rightCount; ++i) {
|
|
|
+ for (let j = 0; j < points.length; ++j) {
|
|
|
+ if (!rightLanes[i]) {
|
|
|
+ rightLanes[i] = [];
|
|
|
}
|
|
|
- rightLanes[i][j].x = join.x;
|
|
|
- rightLanes[i][j].y = join.y;
|
|
|
+ const rightdx =
|
|
|
+ (rightEdgePoints[j].x - points[j].x) / (rightCount + 1);
|
|
|
+ const rightdy =
|
|
|
+ (rightEdgePoints[j].y - points[j].y) / (rightCount + 1);
|
|
|
+ rightLanes[i][j] = {};
|
|
|
+ rightLanes[i][j].x = points[j].x + rightdx * (i + 1);
|
|
|
+ rightLanes[i][j].y = points[j].y + rightdy * (i + 1);
|
|
|
+ // if (j == 0) {
|
|
|
+ // rightLanes[i][j].x = points[j].x + rightdx1 * (i + 1);
|
|
|
+ // rightLanes[i][j].y = points[j].y + rightdy1 * (i + 1);
|
|
|
+ // } else if (j == points.length - 1) {
|
|
|
+ // rightLanes[i][j].x = points[j].x + rightdx2 * (i + 1);
|
|
|
+ // rightLanes[i][j].y = points[j].y + rightdy2 * (i + 1);
|
|
|
+ // } else {
|
|
|
+ // let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
+ // points[j],
|
|
|
+ // points[j - 1],
|
|
|
+ // ((rightEdgePoints[j].x - points[j].x) / (rightCount + 1)) *
|
|
|
+ // (i + 1)
|
|
|
+ // );
|
|
|
+ // let line1 = mathUtil.createLine1(
|
|
|
+ // edgePoints1.rightEdgeStart,
|
|
|
+ // edgePoints1.rightEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
+ // points[j],
|
|
|
+ // points[j + 1],
|
|
|
+ // ((rightEdgePoints[j].x - points[j].x) / (rightCount + 1)) *
|
|
|
+ // (i + 1)
|
|
|
+ // );
|
|
|
+ // let line2 = mathUtil.createLine1(
|
|
|
+ // edgePoints2.rightEdgeStart,
|
|
|
+ // edgePoints2.rightEdgeEnd
|
|
|
+ // );
|
|
|
+
|
|
|
+ // let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
+ // if (join == null) {
|
|
|
+ // join = mathUtil.getJoinLinePoint(points[j], line1);
|
|
|
+ // }
|
|
|
+ // rightLanes[i][j].x = join.x;
|
|
|
+ // rightLanes[i][j].y = join.y;
|
|
|
+ // }
|
|
|
}
|
|
|
+ rightLanesCurves[i] = mathUtil.getCurvesByPoints(rightLanes[i]);
|
|
|
}
|
|
|
- rightLanesCurves[i] = mathUtil.getCurvesByPoints(rightLanes[i]);
|
|
|
+ curveRoad.rightLanes = rightLanes;
|
|
|
+ curveRoad.rightLanesCurves = rightLanesCurves;
|
|
|
}
|
|
|
-
|
|
|
- return {
|
|
|
- leftLanes: leftLanes,
|
|
|
- rightLanes: rightLanes,
|
|
|
- leftLanesCurves: leftLanesCurves,
|
|
|
- rightLanesCurves: rightLanesCurves,
|
|
|
- };
|
|
|
}
|
|
|
|
|
|
//删除或者减少车道
|
|
@@ -319,145 +414,63 @@ export default class CurveRoadService extends RoadService {
|
|
|
if (dir == "left") {
|
|
|
curveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
|
|
|
oldCount = curveRoad.leftDrivewayCount;
|
|
|
+ curveRoad.leftDrivewayCount = newCount;
|
|
|
lanes = curveRoad.leftLanes;
|
|
|
} else if (dir == "right") {
|
|
|
curveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
|
|
|
oldCount = curveRoad.rightDrivewayCount;
|
|
|
+ curveRoad.rightDrivewayCount = newCount;
|
|
|
lanes = curveRoad.rightLanes;
|
|
|
}
|
|
|
+
|
|
|
if (newCount == oldCount) {
|
|
|
return;
|
|
|
+ } else if (newCount == 0) {
|
|
|
+ this.mulToSinglelane(curveRoad);
|
|
|
+ return;
|
|
|
+ } else if (oldCount == 0) {
|
|
|
+ this.singleToMullane(curveRoad);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- const len = curveRoad.points.length;
|
|
|
- let dx1 = curveEdge.points[0].x - curveRoad.points[0].x;
|
|
|
- dx1 = dx1 / oldCount;
|
|
|
- let dy1 = curveEdge.points[0].y - curveRoad.points[0].y;
|
|
|
- dy1 = dy1 / oldCount;
|
|
|
- let dx2 = curveEdge.points[len - 1].x - curveRoad.points[len - 1].x;
|
|
|
- dx2 = dx2 / oldCount;
|
|
|
- let dy2 = curveEdge.points[len - 1].y - curveRoad.points[len - 1].y;
|
|
|
- dy2 = dy2 / oldCount;
|
|
|
-
|
|
|
- if (newCount > oldCount) {
|
|
|
- for (let i = oldCount; i < newCount; ++i) {
|
|
|
- for (let j = 0; j < len; ++j) {
|
|
|
- if (j == 0) {
|
|
|
- lanes[i][j].x = curveRoad.points[j].x + dx1 * (i + 1);
|
|
|
- lanes[i][j].y = curveRoad.points[j].y + dy1 * (i + 1);
|
|
|
- } else if (j == curveRoad.points.length - 1) {
|
|
|
- lanes[i][j].x = curveRoad.points[j].x + dx2 * (i + 1);
|
|
|
- lanes[i][j].y = curveRoad.points[j].y + dy2 * (i + 1);
|
|
|
- } else {
|
|
|
- let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
- curveRoad.points[j],
|
|
|
- curveRoad.points[j - 1],
|
|
|
- dx1 * (i + 1)
|
|
|
- );
|
|
|
- let line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.leftEdgeStart,
|
|
|
- edgePoints1.leftEdgeEnd
|
|
|
- );
|
|
|
- if (dir == "right") {
|
|
|
- line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.rightEdgeStart,
|
|
|
- edgePoints1.rightEdgeEnd
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
- curveRoad.points[j],
|
|
|
- curveRoad.points[j + 1],
|
|
|
- dx1 * (i + 1)
|
|
|
- );
|
|
|
- let line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.leftEdgeStart,
|
|
|
- edgePoints2.leftEdgeEnd
|
|
|
- );
|
|
|
- if (dir == "right") {
|
|
|
- line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.rightEdgeStart,
|
|
|
- edgePoints2.rightEdgeEnd
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
- if (join == null) {
|
|
|
- join = mathUtil.getJoinLinePoint(curveRoad.points[j], line1);
|
|
|
- }
|
|
|
- lanes[i][j].x = join.x;
|
|
|
- lanes[i][j].y = join.y;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- curveEdge.points[0].x = curveRoad.points[0].x + dx1 * newCount;
|
|
|
- curveEdge.points[0].y = curveRoad.points[0].y + dy1 * newCount;
|
|
|
-
|
|
|
- curveEdge.points[len - 1].x =
|
|
|
- curveRoad.points[len - 1].x + dx2 * newCount;
|
|
|
- curveEdge.points[len - 1].y =
|
|
|
- curveRoad.points[len - 1].y + dy2 * newCount;
|
|
|
-
|
|
|
- for (let k = 1; k < len - 1; ++k) {
|
|
|
- let edgePoints1 = mathUtil.RectangleVertex(
|
|
|
- curveRoad.points[k],
|
|
|
- curveRoad.points[k - 1],
|
|
|
- dx1 * newCount
|
|
|
- );
|
|
|
- let line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.leftEdgeStart,
|
|
|
- edgePoints1.leftEdgeEnd
|
|
|
- );
|
|
|
- if (dir == "right") {
|
|
|
- line1 = mathUtil.createLine1(
|
|
|
- edgePoints1.rightEdgeStart,
|
|
|
- edgePoints1.rightEdgeEnd
|
|
|
- );
|
|
|
- }
|
|
|
+ for (let i = 0; i < curveRoad.points.length; ++i) {
|
|
|
+ const dx =
|
|
|
+ (curveEdge.points[i].x - curveRoad.points[i].x) / (oldCount + 1);
|
|
|
+ curveEdge.points[i].x = curveRoad.points[i].x + dx * (newCount + 1);
|
|
|
+ const dy =
|
|
|
+ (curveEdge.points[i].y - curveRoad.points[i].y) / (oldCount + 1);
|
|
|
+ curveEdge.points[i].y = curveRoad.points[i].y + dy * (newCount + 1);
|
|
|
+ }
|
|
|
|
|
|
- let edgePoints2 = mathUtil.RectangleVertex(
|
|
|
- curveRoad.points[k],
|
|
|
- curveRoad.points[k + 1],
|
|
|
- dx1 * newCount
|
|
|
- );
|
|
|
- let line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.leftEdgeStart,
|
|
|
- edgePoints2.leftEdgeEnd
|
|
|
- );
|
|
|
- if (dir == "right") {
|
|
|
- line2 = mathUtil.createLine1(
|
|
|
- edgePoints2.rightEdgeStart,
|
|
|
- edgePoints2.rightEdgeEnd
|
|
|
- );
|
|
|
- }
|
|
|
+ mathUtil.clonePoint(curveEdge.start, curveEdge.points[0]);
|
|
|
+ mathUtil.clonePoint(
|
|
|
+ curveEdge.end,
|
|
|
+ curveEdge.points[curveEdge.points.length - 1]
|
|
|
+ );
|
|
|
+ this.setLanes(curveRoad, dir);
|
|
|
+ }
|
|
|
|
|
|
- let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
- if (join == null) {
|
|
|
- join = mathUtil.getJoinLinePoint(curveRoad.points[j], line1);
|
|
|
- }
|
|
|
- curveEdge.points[k].x = join.x;
|
|
|
- curveEdge.points[k].y = join.y;
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (newCount < oldCount) {
|
|
|
- let count = lanes.length;
|
|
|
- let lane = lanes.pop();
|
|
|
- while (count == newCount) {
|
|
|
- lane = lanes.pop();
|
|
|
- count = lanes.length;
|
|
|
- }
|
|
|
- for (let i = 0; i < curveEdge.points.length; ++i) {
|
|
|
- mathUtil.clonePoint(curveEdge.points[i], lane[i]);
|
|
|
- }
|
|
|
- }
|
|
|
+ //单车道转多车道,默认是转换成左右两边各一个
|
|
|
+ //不改变路的宽度
|
|
|
+ singleToMullane(curveRoad) {
|
|
|
+ curveRoad.rightEdgeId = null;
|
|
|
+ curveRoad.leftDrivewayCount = 1;
|
|
|
+ curveRoad.rightDrivewayCount = 1;
|
|
|
+ let lanes = this.setLanes(curveRoad);
|
|
|
+ curveRoad.leftLanes = lanes.leftLanes;
|
|
|
+ curveRoad.rightLanes = lanes.rightLanes;
|
|
|
+ curveRoad.leftLanesCurves = lanes.leftLanesCurves;
|
|
|
+ curveRoad.rightLanesCurves = lanes.rightLanesCurves;
|
|
|
+ }
|
|
|
|
|
|
- if (dir == "left") {
|
|
|
- curveRoad.leftLanes = lanes;
|
|
|
- curveRoad.leftDrivewayCount = newCount;
|
|
|
- } else if (dir == "right") {
|
|
|
- curveRoad.rightLanes = lanes;
|
|
|
- curveRoad.rightDrivewayCount = newCount;
|
|
|
- }
|
|
|
+ //多车道转单车道
|
|
|
+ mulToSinglelane(curveRoad) {
|
|
|
+ curveRoad.leftDrivewayCount = 0;
|
|
|
+ curveRoad.rightDrivewayCount = 0;
|
|
|
+ curveRoad.leftLanesCurves = [];
|
|
|
+ curveRoad.rightLanesCurves = [];
|
|
|
+ curveRoad.leftLanes = [];
|
|
|
+ curveRoad.rightLanes = [];
|
|
|
}
|
|
|
|
|
|
updateForMovePoint(pointId, position) {
|