mathnet-spatial icon indicating copy to clipboard operation
mathnet-spatial copied to clipboard

Increase PolyLine performance when indexing Vertices

Open bradtglass opened this issue 4 years ago • 0 comments

Expose IReadOnlyList<T> instead of IEnumerable<T> for PolyLine.Vertices

This change allows external methods to index or operate on the vertices without consuming additional memory by using ToList() or ToArray() or enumerating the entire collection multiple times. This change still ensures that the internal list is immutable.

I don't think this is a breaking changes because IReadOnlyList<T> implements IEnumerable<T>, so anything that relies on IEnumerable<T> will still work.

This is implemented by using ReadOnlyCollection<T> internally instead of List<T>.

I think the same change would be appropriate for Polygon2D too but I'm not sure if there was a specific reason for using a custom implementation of ImmutableList<T> instead of ReadOnlyCollection<T>.

bradtglass avatar Aug 19 '21 16:08 bradtglass