import Constant from "../Constant.js"; import { dataService } from "../Service/DataService.js"; import { mathUtil } from "../Util/MathUtil.js"; import VectorType from "../enum/VectorType.js"; import Geometry from "./Geometry"; // 二次贝塞尔曲线 // var ctx=c.getContext("2d"); // ctx.beginPath(); // ctx.moveTo(200,20); // ctx.quadraticCurveTo(20,100,20,20); // ctx.stroke(); export default class ControlPoint extends Geometry { constructor(position, vectorId) { super(); //控制点坐标 this.x = null; this.y = null; this.edgeInfo1 = { id: null, dir: null, }; this.edgeInfo2 = { id: null, dir: null, }; this.extremePoint = null; //极值 this.curves = []; this.geoType = VectorType.ControlPoint; this.setId(vectorId); this.setPosition(position); } setPosition(position) { this.x = position.x; this.y = position.y; } setExtremePoint() { let points = []; let edge1 = dataService.getRoadEdge(this.edgeInfo1.id); let curve = {}; if (this.edgeInfo1.dir == "start") { curve.start = {}; mathUtil.clonePoint(curve.start, edge1.start); } else if (this.edgeInfo1.dir == "end") { curve.start = {}; mathUtil.clonePoint(curve.start, edge1.end); } curve.controls = []; curve.controls.push({ x: this.x, y: this.y, }); let edge2 = dataService.getRoadEdge(this.edgeInfo2.id); if (this.edgeInfo2.dir == "start") { curve.end = {}; mathUtil.clonePoint(curve.end, edge2.start); } else if (this.edgeInfo2.dir == "end") { curve.end = {}; mathUtil.clonePoint(curve.end, edge2.end); } let joinInfo = mathUtil.getHitInfoForCurve( curve.controls[0], curve, Constant.defaultRoadWidth ); this.extremePoint = {}; mathUtil.clonePoint(this.extremePoint, joinInfo.position); this.curves = mathUtil.getCurvesByPoints([ curve.start, this.extremePoint, curve.end, ]); } setCurves() { let points = []; let edge1 = dataService.getRoadEdge(this.edgeInfo1.id); if (this.edgeInfo1.dir == "start") { points[0] = edge1.start; } else if (this.edgeInfo1.dir == "end") { points[0] = edge1.end; } points[1] = { x: this.extremePoint.x, y: this.extremePoint.y, }; let edge2 = dataService.getRoadEdge(this.edgeInfo2.id); if (this.edgeInfo2.dir == "start") { points[2] = edge2.start; } else if (this.edgeInfo2.dir == "end") { points[2] = edge2.end; } points[1] = this.extremePoint; this.curves = mathUtil.getCurvesByPoints(points); } setEdgeInfo(edgeId1, dir1, edgeId2, dir2) { this.edgeInfo1.id = edgeId1; this.edgeInfo1.dir = dir1; this.edgeInfo2.id = edgeId2; this.edgeInfo2.dir = dir2; } }