/// <summary> /// 本规则判断椭圆(圆)的四个顶点,以及圆心与相关Position的关系; /// </summary> /// <param name="owner"></param> /// <param name="position"></param> /// <param name="canvasContext"></param> /// <returns></returns> protected override ISnapShape MatchSnapShape(Ellipse ellipse, Vector2D position, ICanvasContext canvasContext) { if (ellipse.Ellipse2D == null) { return(null); } var screenPosition = canvasContext.CanvasProxy.ToScreen(position); var pointsPositions = new Vector2D[] { ellipse.Ellipse2D.GetTopPoint(), ellipse.Ellipse2D.GetBottomPoint(), ellipse.Ellipse2D.GetLeftPoint(), ellipse.Ellipse2D.GetRightPoint(), ellipse.Ellipse2D.Center }; var screenPoint = new Vector2D(); foreach (var pointPosition in pointsPositions) { canvasContext.CanvasProxy.ToScreen(pointPosition, screenPoint); var screenRect = NativeGeometryExtensions.GetNativeSuroundingScreenRect( screenPoint, TolerantedScreenLength, TolerantedScreenLength ); if (screenRect.Contains(screenPosition)) { return(new StandardSnapPoint(pointPosition)); } } return(null); }
/// <summary> /// 绘制选择状态; /// </summary> /// <param name="canvas"></param> /// <param name="canvasProxy"></param> private void DrawSelectedState(ICanvas canvas, ICanvasScreenConvertable canvasProxy) { if (!IsSelected) { return; } if (Rectangle2D == null) { return; } //绘制四边的中点; var lines = Rectangle2D.GetLines(); var rectLength = TolerantedScreenLength; foreach (var line in lines) { var point = line.MiddlePoint; var rect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(canvasProxy.ToScreen(point), rectLength, rectLength); canvas.NativeDrawRectangle(rect, HighLightEllipseColorBrush, HighLightLinePen); } //绘制中心; var centerPointX = Rectangle2D.GetVertexes().Average(p => p.X); var centerPointY = Rectangle2D.GetVertexes().Average(p => p.Y); var centerScreenPoint = canvasProxy.ToScreen(new Vector2D(centerPointX, centerPointY)); var centerRect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(centerScreenPoint, rectLength, rectLength); canvas.NativeDrawRectangle(centerRect, HighLightEllipseColorBrush, HighLightLinePen); }
public override void Draw(ICanvas canvas, ICanvasScreenConvertable canvasProxy) { var screenPosition = canvasProxy.ToScreen(Position); var rectLength = HighLightRectLength; var rect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(screenPosition, rectLength, rectLength); canvas.NativeDrawRectangle(rect, Background, LinePen); }
public override bool PointInObject(Vector2D point, ICanvasScreenConvertable canvasProxy) { if (point == null) { throw new ArgumentNullException(nameof(point)); } if (canvasProxy == null) { throw new ArgumentNullException(nameof(canvasProxy)); } if (Ellipse2D == null) { return(false); } #if DEBUG #endif //判断是否与圆心有关系; var centerScreenPosition = canvasProxy.ToScreen(Ellipse2D.Center); var centerScreenRect = NativeGeometryExtensions.GetNativeSuroundingScreenRect( centerScreenPosition, TolerantedScreenLength, TolerantedScreenLength ); if (centerScreenRect.Contains(canvasProxy.ToScreen(point))) { return(true); } //若是圆,则通过点到圆心的距离判断; if (Ellipse2D.RadiusX == Ellipse2D.RadiusY) { var screenDis = canvasProxy.ToScreen(Ellipse2D.Center.Distance(point)); var screenRadius = canvasProxy.ToScreen(Ellipse2D.RadiusX); //若半径小于误差值,则判断距离是否小于误差值; if (screenRadius < TolerantedScreenLength) { return(screenDis < TolerantedScreenLength); } //判断是否处于圆周上; else { return(screenDis > screenRadius - TolerantedScreenLength && screenDis < screenRadius + TolerantedScreenLength); } } //To-Do,椭圆,未完成; else { return(Ellipse2D.Contains(point)); } }
public ISnapShape MatchSnapShape(DrawObject[] drawObjects, Vector2D position, ICanvasContext canvasContext) { if (drawObjects == null) { return(null); } #if DEBUG //position = new Vector2D(0, 0); #endif var screenPosition = canvasContext.CanvasProxy.ToScreen(position); var rect = Rectangle2D2.CreateEmpty(); //双游标两两遍历; for (int i = 0; i < drawObjects.Length - 1; i++) { for (int j = i + 1; j < drawObjects.Length; j++) { var intersectPositions = DrawObjectIntersectRule.GetIntersectPositions(drawObjects[i], drawObjects[j]); if (intersectPositions == null) { continue; } foreach (var intersectPosition in intersectPositions) { NativeGeometryExtensions.GetNativeSuroundingScreenRect( canvasContext.CanvasProxy.ToScreen(intersectPosition), TolerantedScreenLength, TolerantedScreenLength, rect ); if (rect.Contains(screenPosition)) { return(new IntersectSnapPoint(intersectPosition)); } } } } return(null); }
public override Rectangle2D2 GetNativeBoundingRect(ICanvasScreenConvertable canvasProxy) { if (canvasProxy == null) { throw new ArgumentNullException(nameof(canvasProxy)); } var screenPosition = canvasProxy.ToScreen(Position); var rect = NativeGeometryExtensions.GetNativeSuroundingScreenRect( screenPosition, HighLightRectLength, HighLightRectLength ); return(rect); }
public ISnapShape MatchSnapShape(DrawObject[] drawObjects, Vector2D position, ICanvasContext canvasContext) { if (position == null) { throw new ArgumentNullException(nameof(position)); } if (canvasContext == null) { throw new ArgumentNullException(nameof(canvasContext)); } //若当前网格的视图长度过小,可能画布缩放比例过大,不能匹配; var screenUnitLength = canvasContext.CanvasProxy.ToScreen(1); if (screenUnitLength < TolerantedScreenLength * 2) { return(null); } var screenPosition = canvasContext.CanvasProxy.ToScreen(position); int gridX = (int)Math.Round(position.X); int gridY = (int)Math.Round(position.Y); var gridPointPosition = new Vector2D(gridX, gridY); var gridPointScreenPosition = canvasContext.CanvasProxy.ToScreen(gridPointPosition); var screenRect = NativeGeometryExtensions.GetNativeSuroundingScreenRect( gridPointScreenPosition, TolerantedScreenLength, TolerantedScreenLength ); if (screenRect.Contains(screenPosition)) { return(new StandardSnapPoint(gridPointPosition)); } return(null); }
public override void Draw(ICanvas canvas, ICanvasScreenConvertable canvasProxy) { base.Draw(canvas, canvasProxy); //检查两个关键位置是否为空; if (MousePositionTracker.LastMouseDownPosition == null || MousePositionTracker.CurrentHoverPosition == null) { return; } //绘制当前随鼠标位置移动的编辑线段; //绘制本次尚未完成的线段的起始点小正方形; var lastMouseDownScreenPosition = canvasProxy.ToScreen(MousePositionTracker.LastMouseDownPosition); var sideLength = HighLightRectLength; var startEditRect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(lastMouseDownScreenPosition, sideLength, sideLength); canvas.NativeDrawRectangle(startEditRect, HighLightRectColorBrush, LinePen); //在外部加入了动态输入,此时显示线段编辑状态多余; //DrawEditingLineState(canvas, canvasProxy); }
/// <summary> /// 绘制选择状态; /// </summary> /// <param name="canvas"></param> private void DrawSelectedState(ICanvas canvas, ICanvasScreenConvertable canvasProxy) { if (!IsSelected) { return; } if (Ellipse2D == null) { return; } if (Ellipse2D.Center == null) { return; } var centerScreenPoint = canvasProxy.ToScreen(Ellipse2D.Center); var screenRadiusX = canvasProxy.ToScreen(Ellipse2D.RadiusX); var screenRadiusY = canvasProxy.ToScreen(Ellipse2D.RadiusY); var rectLength = TolerantedScreenLength; //依次绘制左、下、右、上、圆心的矩形; var points = new Vector2D[] { new Vector2D(centerScreenPoint.X - screenRadiusX, centerScreenPoint.Y), new Vector2D(centerScreenPoint.X, centerScreenPoint.Y - screenRadiusY), new Vector2D(centerScreenPoint.X + screenRadiusX, centerScreenPoint.Y), new Vector2D(centerScreenPoint.X, centerScreenPoint.Y + screenRadiusY), new Vector2D(centerScreenPoint.X, centerScreenPoint.Y), }; foreach (var point in points) { var rect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(point, rectLength, rectLength); canvas.NativeDrawRectangle(rect, HighLightEllipseColorBrush, HighLightLinePen); } }