diff --git a/CADability/BSpline2D.cs b/CADability/BSpline2D.cs index 501b8b54..0ded13f9 100644 --- a/CADability/BSpline2D.cs +++ b/CADability/BSpline2D.cs @@ -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); diff --git a/tests/CADability.Tests/BSpline2DGraphicsPathTests.cs b/tests/CADability.Tests/BSpline2DGraphicsPathTests.cs new file mode 100644 index 00000000..236ccf5c --- /dev/null +++ b/tests/CADability.Tests/BSpline2DGraphicsPathTests.cs @@ -0,0 +1,31 @@ +#if WINDOWS +using CADability.Curve2D; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Drawing; +using System.Drawing.Drawing2D; + +namespace CADability.Tests +{ + /// + /// passed knot parameters to , 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. + /// + [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