public static IEnumerable <TPoint> GetLongestConnected <TCell, TPoint, TBasePoint>( IEvenGrid <TCell, TPoint, TBasePoint> grid, TPoint point, Func <TPoint, TPoint, bool> isNeighborsConnected) where TPoint : ISplicedVectorPoint <TPoint, TBasePoint>, IGridPoint <TPoint> where TBasePoint : IVectorPoint <TBasePoint>, IGridPoint <TBasePoint> { return(GetLongestConnectedLine(grid, point, isNeighborsConnected)); }
/** * Gets the longest line of connected points that contains this point. * * @tparam TCell the type of cell of the grid that this algorithm takes. * @tparam TPoint the type of point of the grid that this algorithm takes. * @tparam TBasePoint the base type of the point. * * @see GetConnectedRays */ public static IEnumerable <IEnumerable <TPoint> > GetConnectedLines <TCell, TPoint, TBasePoint>( IEvenGrid <TCell, TPoint, TBasePoint> grid, TPoint point, Func <TPoint, TPoint, bool> isNeighborsConnected) where TPoint : ISplicedVectorPoint <TPoint, TBasePoint>, IGridPoint <TPoint> where TBasePoint : IVectorPoint <TBasePoint>, IGridPoint <TBasePoint> { var lines = new List <IEnumerable <TPoint> >(); foreach (var direction in grid.GetPrincipleNeighborDirections()) { var line = new PointList <TPoint>(); var edge = point; //go forwards while (grid.Contains(edge) && isNeighborsConnected(point, edge)) { edge = edge.MoveBy(direction); } var oppositeDirection = direction.Negate(); //TPoint oppositeNeighbor = point.MoveBy(direction.Negate()); edge = edge.MoveBy(oppositeDirection); //go backwards while (grid.Contains(edge) && isNeighborsConnected(point, edge)) { line.Add(edge); edge = edge.MoveBy(oppositeDirection); } if (line.Count > 1) { lines.Add(line); } } return(lines); }