1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import ControlPoint from "../Geometry/ControlPoint.js";
- import { dataService } from "./DataService.js";
- import { mathUtil } from "../Util/MathUtil";
- import { edgeService } from "./EdgeService.js";
- export default class ControlPointService {
- constructor() {}
- //暂时没有添加到vectorData里
- create(position, vectorId) {
- let controlPoint = new ControlPoint(position, vectorId);
- return controlPoint;
- }
- update(realRosition, point1, point2, edge1, edge2, dir1, dir2) {
- let controlPoint = dataService.getControlPoint(
- edge1.vectorId,
- edge2.vectorId
- );
- const line1 = edgeService.getLine(edge1);
- const line2 = edgeService.getLine(edge2);
- let position = mathUtil.getPositionForExtendedLine(point1, point2);
- //更新edge的坐标
- let position1 = mathUtil.getJoinLinePoint(position, line1);
- let position2 = mathUtil.getJoinLinePoint(position, line2);
- //可能position1或者position2不在对应的edge上,这时候需要调换顺序
- if (
- !mathUtil.isContainForSegment(position1, edge1.start, edge1.end) ||
- !mathUtil.isContainForSegment(position2, edge2.start, edge2.end)
- ) {
- position = mathUtil.getPositionForExtendedLine(point2, point1);
- position1 = mathUtil.getJoinLinePoint(position, line1);
- position2 = mathUtil.getJoinLinePoint(position, line2);
- }
- // const realRosition = mathUtil.getPositionForExtendedLine(point2, point1);
- // const realRosition = {
- // x: (point1.x + point2.x) / 2,
- // y: (point1.y + point2.y) / 2,
- // };
- if (controlPoint == null) {
- //新建控制点
- controlPoint = this.create(realRosition);
- //设置控制点的信息
- controlPoint.setEdgeInfo(edge1.vectorId, dir1, edge2.vectorId, dir2);
- //添加到数据集里
- dataService.addControlPoint(controlPoint);
- }
- //更新控制点坐标
- else {
- controlPoint.setPosition(realRosition);
- }
- edge1.setPosition(position1, dir1);
- edge2.setPosition(position2, dir2);
- }
- }
- const controlPointService = new ControlPointService();
- export { controlPointService };
|