public SortedSet(Compare compare, Array items, bool alreadySorted) { if (compare == null) throw new Exception("compare must be provided"); _compare = compare; _items = items ?? new Array(); if (!alreadySorted) _items.Sort((CompareCallback)(object)_compare); }
public static bool HaveSameVertices( WKSPointZ[] coords1, WKSPointZ[] coords2, double xyTolerance, double zTolerance, bool ignoreDuplicateVertices = true) { Assert.ArgumentNotNull(coords1, nameof(coords1)); Assert.ArgumentNotNull(coords2, nameof(coords2)); IComparer <WKSPointZ> comparer = new WKSPointZComparer(); Array.Sort(coords1, comparer); Array.Sort(coords2, comparer); var i1 = 0; var i2 = 0; while (i1 < coords1.Length && i2 < coords2.Length) { WKSPointZ a = coords1[i1]; WKSPointZ b = coords2[i2]; if (!GeometryUtils.IsSamePoint(a, b, xyTolerance, zTolerance)) { return(false); } // Advance to next set of coordinates: ++i1; ++i2; // Skip identical points in sequence! while (ignoreDuplicateVertices && ArePointsEqual(coords1, i1, i1 - 1, xyTolerance, zTolerance)) { ++i1; } while (ignoreDuplicateVertices && ArePointsEqual(coords2, i2, i2 - 1, xyTolerance, zTolerance)) { ++i2; } } return((i1 == coords1.Length) && (i2 == coords2.Length)); }
private IList <WKSPointZ> GetChangedVertices( WKSPointZ[] baseCoords, WKSPointZ[] compareCoords, bool reportDuplicateVertices, bool baseInsertsOnly) { Assert.ArgumentNotNull(baseCoords, nameof(baseCoords)); Assert.ArgumentNotNull(compareCoords, nameof(compareCoords)); var comparer = new WKSPointZComparer(_xyTolerance, _zTolerance, 0, 0, 0); Array.Sort(baseCoords, comparer); Array.Sort(compareCoords, comparer); var result = new List <WKSPointZ>(); var i1 = 0; var i2 = 0; while (i1 < baseCoords.Length && i2 < compareCoords.Length) { WKSPointZ a = baseCoords[i1]; WKSPointZ b = compareCoords[i2]; bool inSync = GeometryUtils.IsSamePoint(a, b, _xyTolerance, _zTolerance); if (!inSync) { // a is greater than b, advance b until in sync with a bool matchAdvanceCompareCoords = AdvanceIndexUntilMatch( compareCoords, ref i2, a, comparer, result, !baseInsertsOnly, reportDuplicateVertices); // b is greater than a, advance a until in sync with b bool matchAdvanceBaseCoords = AdvanceIndexUntilMatch( baseCoords, ref i1, b, comparer, result, true, reportDuplicateVertices); if (matchAdvanceCompareCoords || matchAdvanceBaseCoords) { inSync = true; } } // Advance to next set of coordinates only if in sync to make sure no difference points are missed if (inSync) { ++i1; ++i2; } // Skip identical points in sequence otherwise From/To points in rotated ring get reported as changes // NOTE: SameCoords tolerates index out of bounds! while (WKSPointZUtils.ArePointsEqual(baseCoords, i1, i1 - 1, _xyTolerance, _zTolerance)) { bool compareCoordsHasDuplicateToo = inSync && WKSPointZUtils.ArePointsEqual(compareCoords, i2, i2 - 1, _xyTolerance, _zTolerance); if (compareCoordsHasDuplicateToo) { // in sync and both have a duplicate at the same location -> unchanged, do not report // but increment both indexes ++i2; } else { // not in sync or compare geometry has no duplicate -> changed, report on request if (reportDuplicateVertices) { result.Add(baseCoords[i1]); } } // eventually landing at the next non-identical point: ++i1; } // process remaining duplicates at current location (or at original location if not in sync) while (WKSPointZUtils.ArePointsEqual(compareCoords, i2, i2 - 1, _xyTolerance, _zTolerance)) { if (reportDuplicateVertices && !baseInsertsOnly) { result.Add(compareCoords[i2]); } ++i2; } } AddRemainingPoints(baseCoords, compareCoords, i1, i2, result, reportDuplicateVertices, baseInsertsOnly); return(result); }
public static IList <KeyValuePair <WKSPointZ, List <WKSPointZ> > > GroupPoints( [NotNull] WKSPointZ[] coords, double xyTolerance, double zTolerance) { Assert.ArgumentNotNull(coords, nameof(coords)); IComparer <WKSPointZ> comparer = new WKSPointZComparer(); Array.Sort(coords, comparer); var toleranceGroups = new List <List <WKSPointZ> >(); var currentGroup = new List <WKSPointZ> { coords[0] }; for (var i = 1; i < coords.Length; i++) { if (!ArePointsEqual(coords, i - 1, i, xyTolerance, zTolerance)) { toleranceGroups.Add(currentGroup); currentGroup = new List <WKSPointZ> { coords[i] }; continue; } currentGroup.Add(coords[i]); } if (currentGroup.Count > 0) { toleranceGroups.Add(currentGroup); } var result = new List <KeyValuePair <WKSPointZ, List <WKSPointZ> > >(); // For strict interpretation of tolerance: Consider splitting clusters that are too large (Divisive Hierarchical clustering) foreach (List <WKSPointZ> groupedPoints in toleranceGroups) { if (groupedPoints.Count == 1) { result.Add(new KeyValuePair <WKSPointZ, List <WKSPointZ> >(groupedPoints[0], groupedPoints)); } else { var center = new WKSPointZ { X = groupedPoints.Average(p => p.X), Y = groupedPoints.Average(p => p.Y), Z = groupedPoints.Average(p => p.Z) }; result.Add(new KeyValuePair <WKSPointZ, List <WKSPointZ> >(center, groupedPoints)); } } return(result); }
static void CommonlyUsedGenericInstantiations() { // Make absolutely sure we include some of the most common // instantiations here in mscorlib's ngen image. // Note that reference type instantiations are already included // automatically for us. // Need to sort non null, len > 1 array or paths will short-circuit Array.Sort <double>(new double[1]); Array.Sort <int>(new int[1]); Array.Sort <IntPtr>(new IntPtr[1]); new ArraySegment <byte>(new byte[1], 0, 0); new Dictionary <Char, Object>(); new Dictionary <Guid, Byte>(); new Dictionary <Guid, Object>(); new Dictionary <Guid, Guid>(); // Added for Visual Studio 2010 new Dictionary <Int16, IntPtr>(); new Dictionary <Int32, Byte>(); new Dictionary <Int32, Int32>(); new Dictionary <Int32, Object>(); new Dictionary <IntPtr, Boolean>(); new Dictionary <IntPtr, Int16>(); new Dictionary <Object, Boolean>(); new Dictionary <Object, Char>(); new Dictionary <Object, Guid>(); new Dictionary <Object, Int32>(); new Dictionary <Object, Int64>(); // Added for Visual Studio 2010 new Dictionary <uint, WeakReference>(); // NCL team needs this new Dictionary <Object, UInt32>(); new Dictionary <UInt32, Object>(); new Dictionary <Int64, Object>(); #if FEATURE_CORECLR // to genereate mdil for Dictionary instantiation when key is user defined value type new Dictionary <Guid, Int32>(); #endif // Microsoft.Windows.Design new Dictionary <System.Reflection.MemberTypes, Object>(); new EnumEqualityComparer <System.Reflection.MemberTypes>(); // Microsoft.Expression.DesignModel new Dictionary <Object, KeyValuePair <Object, Object> >(); new Dictionary <KeyValuePair <Object, Object>, Object>(); NullableHelper <Boolean>(); NullableHelper <Byte>(); NullableHelper <Char>(); NullableHelper <DateTime>(); NullableHelper <Decimal>(); NullableHelper <Double>(); NullableHelper <Guid>(); NullableHelper <Int16>(); NullableHelper <Int32>(); NullableHelper <Int64>(); NullableHelper <Single>(); NullableHelper <TimeSpan>(); NullableHelper <DateTimeOffset>(); // For SQL new List <Boolean>(); new List <Byte>(); new List <Char>(); new List <DateTime>(); new List <Decimal>(); new List <Double>(); new List <Guid>(); new List <Int16>(); new List <Int32>(); new List <Int64>(); new List <TimeSpan>(); new List <SByte>(); new List <Single>(); new List <UInt16>(); new List <UInt32>(); new List <UInt64>(); new List <IntPtr>(); new List <KeyValuePair <Object, Object> >(); new List <GCHandle>(); // NCL team needs this new List <DateTimeOffset>(); new KeyValuePair <Char, UInt16>('\0', UInt16.MinValue); new KeyValuePair <UInt16, Double>(UInt16.MinValue, Double.MinValue); new KeyValuePair <Object, Int32>(String.Empty, Int32.MinValue); new KeyValuePair <Int32, Int32>(Int32.MinValue, Int32.MinValue); SZArrayHelper <Boolean>(null); SZArrayHelper <Byte>(null); SZArrayHelper <DateTime>(null); SZArrayHelper <Decimal>(null); SZArrayHelper <Double>(null); SZArrayHelper <Guid>(null); SZArrayHelper <Int16>(null); SZArrayHelper <Int32>(null); SZArrayHelper <Int64>(null); SZArrayHelper <TimeSpan>(null); SZArrayHelper <SByte>(null); SZArrayHelper <Single>(null); SZArrayHelper <UInt16>(null); SZArrayHelper <UInt32>(null); SZArrayHelper <UInt64>(null); SZArrayHelper <DateTimeOffset>(null); SZArrayHelper <CustomAttributeTypedArgument>(null); SZArrayHelper <CustomAttributeNamedArgument>(null); #if FEATURE_CORECLR #pragma warning disable 4014 // This is necessary to generate MDIL for AsyncVoidMethodBuilder AsyncHelper <int>(); AsyncHelper2 <int>(); AsyncHelper3(); #pragma warning restore 4014 #endif }
public static void Sort(Array keys, Array items, int index, int length) { Array.Sort(keys, items, index, length, (IComparer)null); }
public static void Sort(Array array, int index, int length) { Array.Sort(array, index, length, (IComparer)null); }
public static void Sort(Array keys, Array items) { Array.Sort(keys, items, (IComparer)null); }