/// <summary> /// Gets the Voronoi cell around a site specified /// by the origin of a QuadEdge. /// </summary> /// <remarks> /// The userData of the polygon is set to be the <see cref="Coordinate" /> /// of the site. This allows attaching external /// data associated with the site to this cell polygon. /// </remarks> /// <param name="qe">a quadedge originating at the cell site</param> /// <param name="geomFact">a factory for building the polygon</param> /// <returns>a polygon indicating the cell extent</returns> public Polygon GetVoronoiCellPolygon(QuadEdge qe, GeometryFactory geomFact) { var cellPts = new List <Coordinate>(); var startQE = qe; do { // Coordinate cc = circumcentre(qe); // use previously computed circumcentre var cc = qe.Rot.Orig.Coordinate; cellPts.Add(cc); // move to next triangle CW around vertex qe = qe.OPrev; } while (qe != startQE); var coordList = new CoordinateList(); coordList.AddAll(cellPts, false); coordList.CloseRing(); if (coordList.Count < 4) { Debug.WriteLine(coordList); coordList.Add(coordList[coordList.Count - 1], true); } var pts = coordList.ToCoordinateArray(); var cellPoly = geomFact.CreatePolygon(geomFact.CreateLinearRing(pts)); var v = startQE.Orig; cellPoly.UserData = v.Coordinate; return(cellPoly); }
/// <summary> /// Gets the Voronoi cell around a site specified /// by the origin of a QuadEdge. /// </summary> /// <remarks> /// The userData of the polygon is set to be the <see cref="Coordinate" /> /// of the site. This allows attaching external /// data associated with the site to this cell polygon. /// </remarks> /// <param name="qe">a quadedge originating at the cell site</param> /// <param name="geomFact">a factory for building the polygon</param> /// <returns>a polygon indicating the cell extent</returns> public IPolygon GetVoronoiCellPolygon(QuadEdge qe, IGeometryFactory geomFact) { var cellPts = new List<Coordinate>(); QuadEdge startQE = qe; do { // Coordinate cc = circumcentre(qe); // use previously computed circumcentre Coordinate cc = qe.Rot.Orig.Coordinate; cellPts.Add(cc); // move to next triangle CW around vertex qe = qe.OPrev; } while (qe != startQE); var coordList = new CoordinateList(); coordList.AddAll(cellPts, false); coordList.CloseRing(); if (coordList.Count < 4) { #if !PCL Debug.WriteLine(coordList); #endif coordList.Add(coordList[coordList.Count - 1], true); } Coordinate[] pts = coordList.ToCoordinateArray(); IPolygon cellPoly = geomFact.CreatePolygon(geomFact.CreateLinearRing(pts), null); Vertex v = startQE.Orig; cellPoly.UserData = v.Coordinate; return cellPoly; }