/// <summary>Calculate the interpolation list for a bezier curve.</summary> /// <param name="inputPoints">The bezier points [Start][Control1]...[End].<see cref="System.Windows.Point[]"/></param> /// <param name="resultPointNumber">The number of requested result points.<see cref="System.Int32"/></param> /// <param name="resultPoints">The calculated result points.<see cref="System.Windows.Point[]"/></param> public static void CalculateInterpolationPoints(System.Windows.Point[] inputPoints, int resultPointNumber, System.Windows.Point[] resultPoints) { if (resultPointNumber <= 0) { SimpleLog.LogLine(TraceEventType.Error, CLASS_NAME + "::CalculateInterpolationPoints () Requires a positive number of result points!"); return; } int inputPointLength = (inputPoints.Length); double step, t; t = 0; step = (double)1.0 / (resultPointNumber - 1); for (int resultPointIndex = 0; resultPointIndex < resultPointNumber; resultPointIndex++) { if ((1.0 - t) < 5e-6) { t = 1.0; } resultPoints[resultPointIndex].X = 0.0; resultPoints[resultPointIndex].Y = 0.0; for (int i = 0; i < inputPointLength; i++) { double basis = Bernstein(inputPointLength - 1, i, t); resultPoints[resultPointIndex].X += basis * inputPoints[i].X; resultPoints[resultPointIndex].Y += basis * inputPoints[i].Y; } t += step; } }
// ############################################################################### // ### M E T H O D S // ############################################################################### #region Methods /// <summary>Add an item to the end of the list.</summary> /// <param name="item">The style to add to the list.<see cref="ITextStyle"/></param> /// <remarks>The list is limited to a maximum of 32 styles.</remarks> public void Add(ITextStyle item) { if (_styles.Count >= 32) { SimpleLog.LogLine(TraceEventType.Error, CLASS_NAME + "::Add () Can't handle more than 32 styles!"); } else { _styles.Add(item); } }
/// <summary>Calculate the interpolation list for a arc curve.</summary> /// <param name="centerX">The arc center point x coordinate.<see cref="System.Double"/></param> /// <param name="centerY">The arc center point y coordinate.<see cref="System.Double"/></param> /// <param name="radiusX">The arc radius at x axis.<see cref="System.Double"/></param> /// <param name="radiusY">The arc radius at y axis.<see cref="System.Double"/></param> /// <param name="startAngle">The arc start angle in radiants relative to the 12 o'clock position.<see cref="System.Double"/></param> /// <param name="endAngle">The arc end angle in radiants relative to the 12 o'clock position.<see cref="System.Double"/></param> /// <param name="reverseDirection">The arc has to be drawn in reverse direction (counterclockwise).<see cref="System.Boolean"/></param> /// <param name="resultPointNumber">The number of requested result points.<see cref="System.Int32"/></param> /// <param name="resultPoints">The calculated result points.<see cref="System.Windows.Point[]"/></param> public static void CalculateInterpolationPoints(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double endAngle, bool reverseDirection, int resultPointNumber, System.Windows.Point[] resultPoints) { if (resultPointNumber <= 0) { SimpleLog.LogLine(TraceEventType.Error, CLASS_NAME + "::CalculateInterpolationPoints () Requires a positive number of result points!"); return; } double angle = Math.Abs(endAngle - startAngle); if (reverseDirection) { angle = Math.PI * 2 - angle; } if (endAngle < startAngle) { angle = -angle; } double angleStep = angle / (resultPointNumber - 1); if (reverseDirection) { angleStep = -angleStep; } double currentAngle = startAngle; for (int resultPointIndex = 0; resultPointIndex < resultPointNumber; resultPointIndex++) { resultPoints[resultPointIndex].X = centerX + (radiusX * Math.Sin(currentAngle)); // Y-axis has negative direction! resultPoints[resultPointIndex].Y = centerY - (radiusY * Math.Cos(currentAngle)); if (resultPointIndex == resultPointNumber - 2) { currentAngle = endAngle; } else { currentAngle += angleStep; } } }
/// <summary>Add the elements of the specified collection to the end of the list.</summary> /// <param name="collection">The collection whose elements are added to the end of the list.<see cref="IEnumerable<ITextStyle>"/></param> /// <remarks>The list is limited to a maximum of 32 styles.</remarks> public void AddRange(IEnumerable <ITextStyle> collection) { if (collection == null) { throw new ArgumentNullException("collection"); } foreach (ITextStyle item in collection) { if (_styles.Count >= 32) { SimpleLog.LogLine(TraceEventType.Error, CLASS_NAME + "::AddRange () Can't handle more than 32 styles!"); return; } else { _styles.Add(item); } } }