Ejemplo n.º 1
0
        private void OnTimerTick(object sender, EventArgs args)
        {
            if (_division == null)
            {
                return;
            }

            // clear current selections, if any
            if (_nearestEdge >= 0)
            {
                SetNearestEdge(null, 0);
            }
            if (_selectedEdge >= 0)
            {
                SetSelectedEdge(-1);
            }
            if (_selectedVertex >= 0)
            {
                SetSelectedVertex(-1);
            }

            // check if mouse cursor is over subdivision
            Point cursor = Mouse.GetPosition(OutputBox);

            if (cursor.X < 0 || cursor.X >= OutputBox.Width ||
                cursor.Y < 0 || cursor.Y >= OutputBox.Height)
            {
                return;
            }

            // show nearest half-edge, if any
            PointD          q = cursor.ToPointD();
            double          distance;
            SubdivisionEdge edge = _division.FindNearestEdge(q, out distance);

            if (edge != null)
            {
                SetNearestEdge(edge, distance);
                if (distance <= 30)
                {
                    SetSelectedEdge(edge.Key);
                }
            }

            // show nearest vertex, if any
            var vertices = _division.Vertices;

            if (vertices.Count > 0)
            {
                var vertexComparer = (PointDComparerY)vertices.Comparer;
                int index          = vertexComparer.FindNearest(vertices.Keys, q);
                SetSelectedVertex(index);
            }
        }