示例#1
0
    static void Main(string[] args)
    {
        DateTime start = DateTime.Now;

        Point[] points = new Point[100000000];
        Console.WriteLine(DateTime.Now - start);
        Console.WriteLine("points.Last().X={0}", points.Last().X);
        Console.WriteLine("points.Last().Y={0}", points.Last().Y);
    }
示例#2
0
    static void Main(string[] args)
    {
        DateTime start = DateTime.Now;

        Point[] points = new Point[100000000];
        for (int i = 0; i < points.Length; i++)
        {
            points[i] = new Point();
        }
        Console.WriteLine(DateTime.Now - start);
        Console.WriteLine("points.Last().X={0}", points.Last().X);
        Console.WriteLine("points.Last().Y={0}", points.Last().Y);
    }
        /// <summary>
        /// Gets the point where NotifyIcon is clicked by the position of ContextMenuStrip and NotifyIcon.
        /// </summary>
        /// <returns>Cursor location</returns>
        /// <remarks>MouseEventArgs.Location property of MouseClick event does not contain data.</remarks>
        private Point GetClickedPoint()
        {
            var contextMenuStrip = _notifyIcon.ContextMenuStrip;

            var corners = new Point[]
            {
                //new Point(contextMenuStrip.Left, contextMenuStrip.Top),
                //new Point(contextMenuStrip.Right, contextMenuStrip.Top),
                new Point(contextMenuStrip.Left, contextMenuStrip.Bottom),
                new Point(contextMenuStrip.Right, contextMenuStrip.Bottom)
            };

            var notifyIconRect = WindowPosition.GetNotifyIconRect(_notifyIcon);

            if (notifyIconRect != Rect.Empty)
            {
                foreach (var corner in corners)
                {
                    if (notifyIconRect.Contains(corner))
                    {
                        return(corner);
                    }
                }
            }

            return(corners.Last());            // Fallback
        }
        public Directions Optimize(Point[] points)
        {
            DBC.Assert(points.Length > 1, "Unable to optimize a route with less than 2 points.");

            Log(points);

            if (IsSingleRouteDirections(points)) return BuildSingleRouteDirections(points);

            var graph = new DirectedGraph(points);
            var graphNavigator = new GraphNavigator(graph, points.First(), points.Last(), roadPathService);
            IList<Directions> cycles = graphNavigator.GetCycles();
            stitchingService = new StitchingService(cycles, graph);
            var stitched = stitchingService.Stitch();
            stitched.Order(points.First(), points.Last());
            return stitched;
        }
        /// <summary>
        /// Get ramer-sampled points without using recursive function. Call "ClearCache" function for recalculation
        /// </summary>
        /// <param name="dthres"></param>
        /// <returns></returns>
        public Point[] GetRamerSampledPoints_NonRecursive(double dthres)
        {
            if (this.ramerSampledPoints == null)
            {
                Point[] points = new Point[this.Points.Count];
                for (int i = 0, ilen = this.Points.Count; i < ilen; i++)
                {
                    points[i] = this.Points[i].PointObject;
                }
                List<Point> sampledPoints = new List<Point>();
                sampledPoints.Add(points[0]);
                sampledPoints.Add(points.Last());
                Queue<int[]> q = new Queue<int[]>();
                q.Enqueue(new int[] {0, points.Length - 1});

                while (q.Count != 0)
                {
                    double dmax = 0.0;
                    int max_index = 0;
                    int[] range = q.Dequeue();
                    for (int i = range[0] + 1; i < range[1]; i++)
                    {
                        double d = CommonFunction.PerpendicularDistance(points[i], points[range[0]], points[range[1]]);
                        if (dmax < d)
                        {
                            dmax = d;
                            max_index = i;
                        }
                    }

                    if (dthres < dmax)
                    {
                        sampledPoints.Add(points[max_index]);
                        q.Enqueue(new int[] { range[0], max_index });
                        q.Enqueue(new int[] { max_index, range[1] });
                    }
                }

                this.ramerSampledPoints = sampledPoints.ToArray();
            }

            return this.ramerSampledPoints;
        }
        /// <summary>
        /// Gets the point where NotifyIcon is clicked by the position of ContextMenuStrip and NotifyIcon.
        /// </summary>
        /// <returns>Cursor location</returns>
        /// <remarks>MouseEventArgs.Location property of MouseClick event does not contain data.</remarks>
        private Point GetClickedPoint()
        {
            var contextMenuStrip = _notifyIcon.ContextMenuStrip;

            var corners = new Point[]
            {
                //new Point(contextMenuStrip.Left, contextMenuStrip.Top),
                //new Point(contextMenuStrip.Right, contextMenuStrip.Top),
                new Point(contextMenuStrip.Left, contextMenuStrip.Bottom),
                new Point(contextMenuStrip.Right, contextMenuStrip.Bottom)
            };

            var notifyIconRect = WindowPosition.GetNotifyIconRect(_notifyIcon);
            if (notifyIconRect != Rect.Empty)
            {
                foreach (var corner in corners)
                {
                    if (notifyIconRect.Contains(corner))
                        return corner;
                }
            }

            return corners.Last(); // Fallback
        }