unsafe public AnchorEdge[] GetFrozenEdges() { int numEdges = GetNumFrozenEdges(); checkError(); var res = new AnchorEdge[numEdges]; if (numEdges > 0) { FrozenWorld_Edge *fwe = stackalloc FrozenWorld_Edge[numEdges]; numEdges = FrozenWorld_GetEdges(FrozenWorld_Snapshot.FROZEN, numEdges, fwe); checkError(); for (int i = 0; i < numEdges; i++) { res[i] = new AnchorEdge() { anchorId1 = (AnchorId)fwe[i].anchorId1, anchorId2 = (AnchorId)fwe[i].anchorId2 }; } } return(res); }
unsafe public void AddSpongyEdges(ICollection <AnchorEdge> spongyEdges) { AnchorEdge[] regularEdges = new AnchorEdge[spongyEdges.Count]; int idx = 0; foreach (var edge in spongyEdges) { regularEdges[idx++] = RegularEdge(edge.anchorId1, edge.anchorId2); } System.Comparison <AnchorEdge> alphabeticCompare = (x, y) => { int cmp1 = x.anchorId1.CompareTo(y.anchorId1); if (cmp1 < 0) { return(-1); } if (cmp1 > 0) { return(1); } int cmp2 = x.anchorId2.CompareTo(y.anchorId2); return(cmp2); }; System.Array.Sort(regularEdges, alphabeticCompare); int spongyIdx = 0; for (int frozenIdx = 0; frozenIdx < frozenEdges.Count; ++frozenIdx) { if (spongyIdx >= regularEdges.Length) { break; } int frozenToSpongy = alphabeticCompare(frozenEdges[frozenIdx], regularEdges[spongyIdx]); if (frozenToSpongy >= 0) { if (frozenToSpongy > 0) { // insert edge here frozenEdges.Insert(frozenIdx, regularEdges[spongyIdx]); } // If existing frozen is greater, we just inserted (above) spongy, so advance. // If they are equal, we want to skip spongy, so advance. // If existing is lesser, we haven't reached insertion point yet, // so don't advance spongyIdx (stay out of this conditional branch if frozenToSpongy < 0). ++spongyIdx; } } while (spongyIdx < regularEdges.Length) { frozenEdges.Add(regularEdges[spongyIdx++]); } checkError(); }
unsafe public AnchorEdge[] GetFrozenEdges() { int numEdges = GetNumFrozenEdges(); checkError(); var res = new AnchorEdge[numEdges]; for (int i = 0; i < res.Length; ++i) { res[i] = frozenEdges[i]; } return(res); }