Disabling Nuvoton NCT6791D because of fan full speed bug on Asus Z97 WS.
1 // --------------------------------------------------------------------------------------------------------------------
2 // <copyright file="CanonicalSplineHelper.cs" company="OxyPlot">
3 // The MIT License (MIT)
5 // Copyright (c) 2012 Oystein Bjorke
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be included
16 // in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 // Interpolates a list of points using a canonical spline.
29 // --------------------------------------------------------------------------------------------------------------------
33 using System.Collections.Generic;
37 /// Provides functionality to interpolate a list of points by a canonical spline.
39 internal static class CanonicalSplineHelper
41 // CanonicalSplineHelper.cs (c) 2009 by Charles Petzold (WPF and Silverlight)
42 // www.charlespetzold.com/blog/2009/01/Canonical-Splines-in-WPF-and-Silverlight.html
44 /// Creates a spline of data points.
46 /// <param name="points">
49 /// <param name="tension">
52 /// <param name="tensions">
55 /// <param name="isClosed">
56 /// True if the spline is closed.
58 /// <param name="tolerance">
62 /// A list of data points.
64 internal static List<IDataPoint> CreateSpline(
65 IList<IDataPoint> points, double tension, IList<double> tensions, bool isClosed, double tolerance)
67 var screenPoints = points.Select(p => new ScreenPoint(p.X, p.Y)).ToList();
68 var interpolatedScreenPoints = CreateSpline(screenPoints, tension, tensions, isClosed, tolerance);
69 var interpolatedDataPoints = new List<IDataPoint>(interpolatedScreenPoints.Count);
71 foreach (var s in interpolatedScreenPoints)
73 interpolatedDataPoints.Add(new DataPoint(s.X, s.Y));
76 return interpolatedDataPoints;
80 /// Creates a spline of screen points.
82 /// <param name="points">
85 /// <param name="tension">
88 /// <param name="tensions">
91 /// <param name="isClosed">
92 /// True if the spline is closed.
94 /// <param name="tolerance">
98 /// A list of screen points.
100 internal static List<ScreenPoint> CreateSpline(
101 IList<ScreenPoint> points, double tension, IList<double> tensions, bool isClosed, double tolerance)
103 var result = new List<ScreenPoint>();
109 int n = points.Count;
117 result.AddRange(points);
125 Segment(result, points[0], points[0], points[1], points[1], tension, tension, tolerance);
129 Segment(result, points[1], points[0], points[1], points[0], tension, tension, tolerance);
130 Segment(result, points[0], points[1], points[0], points[1], tension, tension, tolerance);
135 bool useTensionCollection = tensions != null && tensions.Count > 0;
137 for (int i = 0; i < n; i++)
139 double t1 = useTensionCollection ? tensions[i % tensions.Count] : tension;
140 double t2 = useTensionCollection ? tensions[(i + 1) % tensions.Count] : tension;
146 isClosed ? points[n - 1] : points[0],
161 isClosed ? points[0] : points[i + 1],
170 Segment(result, points[i - 1], points[i], points[0], points[1], t1, t2, tolerance);
175 Segment(result, points[i - 1], points[i], points[i + 1], points[i + 2], t1, t2, tolerance);
186 /// <param name="points">
189 /// <param name="pt0">
192 /// <param name="pt1">
195 /// <param name="pt2">
198 /// <param name="pt3">
201 /// <param name="t1">
204 /// <param name="t2">
207 /// <param name="tolerance">
210 private static void Segment(
211 IList<ScreenPoint> points,
220 // See Petzold, "Programming Microsoft Windows with C#", pages 645-646 or
221 // Petzold, "Programming Microsoft Windows with Microsoft Visual Basic .NET", pages 638-639
222 // for derivation of the following formulas:
223 double sx1 = t1 * (pt2.X - pt0.X);
224 double sy1 = t1 * (pt2.Y - pt0.Y);
225 double sx2 = t2 * (pt3.X - pt1.X);
226 double sy2 = t2 * (pt3.Y - pt1.Y);
228 double ax = sx1 + sx2 + 2 * pt1.X - 2 * pt2.X;
229 double ay = sy1 + sy2 + 2 * pt1.Y - 2 * pt2.Y;
230 double bx = -2 * sx1 - sx2 - 3 * pt1.X + 3 * pt2.X;
231 double by = -2 * sy1 - sy2 - 3 * pt1.Y + 3 * pt2.Y;
238 var num = (int)((Math.Abs(pt1.X - pt2.X) + Math.Abs(pt1.Y - pt2.Y)) / tolerance);
240 // Notice begins at 1 so excludes the first point (which is just pt1)
241 for (int i = 1; i < num; i++)
243 double t = (double)i / (num - 1);
244 var pt = new ScreenPoint(
245 ax * t * t * t + bx * t * t + cx * t + dx,
246 ay * t * t * t + by * t * t + cy * t + dy);