コード例 #1
0
        /// <summary>
        /// Concatenates this path after the given path.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public PathSegment <TIdType> ConcatenateAfter(PathSegment <TIdType> path)
        {
            PathSegment <TIdType> clone     = this.Clone();
            PathSegment <TIdType> first     = clone.First();
            PathSegment <TIdType> pathClone = path.Clone();

            PathSegment <TIdType> current = clone;

            current.Weight = path.Weight + current.Weight;
            while (current.From != null)
            {
                current.From.Weight = path.Weight + current.From.Weight;
                current             = current.From;
            }

            if (first.VertexId.Equals(path.VertexId))
            {
                first.Weight = pathClone.Weight;
                first.From   = pathClone.From;
                return(clone);
            }
            throw new ArgumentException("Paths must share beginning and end vertices to concatenate!");
        }
コード例 #2
0
ファイル: PathSegment.cs プロジェクト: detlevn/OsmSharp
        /// <summary>
        /// Concatenates this path after the given path.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="comparer"></param>
        /// <returns></returns>
        public PathSegment <TIdType> ConcatenateAfter(PathSegment <TIdType> path, Func <TIdType, TIdType, int> comparer)
        {
            PathSegment <TIdType> clone     = this.Clone();
            PathSegment <TIdType> first     = clone.First();
            PathSegment <TIdType> pathClone = path.Clone();

            PathSegment <TIdType> current = clone;

            current.Weight = path.Weight + current.Weight;
            while (current.From != null)
            {
                current.From.Weight = path.Weight + current.From.Weight;
                current             = current.From;
            }

            if (comparer == null)
            { // use default equals.
                if (first.VertexId.Equals(path.VertexId))
                {
                    first.Weight = pathClone.Weight;
                    first.From   = pathClone.From;
                    return(clone);
                }
                throw new ArgumentException("Paths must share beginning and end vertices to concatenate!");
            }
            else
            { // use custom comparer.
                if (comparer.Invoke(first.VertexId, path.VertexId) == 0)
                {
                    first.Weight = pathClone.Weight;
                    first.From   = pathClone.From;
                    return(clone);
                }
                throw new ArgumentException("Paths must share beginning and end vertices to concatenate!");
            }
        }