Skip to content

Commit

Permalink
Merge pull request #1041 from KaterynaSloboda/fix-EllipticalArc.ToPol…
Browse files Browse the repository at this point in the history
…yline-bug

Update ToPolyline function in BoundedCurve
  • Loading branch information
wynged authored Oct 26, 2023
2 parents 12b323e + f588e61 commit 82071df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- `IndexedPolycurve.GetSubdivisionParameters` now works correctly with `startSetbackDistance` and `endSetbackDistance` parameters.
- `Polyline.Frames` now works correctly with `startSetbackDistance` and `endSetbackDistance` parameters.
- `Polygon.Frames` now works correctly with `startSetbackDistance` and `endSetbackDistance` parameters.
- `BoundedCurve.ToPolyline` now works correctly for `EllipticalArc` class.


### Changed
Expand Down
23 changes: 0 additions & 23 deletions Elements/src/Geometry/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,29 +484,6 @@ public override Transform TransformAt(double u)
return this.BasisCurve.TransformAt(u);
}

/// <summary>
/// Create a polyline through a set of points along the curve.
/// </summary>
/// <param name="divisions">The number of divisions of the curve.</param>
/// <returns>A polyline.</returns>
public override Polyline ToPolyline(int divisions = 10)
{
var pts = new List<Vector3>(divisions + 1);
var step = this.Domain.Length / divisions;
for (var t = this.Domain.Min; t < this.Domain.Max; t += step)
{
pts.Add(PointAt(t));
}

// We don't go all the way to the end parameter, and
// add it here explicitly because rounding errors can
// cause small imprecision which accumulates to make
// the final parameter slightly more/less than the actual
// end parameter.
pts.Add(PointAt(this.Domain.Max));
return new Polyline(pts);
}

/// <summary>
/// Get the parameter at a distance from the start parameter along the curve.
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions Elements/src/Geometry/BoundedCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ public virtual Polyline ToPolyline(int divisions = 10)
{
var pts = new List<Vector3>(divisions + 1);
var step = this.Domain.Length / divisions;
for (var t = 0; t <= divisions; t++)
for (var t = this.Domain.Min; t < this.Domain.Max; t += step)
{
pts.Add(PointAt(t * step));
pts.Add(PointAt(t));
}

// We don't go all the way to the end parameter, and
// add it here explicitly because rounding errors can
// cause small imprecision which accumulates to make
// the final parameter slightly more/less than the actual
// end parameter.
pts.Add(PointAt(this.Domain.Max));
return new Polyline(pts);
}

Expand Down
10 changes: 10 additions & 0 deletions Elements/test/EllipticalArcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,15 @@ public void EllipticalArcTransforms()
}
this.Model.AddElement(new ModelCurve(ellipticalArc, BuiltInMaterials.ZAxis));
}

[Fact]
public void ToPolyline()
{
var arc = new EllipticalArc(Vector3.Origin, 1, 2, 10, 20);
var p = arc.ToPolyline(10);
Assert.Equal(10, p.Segments().Length);
Assert.Equal(arc.Start, p.Vertices[0]);
Assert.Equal(arc.End, p.Vertices[p.Vertices.Count - 1]);
}
}
}

0 comments on commit 82071df

Please sign in to comment.