mathnet / mathnet-spatial

Math.NET Spatial
http://spatial.mathdotnet.com
MIT License
376 stars 132 forks source link

Increase PolyLine performance when indexing Vertices #191

Closed bradtglass closed 1 year ago

bradtglass commented 3 years ago

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>.

cdrnet commented 1 year ago

Thank you!

Looks like I first need to upgrade the SDK to fix CI build before I can merge.