using System; using System.Collections.Generic; using System.Globalization; namespace QuantumConcepts.Formats.StereoLithography { public static class Extensions { /// Shifts the vertices within the enumerable by , and . /// The vertices within these facets will be shifted. /// The amount to shift the vertices along the X axis. /// The amount to shift the vertices along the Y axis. /// The amount to shift the vertices along the Z axis. public static void Shift(this IEnumerable facets, float x, float y, float z) { facets.Shift(new Vertex(x, y, z)); } /// Shifts the vertices within the enumerable by the X, Y and Z values in the parameter. /// The vertices to be shifted. /// The amount to shift each vertex. public static void Shift(this IEnumerable facets, Vertex shift) { facets.ForEach(f => f.Shift(shift)); } /// Shifts the enumerable by , and . /// The vertices to be shifted. /// The amount to shift the vertices along the X axis. /// The amount to shift the vertices along the Y axis. /// The amount to shift the vertices along the Z axis. public static void Shift(this IEnumerable vertices, float x, float y, float z) { vertices.Shift(new Vertex(x, y, z)); } /// Shifts the enumerable by the X, Y and Z values in the parameter. /// The vertices to be shifted. /// The amount to shift each vertex. public static void Shift(this IEnumerable vertices, Vertex shift) { vertices.ForEach(v => v.Shift(shift)); } /// Inverts the within the enumerable. /// The facets to invert. public static void Invert(this IEnumerable facets) { facets.ForEach(f => f.Normal.Invert()); } /// Iterates the provided enumerable, applying the provided action to each element. /// The items upon which to apply the action. /// The action to apply to each item. public static void ForEach(this IEnumerable items, Action action) { if (items != null) { foreach (var item in items) { action(item); } } } /// Iterates the provided enumerable, applying the provided action to each element. /// The items upon which to apply the action. /// The action to apply to each item. public static bool All(this IEnumerable items, Func predicate) { if (items != null) { var index = 0; foreach (var item in items) { if (!predicate(index, item)) { return false; } index++; } } return true; } /// Checks if the provided value is null or empty. /// The value to check. /// True if the provided value is null or empty. public static bool IsNullOrEmpty(this string value) { return string.IsNullOrEmpty(value); } /// Interpolates the provided formatted string with the provided args using the default culture. /// The formatted string. /// The values to use for interpolation. public static string Interpolate(this string format, params object[] args) { return format.Interpolate(CultureInfo.InvariantCulture, args); } /// Interpolates the provided formatted string with the provided args. /// The formatted string. /// The culture info to use. /// The values to use for interpolation. public static string Interpolate(this string format, CultureInfo culture, params object[] args) { if (format != null) { return string.Format(culture, format, args); } return null; } } }