예제 #1
0
파일: Index.cs 프로젝트: ackratos/USTCMap
        private static bool intersectPolyline(RectangleF rect, Path path)
        {
            Node prev = null;

            foreach(object i in path.content)
            {
                if(i is Node)
                {
                    Node curr = (Node)i;

                    if(rect.Contains((float)(curr.lon), (float)curr.lat))
                        return true;

                    if(prev!= null)
                    {
                        Line2D line = new Line2D(new PointD(prev.lon, prev.lat), new PointD(curr.lon, curr.lat));
                        if(line.intersects(rect))
                            return true;
                    }

                    prev = curr;
                }
            }

            return false;
        }
예제 #2
0
파일: Toolkit.cs 프로젝트: ackratos/USTCMap
        private static List<Point> douglasPeucker(List<Point> pts, double dist)
        {
            int n = pts.Count;
            if (n <= 2)
                return pts;

            Line2D line = new Line2D(pts[0].point, pts[pts.Count - 1].point);
            double maxDist = Double.NegativeInfinity;
            int best = -1;
            for (int i = 1; i < n - 1; i++)
            {
                double temp = line.ptLineDist(pts[i].point);
                if (maxDist < temp)
                {
                    maxDist = temp;
                    best = i;
                }
            }

            List<Point> result = new List<Point>();
            if (maxDist < dist)
            {
                result.Add(pts[0]);
                result.Add(pts[pts.Count - 1]);
                return result;
            }

            List<Point> part1 = new List<Point>();
            for (int i = 0; i <= best; i++)
            {
                part1.Add(pts[i]);
            }
            result.AddRange(douglasPeucker(part1, dist));
            result.Remove(result[result.Count - 1]);

            List<Point> part2 = new List<Point>();
            for (int i = best; i < n; i++)
            {
                part2.Add(pts[i]);
            }
            result.AddRange(douglasPeucker(part2, dist));

            return result;
        }