Beispiel #1
0
 private void AddToCornerList(List<Corner> v, Corner x)
 {
     if (x != null && v.IndexOf(x) < 0)
         v.Add(x);
 }
Beispiel #2
0
 public Edge lookupEdgeFromCorner(Corner q, Corner s)
 {
     foreach (var edge in q.protrudes)
     {
         if (edge.v0 == s || edge.v1 == s)
             return edge;
     }
     return null;
 }
Beispiel #3
0
        private Corner MakeCorner(Vector2? nullablePoint)
        {
            // The Voronoi library generates multiple Point objects for
            // corners, and we need to canonicalize to one Corner object.
            // To make lookup fast, we keep an array of Points, bucketed by
            // x value, and then we only have to look at other Points in
            // nearby buckets. When we fail to find one, we'll create a new
            // Corner object.

            if (nullablePoint == null)
                return null;

            var point = nullablePoint.Value;

            for (var i = (int)(point.x - 1); i <= (int)(point.x + 1); i++)
            {
                foreach (var kvp in _cornerMap.Where(p => p.Key == i))
                {
                    var dx = point.x - kvp.Value.point.x;
                    var dy = point.y - kvp.Value.point.y;
                    if (dx * dx + dy * dy < 1e-6)
                        return kvp.Value;
                }
            }

            var corner = new Corner { index = corners.Count, point = point };
            corners.Add(corner);
            corner.border = point.x == 0 || point.x == Width || point.y == 0 || point.y == Height;

            _cornerMap.Add(new KeyValuePair<int, Corner>((int)(point.x), corner));

            return corner;
        }