/***************************************/ public static void Add <T>(this PointMatrix <T> matrix, Point position, T data = default(T)) { Dictionary <DiscretePoint, List <LocalData <T> > > cells = matrix.Data; DiscretePoint key = Create.DiscretePoint(position, matrix.CellSize); if (!cells.ContainsKey(key)) { cells[key] = new List <LocalData <T> >(); } cells[key].Add(new LocalData <T> { Position = position, Data = data }); }
/***************************************************/ public static PointMatrix <T> PointMatrix <T>(List <LocalData <T> > data, double cellSize = 1.0) { PointMatrix <T> matrix = new PointMatrix <T> { CellSize = cellSize }; Dictionary <DiscretePoint, List <LocalData <T> > > cells = matrix.Data; foreach (LocalData <T> d in data) { DiscretePoint key = Create.DiscretePoint(d.Position, cellSize); if (!cells.ContainsKey(key)) { cells[key] = new List <LocalData <T> >(); } cells[key].Add(d); } return(matrix); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static List <LocalData <T> > CloseToPoint <T>(this PointMatrix <T> matrix, Point refPt, double maxDist) { // Collect all the points within cells in range Vector range = new Vector { X = maxDist, Y = maxDist, Z = maxDist }; List <LocalData <T> > inCells = matrix.SubMatrixData <T>(Create.DiscretePoint(refPt - range, matrix.CellSize), Create.DiscretePoint(refPt + range, matrix.CellSize)); // Keep only points within maxDist distance of refPt double maxSqrDist = maxDist * maxDist; List <LocalData <T> > result = new List <LocalData <T> >(); foreach (LocalData <T> tuple in inCells) { if (tuple.Position.PMSquareDistance(refPt) < maxSqrDist) { result.Add(tuple); } } // Return final result return(result); }