namespace View_by_Distance.Shared.Models.Stateless.Methods; internal abstract class Sorting { internal static Models.Sorting Get(int faceDistancePermyriad, double rangeDistanceTolerance, Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength) { Models.Sorting result; if (faceDistanceLength.Length is null) throw new NotSupportedException(); if (faceDistanceLength.NormalizedRectangle is null) throw new NotSupportedException(); if (faceDistanceEncoding.MinimumDateTime is null || faceDistanceLength.MinimumDateTime is null) throw new NotSupportedException(); long ticks = faceDistanceEncoding.MinimumDateTime.Value.Ticks; TimeSpan timeSpan = new(faceDistanceLength.MinimumDateTime.Value.Ticks - ticks); bool older = timeSpan.TotalMilliseconds < 0; int daysDelta = (int)Math.Round(Math.Abs(timeSpan.TotalDays), 0); int distancePermyriad = (int)(faceDistanceLength.Length.Value / rangeDistanceTolerance * faceDistancePermyriad); result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, faceDistanceLength.NormalizedRectangle.Value, older); return result; } }