/// <summary> /// Determines whether an entity is in the set. /// </summary> /// <returns> /// <c>true</c> if <paramref name="item"/> is found in the set; otherwise, false. /// </returns> /// <param name="item"> The entity to locate in the set. The value can be null.</param> public new virtual bool Contains(TEntity item) { IEqualityComparer <TEntity> comparer = new ObjectReferenceEqualityComparer(); foreach (var entity in Items) { if (comparer.Equals(entity, item)) { return(true); } } return(false); }
/// <summary> /// Removes the first occurrence of a specific entity object from the set. /// </summary> /// <returns> /// <c>true</c> if <paramref name="item"/> is successfully removed; otherwise, false. /// This method also returns <c>false</c> if <paramref name="item"/> was not found in the set. /// </returns> /// <param name="item"> The entity to remove from the set. The value can be null.</param> public new virtual bool Remove(TEntity item) { IEqualityComparer <TEntity> comparer = new ObjectReferenceEqualityComparer(); var index = 0; for (; index < Count; index++) { if (comparer.Equals(Items[index], item)) { break; } } if (index == Count) { return(false); } RemoveItem(index); return(true); }
private void RemoveCollinearLines() { var objectReferenceComparer = new ObjectReferenceEqualityComparer <LineObstacle>(); for (var i = 0; i < 8; i++) { var points = new Dictionary <Vector2, List <LineObstacle> >(); var lines = GetObstacles(i, ObstacleType.Line); foreach (LineObstacle obstacle in lines) { AddLine(obstacle.Start, obstacle, points); AddLine(obstacle.End, obstacle, points); } foreach (var point in points.Where(point => point.Value.Count > 1)) { var angles = new List <KeyValuePair <double, LineObstacle> >(); foreach (var lineObstacle in point.Value) { var angle = Math.Abs(Math.Atan2(lineObstacle.End.Y - lineObstacle.Start.Y, lineObstacle.End.X - lineObstacle.Start.X)); angles.Add(new KeyValuePair <double, LineObstacle>(angle, lineObstacle)); } var groups = angles.GroupBy(x => x.Key).ToDictionary(g => g.Key, g => g.ToList()); foreach (var group in groups) { var lineList = group.Value.Select(groupValue => groupValue.Value).Distinct(objectReferenceComparer).ToList(); if (lineList.Count > 1) { var newLine = MergeLines(lineList, i); foreach (var lineObstacle in lineList) { Remove(lineObstacle); } Add(newLine); } } } } }