// ----------------------------------------------------------------------- // // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ // // ----------------------------------------------------------------------- namespace UnityEngine.U2D.Animation.TriangleNet .Voronoi.Legacy { using System; using System.Collections.Generic; using Animation.TriangleNet.Topology; using Animation.TriangleNet.Geometry; /// /// Represents a region in the Voronoi diagram. /// internal class VoronoiRegion { int id; Point generator; List vertices; bool bounded; // A map (vertex id) -> (neighbor across adjacent edge) Dictionary neighbors; /// /// Gets the Voronoi region id (which is the same as the generators vertex id). /// public int ID { get { return id; } } /// /// Gets the Voronoi regions generator. /// public Point Generator { get { return generator; } } /// /// Gets the Voronoi vertices on the regions boundary. /// public ICollection Vertices { get { return vertices; } } /// /// Gets or sets whether the Voronoi region is bounded. /// public bool Bounded { get { return bounded; } set { bounded = value; } } public VoronoiRegion(Vertex generator) { this.id = generator.id; this.generator = generator; this.vertices = new List(); this.bounded = true; this.neighbors = new Dictionary(); } public void Add(Point point) { this.vertices.Add(point); } public void Add(List points) { this.vertices.AddRange(points); } /// /// Returns the neighbouring Voronoi region, that lies across the edge starting at /// given vertex. /// /// Vertex defining an edge of the region. /// Neighbouring Voronoi region /// /// The edge starting at p is well defined (vertices are ordered counterclockwise). /// public VoronoiRegion GetNeighbor(Point p) { VoronoiRegion neighbor; if (neighbors.TryGetValue(p.id, out neighbor)) { return neighbor; } return null; } internal void AddNeighbor(int id, VoronoiRegion neighbor) { this.neighbors.Add(id, neighbor); } public override string ToString() { return String.Format("R-ID {0}", id); } } }