// // Copyright © James South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageProcessor { using System; /// /// Provides common mathematical methods. /// internal static class ImageMaths { /// /// Returns the result of a B-C filter against the given value. /// /// /// The value to process. /// The B-Spline curve variable. /// The Cardinal curve variable. /// /// The . /// public static double GetBcValue(double x, double b, double c) { double temp; if (x < 0) { x = -x; } temp = x * x; if (x < 1) { x = ((12 - (9 * b) - (6 * c)) * (x * temp)) + ((-18 + (12 * b) + (6 * c)) * temp) + (6 - (2 * b)); return x / 6; } if (x < 2) { x = ((-b - (6 * c)) * (x * temp)) + (((6 * b) + (30 * c)) * temp) + (((-12 * b) - (48 * c)) * x) + ((8 * b) + (24 * c)); return x / 6; } return 0; } /// /// Gets the result of a sine cardinal function for the given value. /// /// /// The value to calculate the result for. /// /// /// The . /// public static double SinC(double x) { const double Epsilon = .0001; if (Math.Abs(x) > Epsilon) { x *= Math.PI; return Clean(Math.Sin(x) / x); } return 1.0; } /// /// Ensures that any passed double is correctly rounded to zero /// /// The value to clean. /// /// The /// . private static double Clean(double x) { const double Epsilon = .0001; if (Math.Abs(x) < Epsilon) { return 0.0; } return x; } } }