Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="getPosition"></param>
        /// <param name="grid"></param>
        /// <param name="indexMap"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static List <T> RemoveCoincident <T>(IEnumerable <T> items, Func <T, Vector3d> getPosition, HashGrid3d <int> grid, out List <int> indexMap, double tolerance = D.ZeroTolerance)
        {
            var result = new List <T>();

            indexMap   = new List <int>();
            grid.Scale = tolerance * _radiusToGridScale;

            // add points to result if no duplicates are found
            foreach (var item in items)
            {
                var p0 = getPosition(item);

                // search for concident items in result
                foreach (int i in grid.Search(new Interval3d(p0, tolerance)))
                {
                    if (p0.ApproxEquals(getPosition(result[i]), tolerance))
                    {
                        indexMap.Add(i);
                        goto EndFor;
                    }
                }

                // no coincident items found
                grid.Insert(p0, result.Count);
                indexMap.Add(result.Count);
                result.Add(item);

                EndFor :;
            }

            return(result);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="getPosition"></param>
        /// <param name="grid"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static IEnumerable <T> RemoveCoincident <T>(IEnumerable <T> items, Func <T, Vector3d> getPosition, HashGrid3d <Vector3d> grid, double tolerance = D.ZeroTolerance)
        {
            grid.Scale = tolerance * _radiusToGridScale;

            // add points to result if no duplicates are found
            foreach (var item in items)
            {
                var p0 = getPosition(item);

                foreach (var p1 in grid.Search(new Interval3d(p0, tolerance)))
                {
                    if (p0.ApproxEquals(p1, tolerance))
                    {
                        goto EndFor;
                    }
                }

                // no coincident items found
                grid.Insert(p0, p0);
                yield return(item);

                EndFor :;
            }
        }