|
@@ -3,6 +3,7 @@ import Line from "../Geometry/Line.js";
|
|
|
import { dataService } from "./DataService.js";
|
|
|
import VectorCategory from "../enum/VectorCategory.js";
|
|
|
import { mathUtil } from "../Util/MathUtil.js";
|
|
|
+import { lineService } from "./LineService.js";
|
|
|
export default class PointService {
|
|
|
constructor() {}
|
|
|
|
|
@@ -11,6 +12,35 @@ export default class PointService {
|
|
|
dataService.addPoint(point);
|
|
|
return point;
|
|
|
}
|
|
|
+
|
|
|
+ //将pointId1合并到pointId2
|
|
|
+ mergePoint(pointId1, pointId2) {
|
|
|
+ if (pointId1 == pointId2) {
|
|
|
+ return;
|
|
|
+ } else if (pointId1 != null && pointId2 != null) {
|
|
|
+ let point1 = dataService.getPoint(pointId1);
|
|
|
+ let parent1 = point1.getParent();
|
|
|
+ let point2 = dataService.getPoint(pointId2);
|
|
|
+ if (mathUtil.equalPoint(point1, point2)) {
|
|
|
+ let lineId = lineService.getLine(pointId1, pointId2);
|
|
|
+ if (lineId) {
|
|
|
+ dataService.deleteLine(lineId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let key in parent1) {
|
|
|
+ let line = dataService.getLine(key);
|
|
|
+ let dir = line.getDir(pointId1);
|
|
|
+ if (dir == "start") {
|
|
|
+ line.startId = pointId2;
|
|
|
+ } else if (dir == "end") {
|
|
|
+ line.endId = pointId2;
|
|
|
+ }
|
|
|
+ point2.setPointParent(key, dir);
|
|
|
+ }
|
|
|
+ dataService.deletePoint(pointId1);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const pointService = new PointService();
|