public static void Clear(this WriteableBitmap bitmap, Color color, Rect rect) { int pixelRight = Math.Max(bitmap.PixelWidth - 1, 0); int pixelBottom = Math.Max(bitmap.PixelHeight - 1, 0); int left = (int)MathTool.Clamp(Math.Floor(rect.Left), 0.0, pixelRight); int right = (int)MathTool.Clamp(Math.Floor(rect.Right), 0.0, pixelRight); int top = (int)MathTool.Clamp(Math.Floor(rect.Top), 0.0, pixelBottom); int bottom = (int)MathTool.Clamp(Math.Floor(rect.Left), 0.0, pixelBottom); int stride = bitmap.PixelWidth - (left + right); int a = top * bitmap.PixelWidth + left; int c = (color.A << 24) + (color.R << 16) + (color.G << 8) + color.B; for (int i = top; i <= bottom; ++i) { for (int j = left; j <= right; ++j) { #if SILVERLIGHT bitmap.Pixels[i] = c; #else //bitmap.BackBuffer[i]=c; #endif } a += stride; } }
public static Vector3D SphericalInterpolation(Vector3D start, Vector3D end, double p) { double cosΩ = MathTool.Clamp(Vector3D.DotProduct(start, end) / (start.Length * end.Length), -1.0, 1.0); double Ω = Math.Acos(cosΩ); return(SphericalInterpolation(start, end, Ω, Math.Sin(Ω), p)); }
public static Color FromARGBInterpolation(Color min, double p, Color max) { double q = MathTool.Clamp(p, 0.0, 1.0); #if false double amin = min.A / 255.0; double rmin = amin > 0 ? min.R * amin : min.R; double gmin = amin > 0 ? min.G * amin : min.G; double bmin = amin > 0 ? min.B * amin : min.B; double amax = max.A / 255.0; double rmax = amax > 0 ? max.R * amax : max.R; double gmax = amax > 0 ? max.G * amax : max.G; double bmax = amax > 0 ? max.B * amax : max.B; double a = amin * (1.0 - q) + amax * q; double r = (rmin * (1.0 - q) + rmax * q) / a; double g = (gmin * (1.0 - q) + gmax * q) / a; double b = (bmin * (1.0 - q) + bmax * q) / a; return(Color.FromArgb((byte)(a * 255.0), (byte)r, (byte)g, (byte)b)); #else double a = min.A * (1.0 - q) + max.A * q; double r = min.R * (1.0 - q) + max.R * q; double g = min.G * (1.0 - q) + max.G * q; double b = min.B * (1.0 - q) + max.B * q; return(Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b)); #endif }
public static double[] FromAHSVInterpolation(double[] minimum, double p, double[] maximum) { double[] b = minimum; double[] e = maximum; double b1 = b[1] >= 0 ? b[1] : e[1]; double e1 = e[1] >= 0 ? e[1] : b[1]; if (b1 >= 0 && e1 >= 0 && System.Math.Abs(e1 - b1) > 180) { if (e1 > b1) { b1 += 360; } else { e1 += 360; } } p = MathTool.Clamp(p, 0.0, 1.0); double[] ahsv = { b[0] * (1.0 - p) + e[0] * p, b1 *(1.0 - p) + e1 * p, b[2] * (1.0 - p) + e[2] * p, b[3] * (1.0 - p) + e[3] * p }; return(ahsv); }
public static Color Lightened(this Color color, double p) { double[] ahsl = color.AHSL(); if (p < 0.0) { return(FromAHSL(ahsl[0], ahsl[1], ahsl[2], ahsl[3] * (1.0 - MathTool.Clamp(-p, 0.0, 1.0)))); } else { return(FromAHSL(ahsl[0], ahsl[1], ahsl[2], ahsl[3] + MathTool.Clamp(p, 0.0, 1.0) * (1.0 - ahsl[3]))); } }