/// <summary> /// <para>Returns +1 if this instances angle is larger than obj angle.</para> /// <para>Returns -1 if obj angle is larger than this instances angle.</para> /// <para>(Returns 0 if they are the same).</para> /// </summary> /// <param name="obj">Object to compare to</param> /// <returns></returns> public int CompareTo(object obj) { HorizontalPoint other = (HorizontalPoint)obj; //return Math.Sign(other.Angle - Angle); return(Math.Sign(Angle - other.Angle)); }
public List <HorizontalPoint> GetHorizontalPointsInRange(float fromAngle, float toAngle, VerticalAngle verticalAngle) { if (Distances == null || (!Distances.ContainsKey(verticalAngle))) { return new List <HorizontalPoint>() { new HorizontalPoint(0, float.NaN) } } ; List <HorizontalPoint> pointsInRange = new List <HorizontalPoint>(); bool angleSpansZero = fromAngle > toAngle; int startIndex = Distances[verticalAngle].FindIndex(point => point.Angle > fromAngle); if (angleSpansZero) { if (startIndex != -1) { for (int i = startIndex; i < Distances[verticalAngle].Count; i++) { pointsInRange.Add(Distances[verticalAngle][i]); } } int endIndex = Distances[verticalAngle].FindIndex(point2 => point2.Angle > toAngle); for (int i = 0; i < endIndex; i++) { pointsInRange.Add(Distances[verticalAngle][i]); } } else { if (startIndex == -1) { return new List <HorizontalPoint>() { new HorizontalPoint(0, float.NaN) } } ; int i = startIndex; HorizontalPoint point = Distances[verticalAngle][i]; while (point.Angle < toAngle && i < Distances[verticalAngle].Count) { point = Distances[verticalAngle][i]; pointsInRange.Add(point); ++i; } } return(pointsInRange); }