/// <summary> /// Initializes a new instance of MapAround.Geometry.Tesselations.Triangle. /// </summary> /// <param name="cell1">First cell</param> /// <param name="cell2">Second cell</param> /// <param name="cell3">Third sell</param> internal Triangle(VoronoiCell cell1, VoronoiCell cell2, VoronoiCell cell3) { _cell1 = cell1; _cell2 = cell2; _cell3 = cell3; }
/// <summary> /// Builds a Voronoi tessellation. /// </summary> /// <param name="points">Enumerator of points for tesselation building</param> /// <param name="buildTraingles">A value indicating whether the constructed Delaunay triangulation</param> /// <returns>A Voronoi tessellation for cpecified points</returns> public VoronoiTesselation Build(IEnumerable <ICoordinate> points, bool buildTraingles) { List <ICoordinate> sourcePoints = new List <ICoordinate>(); foreach (ICoordinate point in points) { sourcePoints.Add(point); } if (sourcePoints.Count < 3) { throw new ArgumentException("Voronoi tesselation building for this number of point is not supported", "points"); } _buildTriangles = buildTraingles; if (_buildTriangles) { _triangles = new List <Triangle>(); } // sort list sortPoints(sourcePoints); // remove coincident points for (int i = sourcePoints.Count - 1; i > 0; i--) { if (sourcePoints[i].ExactEquals(sourcePoints[i - 1])) { sourcePoints.RemoveAt(i); } } // need to count the number of points with the same (maximum) coordinates as they must be handled in a special way int lastMaxYIndex = 0; while (lastMaxYIndex < sourcePoints.Count - 1 && sourcePoints[lastMaxYIndex].Y == sourcePoints[lastMaxYIndex + 1].Y) { lastMaxYIndex++; } if (lastMaxYIndex > 0) { sourcePoints.Sort(0, lastMaxYIndex + 1, new StartPointsComparer()); } List <VoronoiCell> cells = new List <VoronoiCell>(); foreach (ICoordinate point in sourcePoints) { VoronoiCell cell = new VoronoiCell(); cell.DataPoint = point; cells.Add(cell); } build(cells, lastMaxYIndex); VoronoiTesselation result = new VoronoiTesselation(cells, _triangles); _triangles = null; return(result); }