/// <summary> /// Is loop clockwise oriented? /// </summary> /// <param name="loop"></param> /// <param name="isTransmeridian"></param> /// <returns></returns> internal static bool IsClockwiseNormalized(this GeoFence loop, bool isTransmeridian) { decimal sum = 0m; GeoCoord a; GeoCoord b; // INIT_ITERATION; int loopIndex = -1; while (true) { if (++loopIndex >= loop.NumVerts) { break; } a = loop.Verts[loopIndex]; b = loop.Verts[(loopIndex + 1) % loop.NumVerts]; // If we identify a transmeridian arc (> 180 degrees longitude), // start over with the transmeridian flag set if (!isTransmeridian && Math.Abs(a.Longitude - b.Longitude) > Constants.H3.M_PI) { return(loop.IsClockwiseNormalized(true)); } sum += (b.Longitude.NormalizeLongitude(isTransmeridian) - a.Longitude.NormalizeLongitude(isTransmeridian)) * (b.Latitude + a.Latitude); } return(sum > 0); }
/// <summary> /// Is GeoFence clockwise? /// </summary> /// <param name="loop"></param> /// <returns></returns> public static bool IsClockwise(this GeoFence loop) { return(loop.IsClockwiseNormalized(false)); }