Exemplo n.º 1
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, Vec2d> getPosition, HashGrid2d <Vec2d> grid = null, double tolerance = zMath.ZeroTolerance)
        {
            if (grid == null)
            {
                grid = new HashGrid2d <Vec2d>();
            }

            grid.Scale = tolerance * _radiusToGridScale;

            // add points to result if no duplicates are found
            int i = 0;

            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 :;
                i++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="getPosition"></param>
        /// <param name="indexMap"></param>
        /// <param name="grid"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static List <T> RemoveCoincident <T>(IEnumerable <T> items, Func <T, Vec2d> getPosition, out List <int> indexMap, HashGrid2d <int> grid = null, double tolerance = zMath.ZeroTolerance)
        {
            if (grid == null)
            {
                grid = new HashGrid2d <int>();
            }

            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 j in grid.Search(new Interval2d(p0, tolerance)))
                {
                    if (p0.ApproxEquals(getPosition(result[j]), tolerance))
                    {
                        indexMap.Add(j);
                        goto EndFor;
                    }
                }

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

                EndFor :;
            }

            return(result);
        }