Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CADability/BSpline2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,10 +1668,9 @@ public override void AddToGraphicsPath(System.Drawing.Drawing2D.GraphicsPath pat
// Notfalls Darstellung als Polyline
int l = poles.Length * 4 + 2;
PointF[] ppf = new PointF[l];
double du = (endParam - startParam) / (l - 1);
for (int i = 0; i < l; ++i)
{
ppf[i] = PointAt(startParam + i * du).PointF;
ppf[i] = PointAt((double)i / (l - 1)).PointF; // PointAt expects 0..1, not the knot parameter
}
if (!forward) Array.Reverse(ppf);
path.AddLines(ppf);
Expand Down
31 changes: 31 additions & 0 deletions tests/CADability.Tests/BSpline2DGraphicsPathTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if WINDOWS
using CADability.Curve2D;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace CADability.Tests
{
/// <summary>
/// <see cref="BSpline2D.AddToGraphicsPath"/> passed knot parameters to <see cref="BSpline2D.PointAt"/>, which expects
/// 0..1, so a spline whose knots do not run from 0 to 1 was drawn through wrong points. GDI+ only works on Windows, so
/// this test only runs there.
/// </summary>
[TestClass]
public class BSpline2DGraphicsPathTests
{
[TestMethod]
public void ASplineWithKnotsBeyondOneIsSampledOnTheCurve()
{
BSpline2D bsp = new BSpline2D(new[] { new GeoPoint2D(0, 0), new GeoPoint2D(1, 3), new GeoPoint2D(4, 3), new GeoPoint2D(5, 0) }, null, new double[] { 0, 5 }, new[] { 4, 4 }, 3, false, 0, 5);
GraphicsPath path = new GraphicsPath();
bsp.AddToGraphicsPath(path, true);
PointF[] points = path.PathPoints;
Assert.AreEqual(bsp.StartPoint.PointF, points[0]);
Assert.AreEqual(bsp.EndPoint.PointF, points[points.Length - 1]);
// MinDistance and not Distance: BSpline2D.Distance returns double.MaxValue for these points
foreach (PointF p in points) Assert.AreEqual(0.0, bsp.MinDistance(new GeoPoint2D(p.X, p.Y)), 1e-4);
}
}
}
#endif
Loading