/// <summary> /// Gets the bounds. /// </summary> /// <returns>The bounds.</returns> /// <param name="positions">Positions.</param> public static Bounds GetBounds(Vector3[] positions) { Vector3 min = (positions.Length > 0) ? positions[0] : Vector3.zero; Vector3 max = min; float xMin = min.x; float xMax = max.x; float yMin = min.y; float yMax = max.y; float zMin = min.z; float zMax = max.z; for (int index = 1; index < positions.Length; index++) { Vector3 thisCenter = positions[index]; xMin = HydraMathUtils.Min(xMin, thisCenter.x); xMax = HydraMathUtils.Max(xMax, thisCenter.x); yMin = HydraMathUtils.Min(yMin, thisCenter.y); yMax = HydraMathUtils.Max(yMax, thisCenter.y); zMin = HydraMathUtils.Min(zMin, thisCenter.z); zMax = HydraMathUtils.Max(zMax, thisCenter.z); } return(MinMax(new Vector3(xMin, yMin, zMin), new Vector3(xMax, yMax, zMax))); }
/// <summary> /// Returns the bounds of the given Bounds list /// </summary> /// <returns>The combined bounds.</returns> /// <param name="bounds">Bounds.</param> public static Bounds CombineBounds(Bounds[] bounds) { if (bounds.Length == 0) { return(new Bounds()); } Bounds first = bounds[0]; Vector3 firstCenter = first.center; Vector3 firstExtents = first.extents; Vector3 min = firstCenter - firstExtents; Vector3 max = firstCenter + firstExtents; float xMin = min.x; float xMax = max.x; float yMin = min.y; float yMax = max.y; float zMin = min.z; float zMax = max.z; for (int index = 1; index < bounds.Length; index++) { Bounds thisBounds = bounds[index]; Vector3 thisCenter = thisBounds.center; Vector3 thisExtents = thisBounds.extents; Vector3 thisMin = thisCenter - thisExtents; Vector3 thisMax = thisCenter + thisExtents; xMin = HydraMathUtils.Min(xMin, thisMin.x); xMax = HydraMathUtils.Max(xMax, thisMax.x); yMin = HydraMathUtils.Min(yMin, thisMin.y); yMax = HydraMathUtils.Max(yMax, thisMax.y); zMin = HydraMathUtils.Min(zMin, thisMin.z); zMax = HydraMathUtils.Max(zMax, thisMax.z); } return(MinMax(new Vector3(xMin, yMin, zMin), new Vector3(xMax, yMax, zMax))); }
/// <summary> /// Converts RGB color values to HSL. /// </summary> /// <returns>The HSL value.</returns> /// <param name="red">Red.</param> /// <param name="green">Green.</param> /// <param name="blue">Blue.</param> /// <param name="alpha">Alpha.</param> public static Vector4 RgbToHsl(float red, float green, float blue, float alpha) { float max = HydraMathUtils.Max(red, green, blue); float min = HydraMathUtils.Min(red, green, blue); float hue = (max + min) / 2.0f; float saturation; float lightness = hue; if (HydraMathUtils.Approximately(max, min)) { // achromatic hue = 0.0f; saturation = 0.0f; } else { float delta = max - min; saturation = (lightness > 0.5f) ? delta / (2.0f - max - min) : delta / (max + min); if (red >= green && red >= blue) { hue = (green - blue) / delta + (green < blue ? 6.0f : 0.0f); } else if (green >= red && green >= blue) { hue = (blue - red) / delta + 2.0f; } else { hue = (red - green) / delta + 4.0f; } hue /= 6.0f; } return(new Vector4(hue, saturation, lightness, alpha)); }
/// <summary> /// Divides the channels. /// </summary> /// <returns>The blend.</returns> /// <param name="baseLayer">Base layer.</param> /// <param name="topLayer">Top layer.</param> public static Color BlendDivide(Color baseLayer, Color topLayer) { return(new Color(HydraMathUtils.Min(baseLayer.r / topLayer.r, 1.0f), HydraMathUtils.Min(baseLayer.g / topLayer.g, 1.0f), HydraMathUtils.Min(baseLayer.b / topLayer.b, 1.0f), HydraMathUtils.Min(baseLayer.a / topLayer.a, 1.0f))); }
/// <summary> /// Returns the sums of the color channels. /// </summary> /// <returns>The added layers.</returns> /// <param name="baseLayer">Base layer.</param> /// <param name="topLayer">Top layer.</param> public static Color BlendAdd(Color baseLayer, Color topLayer) { return(new Color(HydraMathUtils.Min(baseLayer.r + topLayer.r, 1.0f), HydraMathUtils.Min(baseLayer.g + topLayer.g, 1.0f), HydraMathUtils.Min(baseLayer.b + topLayer.b, 1.0f), HydraMathUtils.Min(baseLayer.a + topLayer.a, 1.0f))); }
/// <summary> /// Returns the smallest value in each channel. /// </summary> /// <returns>The smallest channels.</returns> /// <param name="baseLayer">Base layer.</param> /// <param name="topLayer">Top layer.</param> public static Color BlendDarken(Color baseLayer, Color topLayer) { return(new Color(HydraMathUtils.Min(baseLayer.r, topLayer.r), HydraMathUtils.Min(baseLayer.g, topLayer.g), HydraMathUtils.Min(baseLayer.b, topLayer.b), HydraMathUtils.Min(baseLayer.a, topLayer.a))); }