/// <summary> /// Get the voronoi cell for the given point using the clip polygon. /// </summary> /// <param name="point"></param> /// <param name="clipPolygon"></param> /// <returns></returns> public Cell GetVoronoiCell(Point point, Vector2[] clipPolygon) { List <Vector2> currentPolygon = GetCircumCenterVectors(point); if (currentPolygon.Count == 0) { return(null); } Cell cell; if (clipPolygon == null) { Vector2 centroid = PolygonUtils.GetMeanVector(currentPolygon.ToArray()); cell = new Cell(currentPolygon.ToArray(), centroid, ToVector(point)); } else { Vector2[] clippedPoints = SutherlandHodgman.GetIntersectedPolygon(currentPolygon.ToArray(), clipPolygon); if (clippedPoints.Length == 0) { UnityEngine.Debug.Log("Clipping algorithm returned non-intersecting polygon. Skipping it."); return(null); } Vector2 centroid = PolygonUtils.GetMeanVector(clippedPoints); // create the cell including polygons and center point cell = new Cell(clippedPoints, centroid, ToVector(point)); } return(cell); }
/// <summary> /// Get the voronoi cell for the given point using the clip polygon. /// </summary> /// <param name="point"></param> /// <param name="clipPolygon"></param> /// <returns></returns> public Cell GetVoronoiCell(Point point, Vector[] clipPolygon) { List <Vector> currentPolygon = GetCircumCenterVectors(point); if (currentPolygon.Count == 0) { return(null); } Cell cell; if (clipPolygon == null) { Vector centroid = PolygonUtils.GetMeanVector(currentPolygon.ToArray()); cell = new Cell(currentPolygon.ToArray(), centroid, ToVector(point)); } else { Vector[] clippedPoints = SutherlandHodgman.GetIntersectedPolygon(currentPolygon.ToArray(), clipPolygon); Vector centroid = PolygonUtils.GetMeanVector(clippedPoints); // create the cell including polygons and center point cell = new Cell(clippedPoints, centroid, ToVector(point)); } return(cell); }
/// <summary> /// Get the mean vector for the given cell /// </summary> /// <param name="cell"></param> /// <returns></returns> public static Vector2 GetMeanVector(Cell cell) { return(PolygonUtils.GetMeanVector(cell.Vertices)); }