Exemplo n.º 1
0
        /// <summary>
        /// Calculate the size of a list of facets
        /// </summary>
        /// <remarks>
        /// Code based on https://github.com/admesh/admesh/
        /// </remarks>
        public static SolidSize CalculateSize(IEnumerable <Facet> facets)
        {
            SolidSize result = new SolidSize();

            if (facets == null)
            {
                return(result);
            }

            var enumerator = facets.SelectMany(f => f.Vertices).GetEnumerator();

            try
            {
                if (!enumerator.MoveNext())
                {
                    return(result);
                }
                Vertex min = new Vertex(enumerator.Current);
                Vertex max = new Vertex(enumerator.Current);
                while (enumerator.MoveNext())
                {
                    var vertice = enumerator.Current;
                    min.X = Math.Min(min.X, vertice.X);
                    min.Y = Math.Min(min.Y, vertice.Y);
                    min.Z = Math.Min(min.Z, vertice.Z);
                    max.X = Math.Max(max.X, vertice.X);
                    max.Y = Math.Max(max.Y, vertice.Y);
                    max.Z = Math.Max(max.Z, vertice.Z);
                }
                result.Min             = min;
                result.Max             = max;
                result.Size            = new Vertex(max.X - min.X, max.Y - min.Y, max.Z - min.Z);
                result.BoudingDiameter = Math.Sqrt(
                    result.Size.X * result.Size.X
                    + result.Size.Y * result.Size.Y
                    + result.Size.Z * result.Size.Z
                    );
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    ((IDisposable)enumerator).Dispose();
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculate the size of a list of facets
        /// </summary>
        /// <remarks>
        /// Code based on https://github.com/admesh/admesh/
        /// </remarks>
        public static SolidSize CalculateSize(IEnumerable<Facet> facets)
        {
            SolidSize result = new SolidSize();

            if (facets == null) return result;

            var enumerator = facets.SelectMany(f => f.Vertices).GetEnumerator();
            try
            {
                if (!enumerator.MoveNext()) return result;
                Vertex min = new Vertex(enumerator.Current);
                Vertex max = new Vertex(enumerator.Current);
                while (enumerator.MoveNext())
                {
                    var vertice = enumerator.Current;
                    min.X = Math.Min(min.X, vertice.X);
                    min.Y = Math.Min(min.Y, vertice.Y);
                    min.Z = Math.Min(min.Z, vertice.Z);
                    max.X = Math.Max(max.X, vertice.X);
                    max.Y = Math.Max(max.Y, vertice.Y);
                    max.Z = Math.Max(max.Z, vertice.Z);
                }
                result.Min = min;
                result.Max = max;
                result.Size = new Vertex(max.X - min.X, max.Y - min.Y, max.Z - min.Z);
                result.BoudingDiameter = Math.Sqrt(
                    result.Size.X * result.Size.X
                    + result.Size.Y * result.Size.Y
                    + result.Size.Z * result.Size.Z
                    );
            }
            finally
            {
                if (enumerator is IDisposable)
                    ((IDisposable)enumerator).Dispose();
            }
            return result;
        }