static public IEnumerable <T> OrderByNearestPointOnLine <T>( this IEnumerable <T> sequence, Vektor2DInt lineVector, Func <T, Vektor2DInt?> getPointRepresentingElement) { var LineVectorLength = lineVector.Length(); if (null == getPointRepresentingElement || LineVectorLength < 1) { return(sequence); } var LineVectorNormalizedMilli = (lineVector * 1000) / LineVectorLength; return (sequence?.Select(element => { Int64?LocationOnLine = null; var PointRepresentingElement = getPointRepresentingElement(element); if (PointRepresentingElement.HasValue) { LocationOnLine = PointRepresentingElement.Value.A * LineVectorNormalizedMilli.A + PointRepresentingElement.Value.B * LineVectorNormalizedMilli.B; } return new { Element = element, LocationOnLine = LocationOnLine }; }) ?.OrderBy(elementAndLocation => elementAndLocation.LocationOnLine) ?.Select(elementAndLocation => (T)elementAndLocation.Element)); }
public static IEnumerable <T> OrderByNearestPointOnLine <T>(this IEnumerable <T> sequence, Vektor2DInt lineVector, Func <T, Vektor2DInt?> getPointRepresentingElement) { long num = lineVector.Length(); if (getPointRepresentingElement == null || num < 1) { return(sequence); } Vektor2DInt LineVectorNormalizedMilli = lineVector * 1000L / num; return(sequence?.Select(delegate(T element) { long?locationOnLine = null; Vektor2DInt?vektor2DInt = getPointRepresentingElement(element); if (vektor2DInt.HasValue) { locationOnLine = vektor2DInt.Value.A * LineVectorNormalizedMilli.A + vektor2DInt.Value.B * LineVectorNormalizedMilli.B; } return new { Element = element, LocationOnLine = locationOnLine }; })?.OrderBy(elementAndLocation => elementAndLocation.LocationOnLine)?.Select(elementAndLocation => elementAndLocation.Element)); }