Ejemplo n.º 1
0
        private static void GetInfiniteEdge(DelaunayCell cell, MIVector[] verticesOnEdge, out MIVector from, out MIVector to)
        {
            from = cell.Circumcenter;

            var factor = 100
                         * IsLeft(verticesOnEdge[0], verticesOnEdge[1], from)
                         * IsLeft(verticesOnEdge[0], verticesOnEdge[1], cell.Center);
            var fromToEdgeMidpoint =
                new MIVector(0.5 * (verticesOnEdge[0].Position[0] + verticesOnEdge[1].Position[0] - from.X),
                             0.5 * (verticesOnEdge[0].Position[1] + verticesOnEdge[1].Position[1]) - from.Z);

            to = new MIVector(from.X + factor * fromToEdgeMidpoint.X, from.Z + factor * fromToEdgeMidpoint.Z);
        }
Ejemplo n.º 2
0
        private List <MIVector> GetVerticesForSideOfRectangle(MIVector from, MIVector to, bool leftSide)
        {
            List <MIVector> vertices = new List <MIVector>
            {
                from,
                to
            };

            foreach (MIVector bound in _bounds)
            {
                if ((leftSide ? 1 : -1) * IsLeft(from, to, bound) > 0)
                {
                    vertices.Add(bound);
                }
            }

            return(ConvexHull.Create(vertices).Points.ToList());
        }
Ejemplo n.º 3
0
        public Dictionary <int, Polygon> GetAreasForPositions(Dictionary <int, Vector> idToPosition)
        {
            Dictionary <Vector, MIVector> vectorToMiVectorMapping = new Dictionary <Vector, MIVector>();

            idToPosition.ForEachValue(vector => vectorToMiVectorMapping[vector] = new MIVector(vector.X, vector.Z));

            // add fake generators
            vectorToMiVectorMapping.Add(new Vector(0, 10), new MIVector(0, 10));
            vectorToMiVectorMapping.Add(new Vector(10, 0), new MIVector(10, 0));
            vectorToMiVectorMapping.Add(new Vector(0, -10), new MIVector(0, -10));
            vectorToMiVectorMapping.Add(new Vector(-10, 0), new MIVector(-10, 0));

            Dictionary <MIVector, VoronoiCell> positionsToVoronoi = GetAreasForPositions(vectorToMiVectorMapping.Values.ToList());

            Dictionary <int, Polygon> idsToVoronoi = new Dictionary <int, Polygon>();

            foreach (KeyValuePair <int, Vector> pair in idToPosition)
            {
                if (!positionsToVoronoi.ContainsKey(vectorToMiVectorMapping[pair.Value]))
                {
                    continue;
                }

                PolygonList intersection = ClipperUtility.Intersection(
                    _wrapperPolygon,
                    new PolygonList(positionsToVoronoi[vectorToMiVectorMapping[pair.Value]]
                                    .CellVertices
                                    .Select((p) =>
                {
                    List <Vector> list = p.Select(mi => new Vector(mi.X, mi.Z)).ToList();
                    Polygon poly       = new Polygon(list);
                    poly.MakeContour();
                    return(poly);
                })
                                    .ToList())
                    );
                if (intersection.Count > 0)
                {
                    idsToVoronoi[pair.Key] = intersection.First();
                }
            }

            return(idsToVoronoi);
        }
Ejemplo n.º 4
0
        private static bool _vecEq(MIVector a, MIVector b)
        {
            double epsilon = 0.00001;

            return(Math.Abs(a.X - b.X) < epsilon && Math.Abs(a.Z - b.Z) < epsilon);
        }
Ejemplo n.º 5
0
 static int IsLeft(MIVector a, MIVector b, MIVector c)
 {
     return(((b.X - a.X) * (c.Z - a.Z) - (b.Z - a.Z) * (c.X - a.X)) > 0 ? 1 : -1);
 }