/// <summary> /// 当前屏幕上鼠标点击点附近可用的交点或者依附点 /// </summary> /// <param name="surroundings"></param> /// <returns></returns> public Surroundings GetCross(Surroundings surroundings) { Surroundings result = new Surroundings() { screenPoint = surroundings.screenPoint }; if (surroundings.surroundingLine.Count == 0 && surroundings.surroundingCircle.Count == 0) { return(result); } float currentLength; if (surroundings.surroundingLine.Count > 0 || surroundings.surroundingCircle.Count > 0) { for (int i = 0; i < surroundings.surroundingLine.Count; i++) //遍历直线集合 { Line lCurrent = surroundings.surroundingLine[i].geometry as Line; for (int j = i; j < surroundings.surroundingLine.Count; j++) //前一个元素已经和自己相交过,所以后面的元素不需要 { Vector2 perpendicularFoot = new Vector2(); //垂足 if (i == j) //自己和自己,单依赖 { currentLength = DistanceOfPointAndLine(this.ToVector2(lCurrent.p1), this.ToVector2(lCurrent.p2) - this.ToVector2(lCurrent.p1), surroundings.screenPoint, ref perpendicularFoot); Point2 pf = ToPoint2(perpendicularFoot); pf.rely.Add(lCurrent); //依赖于一条直线 result.surroundingPoint.Add(new GeometryAndTheDistance() { geometry = pf, distance = currentLength }); } else //相交依赖 { List <Point2> plist = ((IPointSet)lCurrent).Intersection(surroundings.surroundingLine[j].geometry as Line); for (int k = 0; k < plist.Count; k++) { //plist[k].rely.Add(lCurrent); //添加依赖于两条直线 //plist[k].rely.Add(surroundings.surroundingLine[j].geometry as Line); result.surroundingPoint.Add(new GeometryAndTheDistance() { geometry = plist[k], distance = Vector2.Distance(this.ToVector2(plist[k]), surroundings.screenPoint) }); } } } for (int j = 0; j < surroundings.surroundingCircle.Count; j++) //直线与每个圆相交 { List <Point2> plist = ((IPointSet)lCurrent).Intersection(surroundings.surroundingCircle[j].geometry as Circle); for (int k = 0; k < plist.Count; k++) { //plist[k].rely.Add(lCurrent); //添加依赖于1条直线和1个圆 //plist[k].rely.Add(surroundings.surroundingCircle[j].geometry as Circle); result.surroundingPoint.Add(new GeometryAndTheDistance() { geometry = plist[k], distance = Vector2.Distance(this.ToVector2(plist[k]), surroundings.screenPoint) }); } } } for (int i = 0; i < surroundings.surroundingCircle.Count; i++) { Circle cCurrent = surroundings.surroundingCircle[i].geometry as Circle; for (int j = 0; j < surroundings.surroundingCircle.Count; j++) //圆集合的相交 { Vector2 nearestFoot = new Vector2(); if (i == j) //自己和自己,单依赖 { currentLength = OutputCoordinate.DistanceOfPointAndCircle(this.ToVector2(cCurrent.center), (this.ToVector2(cCurrent.radius) - this.ToVector2(cCurrent.center)).Length(), surroundings.screenPoint, ref nearestFoot); Point2 nf = ToPoint2(nearestFoot); nf.rely.Add(cCurrent); //依赖于圆 result.surroundingPoint.Add(new GeometryAndTheDistance() { geometry = nf, distance = currentLength }); } else //相交依赖 { List <Point2> plist = ((IPointSet)cCurrent).Intersection(surroundings.surroundingCircle[j].geometry as Circle); for (int k = 0; k < plist.Count; k++) { //plist[k].rely.Add(cCurrent); //添加依赖于两条直线 //plist[k].rely.Add(surroundings.surroundingCircle[j].geometry as Circle); result.surroundingPoint.Add(new GeometryAndTheDistance() { geometry = plist[k], distance = Vector2.Distance(this.ToVector2(plist[k]), surroundings.screenPoint) }); } } } } } result.surroundingPoint.Sort(); //排序 return(result); }
/// <summary> /// 获取鼠标在屏幕当前点附近的逻辑坐标点 /// </summary> /// <param name="point">屏幕上的点</param> /// <returns>逻辑点列表</returns> public Surroundings GetSurroundings(Vector2 point) { Surroundings result = new Surroundings() { screenPoint = point }; float currentLength = 0; if (outputPointList == null && outputPointSetList == null) { return(null); } for (int i = 0; i < outputPointList.Count; i++) { if (outputPointList[i].isVisible == true) { var pCurrent = outputPointList[i]; if ((currentLength = (pCurrent.viewPoint - point).Length()) < OutputPoint.scopeLength) //点击的点在屏幕上某个点的圆圈内 { result.surroundingPoint.Add(new GeometryAndTheDistance() { geometry = pCurrent.point, distance = currentLength }); } } } for (int i = 0; i < outputPointSetList.Count; i++) { if (outputPointSetList[i].isVisible == true) { if (outputPointSetList[i] is OutputLine) { var lCurrent = outputPointSetList[i] as OutputLine; var perpendicularFoot = new Vector2(); if ((currentLength = OutputCoordinate.DistanceOfPointAndLine(lCurrent.p1, lCurrent.p2 - lCurrent.p1, point, ref perpendicularFoot)) < OutputPoint.scopeLength) { int j; for (j = 0; j < result.surroundingLine.Count; j++) { if (result.surroundingLine[j].geometry == lCurrent.line) { break; } } if (j == result.surroundingLine.Count) //防止重复添加 { result.surroundingLine.Add(new GeometryAndTheDistance() { geometry = lCurrent.line, distance = currentLength }); } } } else if (outputPointSetList[i] is OutputCircle) { var cCurrent = outputPointSetList[i] as OutputCircle; if ((currentLength = Math.Abs(cCurrent.radius - (point - cCurrent.center).Length())) < OutputPoint.scopeLength) { result.surroundingCircle.Add(new GeometryAndTheDistance() { geometry = cCurrent.circle, distance = currentLength }); } } } } result.surroundingPoint.Sort(); //排序 result.surroundingLine.Sort(); result.surroundingCircle.Sort(); return(result); }