예제 #1
0
        protected override bool IsHit(IInputModeContext context, PointD location, INode node)
        {
            const double cornerRadius = 7;
            var          layout       = node.Layout;
            // Our shape is a rounded rectangle. Hits can appear in either of the following rectangles ...
            var rect1 = new RectD(layout.X, layout.Y + cornerRadius, layout.Width, layout.Height - 2 * cornerRadius);
            var rect2 = new RectD(layout.X + cornerRadius, layout.Y, layout.Width - 2 * cornerRadius, layout.Height);

            if (rect1.Contains(location, context.HitTestRadius) || rect2.Contains(location, context.HitTestRadius))
            {
                return(true);
            }
            // ... or in circle arcs around the corners
            var p1 = new PointD(layout.X + cornerRadius, layout.Y + cornerRadius);
            var p2 = new PointD(layout.X + layout.Width - cornerRadius, layout.Y + cornerRadius);
            var p3 = new PointD(layout.X + cornerRadius, layout.Y + layout.Height - cornerRadius);
            var p4 = new PointD(layout.X + layout.Width - cornerRadius, layout.Y + layout.Height - cornerRadius);

            if (location.DistanceTo(p1) < cornerRadius + context.HitTestRadius ||
                location.DistanceTo(p2) < cornerRadius + context.HitTestRadius ||
                location.DistanceTo(p3) < cornerRadius + context.HitTestRadius ||
                location.DistanceTo(p4) < cornerRadius + context.HitTestRadius)
            {
                return(true);
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 取两点所在直线上的指定长度的向量
        /// </summary>
        /// <param name="lineStart">线起点</param>
        /// <param name="lineEnd">线终点</param>
        /// <param name="length">向量长度</param>
        /// <returns></returns>
        private static VectorD GetVectorOnLineByLength(PointD lineStart, PointD lineEnd, double length)
        {
            double  scale     = length / lineStart.DistanceTo(lineEnd);
            VectorD vectorOld = lineEnd - lineStart;

            return(vectorOld.ScaleBy(scale));
        }
예제 #3
0
        /// <summary>
        /// 根据workpiece1 和workpiece1计算出patternMark1相对于workpiece1的方位,用角度和长度定位
        /// </summary>
        /// <param name="worpieceMark1"></param>
        /// <param name="worpieceMark2"></param>
        /// <param name="patternMark1"></param>
        /// <param name="angle"></param>
        /// <param name="lengthW1P"></param>
        public void findPointRelWorkPiece(PointD worpieceMark1, PointD worpieceMark2, PointD patternMark1, out double angle, out double lengthW1P)
        {
            angle = 0;

            double angleW1ToW2 = MathUtils.CalculateArc(worpieceMark1, worpieceMark2);
            double angleW1ToP1 = MathUtils.CalculateArc(worpieceMark1, patternMark1);

            //夹角
            angle = angleW1ToP1 - angleW1ToW2;
            //长度
            lengthW1P = worpieceMark1.DistanceTo(patternMark1);
        }
예제 #4
0
        /// <summary>
        /// 计算加速时间
        /// </summary>
        /// <param name="accStartPoint">加速起点</param>
        /// <param name="lineStartPoint">直线起点</param>
        /// <param name="vel">速度</param>
        /// <param name="acc">加速度</param>
        /// <returns></returns>
        protected double CalcAccTime(PointD accStartPoint, PointD lineStartPoint, double vel, double acc)
        {
            double distance = accStartPoint.DistanceTo(lineStartPoint);
            double t1       = vel / acc;
            double d        = vel * t1 * 0.5;
            double t2       = 0;

            if (distance > d)
            {
                t2 = (distance - d) / vel;
            }
            return(t1 + t2);
        }
예제 #5
0
        /// <summary>
        /// 获取角平分线上一点
        /// </summary>
        /// <param name="start"></param>
        /// <param name="middle"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private static PointD GetAPointOnAngleBiscetor(PointD start, PointD middle, PointD end)
        {
            double len1  = start.DistanceTo(middle);
            double len2  = middle.DistanceTo(end);
            double scale = len1 / (len1 + len2);

            // 角平分线与对边交点
            PointD  point1  = new PointD();
            VectorD vector1 = end - start;

            point1 = start + vector1.ScaleBy(scale);
            return(point1);
        }
예제 #6
0
        /// <summary>
        /// 计算两点之间的角度 [0-180]
        /// </summary>
        /// <returns></returns>
        public static double CalculateDegree(PointD start, PointD end)
        {
            double dx     = end.X - start.X;
            double dy     = end.Y - start.Y;
            double length = start.DistanceTo(end);

            if (length == 0)
            {
                return(0);
            }
            double cos = dx / length;
            double arc = Math.Acos(cos) / Math.PI * 180;

            return(arc);
        }
예제 #7
0
        /// <summary>
        /// Fix the ports for <see cref="RoutingMode.ShortestStraightPathToBorder"/>
        /// by enlarging the adjacent segment to the rotated layout.
        /// </summary>
        /// <param name="graph">The layout graph to work on.</param>
        /// <param name="edge">The edge to fix.</param>
        /// <param name="path">A <see cref="GeneralPath"/> which represents the rotated layout.</param>
        /// <param name="atSource">Whether to fix the source or target port of the edge.</param>
        private static void FixPorts(LayoutGraph graph, Edge edge, GeneralPath path, bool atSource)
        {
            var el         = graph.GetLayout(edge);
            var pointCount = el.PointCount();
            // find the opposite point of the port at the adjacent segment
            PointD firstBend = atSource
        ? (pointCount > 0 ? el.GetPoint(0) : graph.GetTargetPointAbs(edge)).ToPointD()
        : (pointCount > 0 ? el.GetPoint(pointCount - 1) : graph.GetSourcePointAbs(edge)).ToPointD();
            // The port itself
            PointD port = (atSource ? graph.GetSourcePointAbs(edge) : graph.GetTargetPointAbs(edge)).ToPointD();
            // The adjacent segment as vector pointing from the opposite point to the port
            var direction = port - firstBend;
            // find the intersection (there is always one)
            var    intersection = path.FindRayIntersection(firstBend.ToPointD(), direction);
            PointD point        = port;

            if (intersection < Double.PositiveInfinity)
            {
                // found an intersection: extend the adjacent segment
                point = firstBend + (direction * intersection);
            }
            else
            {
                // no intersection: connect to the original port's nearest point
                var    cursor      = path.CreateCursor();
                double minDistance = Double.PositiveInfinity;
                while (cursor.MoveNext())
                {
                    var distance = port.DistanceTo(cursor.CurrentEndPoint);
                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        point       = cursor.CurrentEndPoint;
                    }
                }
            }
            // set the port position
            if (atSource)
            {
                graph.SetSourcePointAbs(edge, point.ToYPoint());
            }
            else
            {
                graph.SetTargetPointAbs(edge, point.ToYPoint());
            }
        }
        public void onMouseMove(MouseEventArgs e)
        {
            //this.OnScroll();

            PointD CurrPosition = new PointD(e.ClientX - LocalData.SVGPosition.X, e.ClientY - LocalData.SVGPosition.Y);

            currMouseLocation    = CurrPosition;
            strCurrMouseLocation = "x: " + currMouseLocation.X.ToString("F2") + "; y: " + currMouseLocation.Y.ToString("F2");

            if (CurrOperationalMode == OperationalMode.select)
            {
                switch (CurrSelectionMode)
                {
                case SelectionMode.idle:
                    if (SelectionVerticesList.Any(x => (CurrPosition.DistanceTo(x.PtD) <= 10)))
                    {
                        BPaintVertex currVertex =
                            SelectionVerticesList.Single(x => (CurrPosition.DistanceTo(x.PtD) <= 10));

                        bpSelectionVertexUnderMousePointer          = currVertex;
                        bpSelectionVertexUnderMousePointer.Selected = true;
                        CurrSelectionMode = SelectionMode.hoveredAVertex;
                    }
                    else
                    {
                        bpSelectionVertexUnderMousePointer = null;
                        CurrSelectionMode = SelectionMode.idle;
                    }

                    break;

                case SelectionMode.movingAnElement:
                    BPaintVertex vertex2Move = bpSelectionVertexUnderMousePointer as BPaintVertex;
                    vertex2Move.PtD = CurrPosition;
                    break;

                case SelectionMode.hoveredAVertex:
                    if (SelectionVerticesList.Any(x => (CurrPosition.DistanceTo(x.PtD) <= 10)))
                    {
                        BPaintVertex currVertex =
                            SelectionVerticesList.Single(x => (CurrPosition.DistanceTo(x.PtD) <= 10));

                        bpSelectionVertexUnderMousePointer = currVertex;
                        CurrSelectionMode = SelectionMode.hoveredAVertex;
                    }
                    else
                    {
                        bpSelectionVertexUnderMousePointer = null;

                        foreach (BPaintVertex vertex in SelectionVerticesList)
                        {
                            vertex.Selected = false;
                        }

                        CurrSelectionMode = SelectionMode.idle;
                    }

                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (CurrPaintMode)
                {
                // TODO: Fix vertices highlighting
                // category=Appearance issue=none estimate=2h
                // when there is no selection rectangle, vertices under the mouse cursor are not highlighted

                case BPaintMode.idle:
                    if (VerticesList.Any(x => (CurrPosition.DistanceTo(x.PtD) <= 10)))
                    {
                        BPaintVertex currVertex = VerticesList.Single(x => (CurrPosition.DistanceTo(x.PtD) <= 10));

                        bpVertexUnderMousePointer          = currVertex;
                        bpVertexUnderMousePointer.Selected = true;
                        CurrPaintMode = BPaintMode.hoveredAVertex;
                    }
                    else
                    {
                        bpVertexUnderMousePointer = null;
                        CurrPaintMode             = BPaintMode.idle;
                    }

                    break;

                case BPaintMode.drawing:
                    break;

                case BPaintMode.movingAnElement:
                    BPaintVertex vertex2Move = bpVertexUnderMousePointer as BPaintVertex;
                    vertex2Move.PtD = CurrPosition;
                    break;

                case BPaintMode.hoveredAVertex:
                    if (VerticesList.Any(x => (CurrPosition.DistanceTo(x.PtD) <= 10)))
                    {
                        BPaintVertex currVertex = VerticesList.Single(x => (CurrPosition.DistanceTo(x.PtD) <= 10));

                        bpVertexUnderMousePointer = currVertex;
                        CurrPaintMode             = BPaintMode.hoveredAVertex;
                    }
                    else
                    {
                        bpVertexUnderMousePointer = null;
                        foreach (BPaintObject bpObject in ObjectsList)
                        {
                            //bpObject.Selected = false;
                            bpObject.EditMode = false;
                        }

                        foreach (BPaintVertex vertex in VerticesList)
                        {
                            vertex.Selected = false;
                        }

                        CurrPaintMode = BPaintMode.idle;
                    }

                    break;

                default:
                    break;
                }
            }

            ProcessSelection();
            StateHasChanged();
        }
예제 #9
0
 public double DistanceTo(PointD to)
 {
     return(PointD.DistanceTo(this.Location, to));
 }
예제 #10
0
 public double DistanceTo(ActorBase to)
 {
     return(PointD.DistanceTo(this.Location, to.Location));
 }
예제 #11
0
파일: Utility.cs 프로젝트: NTDLS/AIVolution
 public static double DistanceTo(ActorBase from, ActorBase to)
 {
     return(PointD.DistanceTo(from.Location, to.Location));
 }