public IReadOnlyList <uint> AddStrokes(IReadOnlyList <InkStroke> inkStrokes) { var strokeIds = new List <uint>(); var strokeIdArray = new uint[inkStrokes.Count]; if (inkStrokes.Count == 0) { return(strokeIds.AsReadOnly()); } // Duplicate list. var strokesToAdd = inkStrokes.ToList(); // Keep a second copy that we can search through. var inkStrokesSearchList = inkStrokes.ToList(); // First search through existing strokes. foreach (var pair in StrokeMap) { var index = strokesToAdd.FindIndex(stroke => stroke == pair.Value); if (index >= 0) { strokesToAdd.RemoveAt(index); var index2 = inkStrokesSearchList.FindIndex(stroke => stroke == pair.Value); if (index2 >= 0) { strokeIdArray[index2] = pair.Key; } } } // Add remaining strokes. foreach (var stroke in strokesToAdd) { uint newId = TotalStrokeCount; ++TotalStrokeCount; StrokeMap.Add(newId, stroke); RefCountMap.Add(newId, 0); var index = inkStrokesSearchList.FindIndex(listStroke => listStroke == stroke); if (index >= 0) { strokeIdArray[index] = newId; } } // Ensure stroke order is identical. for (uint i = 0; i < inkStrokes.Count; i++) { strokeIds.Add(strokeIdArray[i]); } return(strokeIds.AsReadOnly()); }
public uint AddStroke(InkStroke inkStroke) { if (StrokeMap.ContainsValue(inkStroke)) { return(StrokeMap.FirstOrDefault(x => x.Value == inkStroke).Key); } // Add new stroke. var newId = TotalStrokeCount; ++TotalStrokeCount; StrokeMap.Add(newId, inkStroke); RefCountMap.Add(newId, 0); return(newId); }