Example #1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <Tuple <LocalData <T>, LocalData <T> > > RelatedPairs <T>(this PointMatrix <T> matrix, double minDist, double maxDist)
        {
            int    range      = (int)Math.Ceiling(maxDist / matrix.CellSize);
            double minSqrDist = minDist * minDist;
            double maxSqrDist = maxDist * maxDist;

            List <Tuple <LocalData <T>, LocalData <T> > > result = new List <Tuple <LocalData <T>, LocalData <T> > >();

            foreach (KeyValuePair <DiscretePoint, List <LocalData <T> > > kvp in matrix.Data)
            {
                DiscretePoint         k           = kvp.Key;
                List <LocalData <T> > closePoints = matrix.SubMatrixData <T>(
                    new DiscretePoint {
                    X = k.X - range, Y = k.Y - range, Z = k.Z - range
                },
                    new DiscretePoint {
                    X = k.X + range, Y = k.Y + range, Z = k.Z + range
                });

                foreach (LocalData <T> value in kvp.Value)
                {
                    foreach (LocalData <T> other in closePoints)
                    {
                        double sqrDist = value.Position.PMSquareDistance(other.Position);
                        if (sqrDist < maxSqrDist && sqrDist > minSqrDist)
                        {
                            result.Add(new Tuple <LocalData <T>, LocalData <T> >(value, other));
                        }
                    }
                }
            }

            return(result);
        }
Example #2
0
        /***************************************************/
        /**** 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);
        }