|
@@ -1,7 +1,9 @@
|
|
import { dataService } from "./DataService";
|
|
import { dataService } from "./DataService";
|
|
import { pointService } from "./PointService";
|
|
import { pointService } from "./PointService";
|
|
|
|
+import { edgeService } from "./EdgeService";
|
|
import { mathUtil } from "../Util/MathUtil.js";
|
|
import { mathUtil } from "../Util/MathUtil.js";
|
|
import CurveRoad from "../Geometry/CurveRoad.js";
|
|
import CurveRoad from "../Geometry/CurveRoad.js";
|
|
|
|
+import VectorType from "../enum/VectorType";
|
|
|
|
|
|
export default class CurveRoadService {
|
|
export default class CurveRoadService {
|
|
constructor() {}
|
|
constructor() {}
|
|
@@ -12,9 +14,11 @@ export default class CurveRoadService {
|
|
|
|
|
|
let startPoint = dataService.getPoint(startId);
|
|
let startPoint = dataService.getPoint(startId);
|
|
startPoint.setPointParent(curveRoad.vectorId, "start");
|
|
startPoint.setPointParent(curveRoad.vectorId, "start");
|
|
|
|
+ startPoint.setGeoType(VectorType.CurveRoadCorner);
|
|
|
|
|
|
let endPoint = dataService.getPoint(endId);
|
|
let endPoint = dataService.getPoint(endId);
|
|
endPoint.setPointParent(curveRoad.vectorId, "end");
|
|
endPoint.setPointParent(curveRoad.vectorId, "end");
|
|
|
|
+ endPoint.setGeoType(VectorType.CurveRoadCorner);
|
|
|
|
|
|
let edgePoints = mathUtil.RectangleVertex(
|
|
let edgePoints = mathUtil.RectangleVertex(
|
|
startPoint,
|
|
startPoint,
|
|
@@ -41,6 +45,9 @@ export default class CurveRoadService {
|
|
leftEdge.setEdgeParent(curveRoad.vectorId);
|
|
leftEdge.setEdgeParent(curveRoad.vectorId);
|
|
rightEdge.setEdgeParent(curveRoad.vectorId);
|
|
rightEdge.setEdgeParent(curveRoad.vectorId);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ curveRoad.points.push(startPoint);
|
|
|
|
+ curveRoad.points.push(endPoint);
|
|
this.addCPoint(
|
|
this.addCPoint(
|
|
curveRoad,
|
|
curveRoad,
|
|
{
|
|
{
|
|
@@ -49,6 +56,11 @@ export default class CurveRoadService {
|
|
},
|
|
},
|
|
0
|
|
0
|
|
);
|
|
);
|
|
|
|
+ curveRoad.leftEdgePoints.push(edgePoints.leftEdgeStart);
|
|
|
|
+ curveRoad.leftEdgePoints.push(edgePoints.leftEdgeEnd);
|
|
|
|
+
|
|
|
|
+ curveRoad.rightEdgePoints.push(edgePoints.rightEdgeStart);
|
|
|
|
+ curveRoad.rightEdgePoints.push(edgePoints.rightEdgeEnd);
|
|
|
|
|
|
let lanes = this.setLanes(
|
|
let lanes = this.setLanes(
|
|
curveRoad.points,
|
|
curveRoad.points,
|
|
@@ -57,14 +69,25 @@ export default class CurveRoadService {
|
|
curveRoad.leftDrivewayCount,
|
|
curveRoad.leftDrivewayCount,
|
|
curveRoad.rightDrivewayCount
|
|
curveRoad.rightDrivewayCount
|
|
);
|
|
);
|
|
- road.leftLanes = lanes.leftLanes;
|
|
|
|
- road.rightLanes = lanes.rightLanes;
|
|
|
|
- return road;
|
|
|
|
|
|
+ curveRoad.leftLanes = lanes.leftLanes;
|
|
|
|
+ curveRoad.rightLanes = lanes.rightLanes;
|
|
|
|
+ return curveRoad;
|
|
}
|
|
}
|
|
|
|
|
|
addCPoint(curveRoad, position, startIndex) {
|
|
addCPoint(curveRoad, position, startIndex) {
|
|
let point = pointService.create(position);
|
|
let point = pointService.create(position);
|
|
- curveRoad.points[startIndex + 1] = point;
|
|
|
|
|
|
+ curveRoad.points.splice(startIndex + 1, 0, point);
|
|
|
|
+ point.setGeoType(VectorType.CurveRoadCorner);
|
|
|
|
+ point.setPointParent(curveRoad.vectorId, 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];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
moveCPoint(position) {}
|
|
moveCPoint(position) {}
|
|
@@ -98,10 +121,12 @@ export default class CurveRoadService {
|
|
let leftdy1 = leftEdgePoints[0].y - points[0].y;
|
|
let leftdy1 = leftEdgePoints[0].y - points[0].y;
|
|
leftdy1 = leftdy1 / leftCount;
|
|
leftdy1 = leftdy1 / leftCount;
|
|
|
|
|
|
- let leftdx2 = leftEdgePoints[len - 1].x - points[len - 1].x;
|
|
|
|
|
|
+ let leftdx2 =
|
|
|
|
+ leftEdgePoints[leftEdgePoints.length - 1].x - points[len - 1].x;
|
|
leftdx2 = leftdx2 / leftCount;
|
|
leftdx2 = leftdx2 / leftCount;
|
|
|
|
|
|
- let leftdy2 = leftEdgePoints[len - 1].y - points[len - 1].y;
|
|
|
|
|
|
+ let leftdy2 =
|
|
|
|
+ leftEdgePoints[leftEdgePoints.length - 1].y - points[len - 1].y;
|
|
leftdy2 = leftdy2 / leftCount;
|
|
leftdy2 = leftdy2 / leftCount;
|
|
|
|
|
|
for (let i = 0; i < leftCount - 1; ++i) {
|
|
for (let i = 0; i < leftCount - 1; ++i) {
|
|
@@ -136,6 +161,9 @@ export default class CurveRoadService {
|
|
);
|
|
);
|
|
|
|
|
|
let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
|
+ if (join == null) {
|
|
|
|
+ join = mathUtil.getLineForPoint(line1, points[j]);
|
|
|
|
+ }
|
|
leftLanes[i][j].x = join.x;
|
|
leftLanes[i][j].x = join.x;
|
|
leftLanes[i][j].y = join.y;
|
|
leftLanes[i][j].y = join.y;
|
|
}
|
|
}
|
|
@@ -148,10 +176,12 @@ export default class CurveRoadService {
|
|
let rightdy1 = rightEdgePoints[0].y - points[0].y;
|
|
let rightdy1 = rightEdgePoints[0].y - points[0].y;
|
|
rightdy1 = rightdy1 / rightCount;
|
|
rightdy1 = rightdy1 / rightCount;
|
|
|
|
|
|
- let rightdx2 = rightEdgePoints[len - 1].x - points[len - 1].x;
|
|
|
|
|
|
+ let rightdx2 =
|
|
|
|
+ rightEdgePoints[rightEdgePoints.length - 1].x - points[len - 1].x;
|
|
rightdx2 = rightdx2 / rightCount;
|
|
rightdx2 = rightdx2 / rightCount;
|
|
|
|
|
|
- let rightdy2 = rightEdgePoints[len - 1].y - points[len - 1].y;
|
|
|
|
|
|
+ let rightdy2 =
|
|
|
|
+ rightEdgePoints[rightEdgePoints.length - 1].y - points[len - 1].y;
|
|
rightdy2 = rightdy2 / rightCount;
|
|
rightdy2 = rightdy2 / rightCount;
|
|
|
|
|
|
for (let i = 0; i < rightCount - 1; ++i) {
|
|
for (let i = 0; i < rightCount - 1; ++i) {
|
|
@@ -186,6 +216,9 @@ export default class CurveRoadService {
|
|
);
|
|
);
|
|
|
|
|
|
let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
let join = mathUtil.getIntersectionPoint(line1, line2);
|
|
|
|
+ if (join == null) {
|
|
|
|
+ join = mathUtil.getLineForPoint(line1, points[j]);
|
|
|
|
+ }
|
|
rightLanes[i][j].x = join.x;
|
|
rightLanes[i][j].x = join.x;
|
|
rightLanes[i][j].y = join.y;
|
|
rightLanes[i][j].y = join.y;
|
|
}
|
|
}
|
|
@@ -197,6 +230,108 @@ export default class CurveRoadService {
|
|
rightLanes: rightLanes,
|
|
rightLanes: rightLanes,
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ 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);
|
|
|
|
+ curveRoad.rightLanes[i][index].x = join.x;
|
|
|
|
+ curveRoad.rightLanes[i][index].y = join.y;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
const curveRoadService = new CurveRoadService();
|
|
const curveRoadService = new CurveRoadService();
|