From 9e84b489e7a2f2ff5a0ee25fdb11d3d0b37dfacc Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Thu, 23 Jul 2009 02:11:53 +0800 Subject: [PATCH] interpolation: code style Signed-off-by: Christoph Ruegg --- .../Algorithms/BarycentricInterpolation.cs | 40 +++++----- .../Algorithms/LinearSplineInterpolation.cs | 20 ++--- .../NevillePolynomialInterpolation.cs | 52 ++++++------ .../RationalPoleFreeInterpolation.cs | 16 ++-- .../Algorithms/SplineInterpolation.cs | 79 +++++++++---------- src/Managed/Interpolation/IInterpolation.cs | 2 +- src/Managed/Interpolation/Interpolation.cs | 2 +- src/Settings.Resharper.xml | 79 +++++++++++++++++++ 8 files changed, 184 insertions(+), 106 deletions(-) create mode 100644 src/Settings.Resharper.xml diff --git a/src/Managed/Interpolation/Algorithms/BarycentricInterpolation.cs b/src/Managed/Interpolation/Algorithms/BarycentricInterpolation.cs index 461f631d..981760f1 100644 --- a/src/Managed/Interpolation/Algorithms/BarycentricInterpolation.cs +++ b/src/Managed/Interpolation/Algorithms/BarycentricInterpolation.cs @@ -42,17 +42,17 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// /// Sample Points t. /// - private IList points; + private IList _points; /// /// Sample Values x(t). /// - private IList values; + private IList _values; /// /// Barycentric Weights w(t). /// - private IList weights; + private IList _weights; /// /// Initializes a new instance of the BarycentricInterpolation class. @@ -72,7 +72,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms IList sampleValues, IList barycentricWeights) { - this.Initialize(samplePoints, sampleValues, barycentricWeights); + Initialize(samplePoints, sampleValues, barycentricWeights); } /// @@ -135,9 +135,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLengths); } - this.points = samplePoints; - this.values = sampleValues; - this.weights = barycentricWeights; + _points = samplePoints; + _values = sampleValues; + _weights = barycentricWeights; } /// @@ -148,19 +148,19 @@ namespace MathNet.Numerics.Interpolation.Algorithms public double Interpolate(double t) { // trivial case: only one sample? - if (this.points.Count == 1) + if (_points.Count == 1) { - return this.values[0]; + return _values[0]; } // evaluate closest point and offset from that point (no sorting assumed) int closestPoint = 0; - double offset = t - this.points[0]; - for (int i = 1; i < this.points.Count; i++) + double offset = t - _points[0]; + for (int i = 1; i < _points.Count; i++) { - if (Math.Abs(t - this.points[i]) < Math.Abs(offset)) + if (Math.Abs(t - _points[i]) < Math.Abs(offset)) { - offset = t - this.points[i]; + offset = t - _points[i]; closestPoint = i; } } @@ -168,7 +168,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms // trivial case: on a known sample point? if (offset.AlmostZero()) { - return this.values[closestPoint]; + return _values[closestPoint]; } if (Math.Abs(offset) > 1e-150) @@ -180,18 +180,18 @@ namespace MathNet.Numerics.Interpolation.Algorithms double s1 = 0.0; double s2 = 0.0; - for (int i = 0; i < this.points.Count; i++) + for (int i = 0; i < _points.Count; i++) { if (i != closestPoint) { - double v = offset * this.weights[i] / (t - this.points[i]); - s1 = s1 + (v * this.values[i]); + double v = offset * _weights[i] / (t - _points[i]); + s1 = s1 + (v * _values[i]); s2 = s2 + v; } else { - double v = this.weights[i]; - s1 = s1 + (v * this.values[i]); + double v = _weights[i]; + s1 = s1 + (v * _values[i]); s2 = s2 + v; } } @@ -239,4 +239,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms throw new NotSupportedException(); } } -} +} \ No newline at end of file diff --git a/src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs b/src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs index 2fe4f5b9..82d2bf6c 100644 --- a/src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs +++ b/src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs @@ -42,14 +42,14 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// /// Internal Spline Interpolation /// - private readonly SplineInterpolation spline; + private readonly SplineInterpolation _spline; /// /// Initializes a new instance of the LinearSplineInterpolation class. /// public LinearSplineInterpolation() { - this.spline = new SplineInterpolation(); + _spline = new SplineInterpolation(); } /// @@ -61,8 +61,8 @@ namespace MathNet.Numerics.Interpolation.Algorithms IList samplePoints, IList sampleValues) { - this.spline = new SplineInterpolation(); - this.Initialize(samplePoints, sampleValues); + _spline = new SplineInterpolation(); + Initialize(samplePoints, sampleValues); } /// @@ -123,7 +123,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms coefficients[j + 3] = 0; } - this.spline.Initialize(samplePoints, coefficients); + _spline.Initialize(samplePoints, coefficients); } /// @@ -133,7 +133,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// Interpolated value x(t). public double Interpolate(double t) { - return this.spline.Interpolate(t); + return _spline.Interpolate(t); } /// @@ -145,7 +145,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// public double Differentiate(double t) { - return this.spline.Differentiate(t); + return _spline.Differentiate(t); } /// @@ -162,7 +162,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms out double interpolatedValue, out double secondDerivative) { - return this.spline.Differentiate(t, out interpolatedValue, out secondDerivative); + return _spline.Differentiate(t, out interpolatedValue, out secondDerivative); } /// @@ -173,7 +173,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// public double Integrate(double t) { - return this.spline.Integrate(t); + return _spline.Integrate(t); } } -} +} \ No newline at end of file diff --git a/src/Managed/Interpolation/Algorithms/NevillePolynomialInterpolation.cs b/src/Managed/Interpolation/Algorithms/NevillePolynomialInterpolation.cs index 58ee1542..20cbc92e 100644 --- a/src/Managed/Interpolation/Algorithms/NevillePolynomialInterpolation.cs +++ b/src/Managed/Interpolation/Algorithms/NevillePolynomialInterpolation.cs @@ -49,12 +49,12 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// /// Sample Points t. /// - private IList points; + private IList _points; /// /// Spline Values x(t). /// - private IList values; + private IList _values; /// /// Initializes a new instance of the NevillePolynomialInterpolation class. @@ -72,7 +72,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms IList samplePoints, IList sampleValues) { - this.Initialize(samplePoints, sampleValues); + Initialize(samplePoints, sampleValues); } /// @@ -118,8 +118,8 @@ namespace MathNet.Numerics.Interpolation.Algorithms throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLengths); } - this.points = samplePoints; - this.values = sampleValues; + _points = samplePoints; + _values = sampleValues; } /// @@ -129,16 +129,16 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// Interpolated value x(t). public double Interpolate(double t) { - double[] x = new double[this.values.Count]; - this.values.CopyTo(x, 0); + double[] x = new double[_values.Count]; + _values.CopyTo(x, 0); for (int level = 1; level < x.Length; level++) { for (int i = 0; i < x.Length - level; i++) { - double hp = t - this.points[i + level]; - double ho = this.points[i] - t; - double den = this.points[i] - this.points[i + level]; + double hp = t - _points[i + level]; + double ho = _points[i] - t; + double den = _points[i] - _points[i + level]; x[i] = ((hp * x[i]) + (ho * x[i + 1])) / den; } } @@ -155,17 +155,17 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// public double Differentiate(double t) { - double[] x = new double[this.values.Count]; - double[] dx = new double[this.values.Count]; - this.values.CopyTo(x, 0); + double[] x = new double[_values.Count]; + double[] dx = new double[_values.Count]; + _values.CopyTo(x, 0); for (int level = 1; level < x.Length; level++) { for (int i = 0; i < x.Length - level; i++) { - double hp = t - this.points[i + level]; - double ho = this.points[i] - t; - double den = this.points[i] - this.points[i + level]; + double hp = t - _points[i + level]; + double ho = _points[i] - t; + double den = _points[i] - _points[i + level]; dx[i] = ((hp * dx[i]) + x[i] + (ho * dx[i + 1]) - x[i + 1]) / den; x[i] = ((hp * x[i]) + (ho * x[i + 1])) / den; } @@ -188,26 +188,26 @@ namespace MathNet.Numerics.Interpolation.Algorithms out double interpolatedValue, out double secondDerivative) { - double[] x = new double[this.values.Count]; - double[] dx = new double[this.values.Count]; - double[] d2x = new double[this.values.Count]; - this.values.CopyTo(x, 0); + double[] x = new double[_values.Count]; + double[] dx = new double[_values.Count]; + double[] ddx = new double[_values.Count]; + _values.CopyTo(x, 0); for (int level = 1; level < x.Length; level++) { for (int i = 0; i < x.Length - level; i++) { - double hp = t - this.points[i + level]; - double ho = this.points[i] - t; - double den = this.points[i] - this.points[i + level]; - d2x[i] = ((hp * d2x[i]) + (ho * d2x[i + 1]) + (2 * dx[i]) - (2 * dx[i + 1])) / den; + double hp = t - _points[i + level]; + double ho = _points[i] - t; + double den = _points[i] - _points[i + level]; + ddx[i] = ((hp * ddx[i]) + (ho * ddx[i + 1]) + (2 * dx[i]) - (2 * dx[i + 1])) / den; dx[i] = ((hp * dx[i]) + x[i] + (ho * dx[i + 1]) - x[i + 1]) / den; x[i] = ((hp * x[i]) + (ho * x[i + 1])) / den; } } interpolatedValue = x[0]; - secondDerivative = d2x[0]; + secondDerivative = ddx[0]; return dx[0]; } @@ -222,4 +222,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms throw new NotSupportedException(); } } -} +} \ No newline at end of file diff --git a/src/Managed/Interpolation/Algorithms/RationalPoleFreeInterpolation.cs b/src/Managed/Interpolation/Algorithms/RationalPoleFreeInterpolation.cs index f03c2a5d..8a809374 100644 --- a/src/Managed/Interpolation/Algorithms/RationalPoleFreeInterpolation.cs +++ b/src/Managed/Interpolation/Algorithms/RationalPoleFreeInterpolation.cs @@ -42,14 +42,14 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// /// Internal Barycentric Interpolation /// - private readonly BarycentricInterpolation barycentric; + private readonly BarycentricInterpolation _barycentric; /// /// Initializes a new instance of the RationalPoleFreeInterpolation class. /// public RationalPoleFreeInterpolation() { - this.barycentric = new BarycentricInterpolation(); + _barycentric = new BarycentricInterpolation(); } /// @@ -61,8 +61,8 @@ namespace MathNet.Numerics.Interpolation.Algorithms IList samplePoints, IList sampleValues) { - this.barycentric = new BarycentricInterpolation(); - this.Initialize(samplePoints, sampleValues); + _barycentric = new BarycentricInterpolation(); + Initialize(samplePoints, sampleValues); } /// @@ -96,7 +96,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms IList samplePoints, IList sampleValues) { - this.Initialize(samplePoints, sampleValues, Math.Min(3, samplePoints.Count - 1)); + Initialize(samplePoints, sampleValues, Math.Min(3, samplePoints.Count - 1)); } /// @@ -198,7 +198,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms weights[perm[i]] = sortedWeights[i]; } - this.barycentric.Initialize(samplePoints, sampleValues, weights); + _barycentric.Initialize(samplePoints, sampleValues, weights); } /// @@ -208,7 +208,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// Interpolated value x(t). public double Interpolate(double t) { - return this.barycentric.Interpolate(t); + return _barycentric.Interpolate(t); } /// @@ -251,4 +251,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms throw new NotSupportedException(); } } -} +} \ No newline at end of file diff --git a/src/Managed/Interpolation/Algorithms/SplineInterpolation.cs b/src/Managed/Interpolation/Algorithms/SplineInterpolation.cs index ffc5d5bb..6b28cfcc 100644 --- a/src/Managed/Interpolation/Algorithms/SplineInterpolation.cs +++ b/src/Managed/Interpolation/Algorithms/SplineInterpolation.cs @@ -42,17 +42,17 @@ namespace MathNet.Numerics.Interpolation.Algorithms /// /// Sample Points t. /// - private IList points; + private IList _points; /// /// Spline Coefficients c(t). /// - private IList coefficients; + private IList _coefficients; /// /// Number of samples. /// - private int sampleCount; + private int _sampleCount; /// /// Initializes a new instance of the SplineInterpolation class. @@ -70,7 +70,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms IList samplePoints, IList splineCoefficients) { - this.Initialize(samplePoints, splineCoefficients); + Initialize(samplePoints, splineCoefficients); } /// @@ -121,9 +121,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms throw new ArgumentOutOfRangeException("splineCoefficients"); } - this.points = samplePoints; - this.coefficients = splineCoefficients; - this.sampleCount = samplePoints.Count; + _points = samplePoints; + _coefficients = splineCoefficients; + _sampleCount = samplePoints.Count; } /// @@ -136,13 +136,13 @@ namespace MathNet.Numerics.Interpolation.Algorithms int closestLeftIndex = IndexOfClosestPointLeftOf(t); // Interpolation - double offset = t - this.points[closestLeftIndex]; + double offset = t - _points[closestLeftIndex]; int k = closestLeftIndex << 2; - return this.coefficients[k] - + (offset * (this.coefficients[k + 1] - + (offset * (this.coefficients[k + 2] - + (offset * this.coefficients[k + 3]))))); + return _coefficients[k] + + (offset * (_coefficients[k + 1] + + (offset * (_coefficients[k + 2] + + (offset * _coefficients[k + 3]))))); } /// @@ -157,12 +157,12 @@ namespace MathNet.Numerics.Interpolation.Algorithms int closestLeftIndex = IndexOfClosestPointLeftOf(t); // Differentiation - double offset = t - this.points[closestLeftIndex]; + double offset = t - _points[closestLeftIndex]; int k = closestLeftIndex << 2; - return this.coefficients[k + 1] - + (2 * offset * this.coefficients[k + 2]) - + (3 * offset * offset * this.coefficients[k + 3]); + return _coefficients[k + 1] + + (2 * offset * _coefficients[k + 2]) + + (3 * offset * offset * _coefficients[k + 3]); } /// @@ -182,20 +182,20 @@ namespace MathNet.Numerics.Interpolation.Algorithms int closestLeftIndex = IndexOfClosestPointLeftOf(t); // Differentiation - double offset = t - this.points[closestLeftIndex]; + double offset = t - _points[closestLeftIndex]; int k = closestLeftIndex << 2; - interpolatedValue = this.coefficients[k] - + (offset * (this.coefficients[k + 1] - + (offset * (this.coefficients[k + 2] - + (offset * this.coefficients[k + 3]))))); + interpolatedValue = _coefficients[k] + + (offset * (_coefficients[k + 1] + + (offset * (_coefficients[k + 2] + + (offset * _coefficients[k + 3]))))); - secondDerivative = (2 * this.coefficients[k + 2]) - + (6 * offset * this.coefficients[k + 3]); + secondDerivative = (2 * _coefficients[k + 2]) + + (6 * offset * _coefficients[k + 3]); - return this.coefficients[k + 1] - + (2 * offset * this.coefficients[k + 2]) - + (3 * offset * offset * this.coefficients[k + 3]); + return _coefficients[k + 1] + + (2 * offset * _coefficients[k + 2]) + + (3 * offset * offset * _coefficients[k + 3]); } /// @@ -212,21 +212,20 @@ namespace MathNet.Numerics.Interpolation.Algorithms double result = 0; for (int i = 0, j = 0; i < closestLeftIndex; i++, j += 4) { - double w = this.points[i + 1] - this.points[i]; - result += w * (this.coefficients[j] - + ((w * (this.coefficients[j + 1] * 0.5)) - + (w * ((this.coefficients[j + 2] / 3) - + (w * this.coefficients[j + 3] * 0.25))))); + double w = _points[i + 1] - _points[i]; + result += w * (_coefficients[j] + + ((w * _coefficients[j + 1] * 0.5) + + (w * ((_coefficients[j + 2] / 3) + + (w * _coefficients[j + 3] * 0.25))))); } - double offset = t - this.points[closestLeftIndex]; + double offset = t - _points[closestLeftIndex]; int k = closestLeftIndex << 2; - return result - + (offset * (this.coefficients[k] - + ((offset * (this.coefficients[k + 1] * 0.5)) - + (offset * (this.coefficients[k + 2] / 3)) - + (offset * this.coefficients[k + 3] * 0.25)))); + return result + (offset * (_coefficients[k] + + (offset * _coefficients[k + 1] * 0.5) + + (offset * _coefficients[k + 2] / 3) + + (offset * _coefficients[k + 3] * 0.25))); } /// @@ -238,11 +237,11 @@ namespace MathNet.Numerics.Interpolation.Algorithms { // Binary search in the [ t[0], ..., t[n-2] ] (t[n-1] is not included) int low = 0; - int high = this.sampleCount - 1; + int high = _sampleCount - 1; while (low != high - 1) { int middle = (low + high) / 2; - if (this.points[middle] > t) + if (_points[middle] > t) { high = middle; } @@ -255,4 +254,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms return low; } } -} +} \ No newline at end of file diff --git a/src/Managed/Interpolation/IInterpolation.cs b/src/Managed/Interpolation/IInterpolation.cs index a4fa6b24..8f198a6b 100644 --- a/src/Managed/Interpolation/IInterpolation.cs +++ b/src/Managed/Interpolation/IInterpolation.cs @@ -84,4 +84,4 @@ namespace MathNet.Numerics.Interpolation /// double Integrate(double t); } -} +} \ No newline at end of file diff --git a/src/Managed/Interpolation/Interpolation.cs b/src/Managed/Interpolation/Interpolation.cs index 0edcb4cc..16a5813d 100644 --- a/src/Managed/Interpolation/Interpolation.cs +++ b/src/Managed/Interpolation/Interpolation.cs @@ -91,4 +91,4 @@ namespace MathNet.Numerics.Interpolation return method; } } -} +} \ No newline at end of file diff --git a/src/Settings.Resharper.xml b/src/Settings.Resharper.xml new file mode 100644 index 00000000..5611929d --- /dev/null +++ b/src/Settings.Resharper.xml @@ -0,0 +1,79 @@ + + + + NEXT_LINE + NEXT_LINE + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD + 4 + NEXT_LINE + + public + protected + internal + private + new + abstract + virtual + override + sealed + static + readonly + extern + unsafe + volatile + + True + True + + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file