Exemple #1
0
        public static List <TravelTimePolygonPath> CreatePolygonPaths(List <TravelTimeCircle> circles, double speed)
        {
            List <TravelTimePolygonPath> paths = new List <TravelTimePolygonPath>();

            var clipper = new Clipper.Clipper();

            foreach (var circle in circles)
            {
                clipper.AddPolygon(CreateCirclePolygon(circle.Center, circle.TimeLeft, 12, speed), PolyType.ptSubject);
            }

            List <List <IntPoint> > solution = new List <List <IntPoint> >();

            clipper.Execute(ClipType.ctUnion, solution, PolyFillType.pftPositive, PolyFillType.pftPositive);

            foreach (var solutionItem in solution)
            {
                var path = new TravelTimePolygonPath();
                foreach (var intPoint in solutionItem)
                {
                    path.Coords.Add(new LatLng(intPoint.X / 10000000.0, intPoint.Y / 10000000.0));
                }
                paths.Add(path);
            }

            return(paths);
        }
        public static long ExecuteRefactoredClipper(int testIterationCount, List <ClipExecutionData> executionData)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            for (var i = 0; i < testIterationCount; i++)
            {
                foreach (var clipPath in executionData)
                {
                    var subject = new Clipper.PolygonPath(
                        clipPath
                        .Subject
                        .Select(poly => new Clipper.Polygon(poly.Select(pt =>
                                                                        new Clipper.IntPoint(
                                                                            pt.X * Scale,
                                                                            pt.Y * Scale)))));

                    var clip = new Clipper.PolygonPath(
                        clipPath
                        .Clip
                        .Select(poly => new Clipper.Polygon(poly.Select(pt =>
                                                                        new Clipper.IntPoint(
                                                                            pt.X * Scale,
                                                                            pt.Y * Scale)))));

                    var solution = new Clipper.PolygonTree();
                    var clipper  = new Clipper.Clipper();

                    clipper.AddPath(subject, Clipper.PolygonKind.Subject);
                    clipper.AddPath(clip, Clipper.PolygonKind.Clip);

                    // Convert performance test library operation enum to Clipper operation enum.
                    var operation = (Clipper.ClipOperation)Enum.Parse(typeof(Clipper.ClipOperation), clipPath.Operation.ToString(), true);
                    Assert.IsTrue(clipper.Execute(operation, solution));
                }
            }

            stopwatch.Stop();

            return(stopwatch.Elapsed.Ticks);
        }
Exemple #3
0
        /// <summary>
        ///     Creates a double list of the list of <see cref="Polygon" /> broken up into <see cref="IntPoint" />'s.
        /// </summary>
        /// <param name="polygons">List of <see cref="Polygon" />s</param>
        /// <returns>Double list of <see cref="IntPoint" />, each list mathing a polygon that was broken up.</returns>
        public static List <List <IntPoint> > ClipPolygons(List <Polygon> polygons)
        {
            var subj = new List <List <IntPoint> >(polygons.Count);
            var clip = new List <List <IntPoint> >(polygons.Count);

            foreach (var polygon in polygons)
            {
                subj.Add(polygon.ToClipperPath());
                clip.Add(polygon.ToClipperPath());
            }

            var solution = new List <List <IntPoint> >();
            var c        = new Clipper.Clipper();

            c.AddPaths(subj, PolyType.PtSubject, true);
            c.AddPaths(clip, PolyType.PtClip, true);
            c.Execute(ClipType.CtUnion, solution, PolyFillType.PftPositive, PolyFillType.PftEvenOdd);

            return(solution);
        }