Ejemplo n.º 1
0
        /// <summary>
        /// Loads a vertex and returns true if found.
        /// </summary>
        /// <param name="vertexId"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        private bool LoadVertex(uint vertexId, out float latitude, out float longitude)
        {
            uint    blockId = CHBlock.CalculateId(vertexId, _blockSize);
            CHBlock block;

            if (!_blocks.TryGet(blockId, out block))
            { // damn block not cached!
                block = this.DeserializeBlock(blockId);
                if (block == null)
                { // oops even now the block is not found!
                    longitude = 0;
                    latitude  = 0;
                    return(false);
                }
                _blocks.Add(blockId, block);
            }
            uint blockIdx = vertexId - blockId;

            if (block.Vertices != null &&
                blockIdx < block.Vertices.Length)
            { // block is found and the vertex is there!
                latitude  = block.Vertices[blockIdx].Latitude;
                longitude = block.Vertices[blockIdx].Longitude;
                return(true);
            }
            // oops even now the block is not found!
            longitude = 0;
            latitude  = 0;
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads all arcs associated with the given vertex.
        /// </summary>
        /// <param name="vertexId"></param>
        /// <returns></returns>
        private KeyValuePair <uint, CHEdgeData>[] LoadArcs(uint vertexId)
        {
            uint    blockId = CHBlock.CalculateId(vertexId, _blockSize);
            CHBlock block;

            if (!_blocks.TryGet(blockId, out block))
            { // damn block not cached!
                block = this.DeserializeBlock(blockId);
                if (block == null)
                { // oops even now the block is not found!
                    return(new KeyValuePair <uint, CHEdgeData> [0]);
                }
                _blocks.Add(blockId, block);
            }
            uint blockIdx = vertexId - blockId;

            if (block.Vertices != null &&
                blockIdx < block.Vertices.Length)
            { // block is found and the vertex is there!
                KeyValuePair <uint, CHEdgeData>[] arcs = new KeyValuePair <uint, CHEdgeData> [
                    block.Vertices[blockIdx].ArcCount];
                for (int arcIdx = block.Vertices[blockIdx].ArcIndex;
                     arcIdx < block.Vertices[blockIdx].ArcIndex + block.Vertices[blockIdx].ArcCount; arcIdx++)
                { // loop over all arcs.
                    CHArc      chArc    = block.Arcs[arcIdx];
                    CHEdgeData edgeData = new CHEdgeData();
                    edgeData.Direction          = chArc.Direction;
                    edgeData.ContractedVertexId = chArc.ShortcutId;
                    edgeData.Weight             = chArc.Weight;
                    edgeData.Tags = chArc.TagsId;
                    arcs[arcIdx - block.Vertices[blockIdx].ArcIndex] = new KeyValuePair <uint, CHEdgeData>(
                        chArc.TargetId, edgeData);
                }
                return(arcs);
            }
            // oops even now the block is not found!
            return(new KeyValuePair <uint, CHEdgeData> [0]);
        }