private Element ReadElement(BinaryReader reader, BoundingBox bbox) { var elementId = reader.ReadInt64(); var type = (ElementType)reader.ReadByte(); Element element; switch (type) { case ElementType.Node: element = ReadNode(reader); if (bbox != null && !element.IsInside(bbox)) { return(null); } break; case ElementType.Way: var way = ReadWay(reader); if (bbox != null && !way.IsInside(bbox)) { _objectPool.StoreList(way.Coordinates); return(null); } element = way; break; case ElementType.Relation: var relation = ReadRelation(reader); if (bbox != null && !relation.IsInside(bbox)) { foreach (var relationWay in relation.Members.OfType <Way>()) { _objectPool.StoreList(relationWay.Coordinates); } return(null); } element = relation; break; default: throw new InvalidOperationException(String.Format("Unknown element type: {0}", type)); } element.Id = elementId; var tags = ReadTags(_keyValueStore, reader); element.Tags = tags; return(element); }
/// <summary> Dispose pattern implementation. </summary> /// <param name="disposing">True if necessary to dispose managed resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { // return lists to object pool foreach (var tuple in Surfaces) { _objectPool.StoreList(tuple.Item1.Points); } foreach (var water in Water) { _objectPool.StoreList(water.Points); } foreach (var road in Roads) { _objectPool.StoreList(road.Points); } } }
/// <inheritdoc /> public void Dispose() { _objectPool.StoreList(Entrances); _objectPool.StoreList(Apartments); _objectPool.StoreList(Stairs); _objectPool.StoreList(OuterWalls); _objectPool.StoreList(PartitionWalls); _objectPool.StoreList(TransitWalls); }
/// <summary> /// Reduces the number of points /// </summary> public static void Reduce(List <Vector2d> source, List <Vector2d> destination, Double tolerance, IObjectPool objectPool) { if (source == null || source.Count < 3) { destination.AddRange(source); return; } Int32 firstPoint = 0; Int32 lastPoint = source.Count - 1; var pointIndexsToKeep = objectPool.NewList <int>(128); //Add the first and last index to the keepers pointIndexsToKeep.Add(firstPoint); pointIndexsToKeep.Add(lastPoint); //The first and the last point can not be the same while (source[firstPoint].Equals(source[lastPoint])) { lastPoint--; } Reduce(source, firstPoint, lastPoint, tolerance, pointIndexsToKeep); pointIndexsToKeep.Sort(); for (int i = 0; i < pointIndexsToKeep.Count; i++) { var index = pointIndexsToKeep[i]; // NOTE do not add items twice due to bug in implementation if (i > 0 && pointIndexsToKeep[i - 1] == pointIndexsToKeep[i]) { continue; } destination.Add(source[index]); } objectPool.StoreList(pointIndexsToKeep); }
/// <summary> Splits line to segments. </summary> public void Split(Point s, Point e, IObjectPool objectPool, List <Point> result) { var start = new Point(s.X, s.Y); var end = new Point(e.X, e.Y); var points = objectPool.NewList <Point>(); points.Add(s); double slope = (e.Y - s.Y) / (e.X - s.X); if (double.IsInfinity(slope) || Math.Abs(slope) < double.Epsilon) { ZeroSlope(s, e, points); } else { NormalCase(start, end, slope, points); } MergeResults(points, result); objectPool.StoreList(points); }
/// <inheritdoc /> public void LoadArea(Tile tile, Area area) { LoadModel(tile, area, (rule, modelBuilder) => modelBuilder.BuildArea(tile, rule, area)); _objectPool.StoreList(area.Points); }
public void Dispose() { _objectPool.StoreList(Triangles); Triangles = null; }
/// <inheritdoc /> public void Dispose() { _objectPool.StoreList(OuterWalls); _objectPool.StoreList(TransitWalls); _objectPool.StoreList(PartitionWalls); }
/// <inheritdoc /> public void Dispose() { _objectPool.StoreList(Points); _objectPool.StoreList(Holes); _objectPool.StoreList(Segments); }