All files / lib/core path.js

0% Statements 0/20
0% Branches 0/4
0% Functions 0/8
0% Lines 0/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                                                                                           
/**
 * A path through the network graph. Composed of PathSegments (which
 * are in turn composed of a sequence of graph edges)
 */
export default class NetworkPath {
  /**
   * NetworkPath constructor
   * @param {Object} parent the parent object (a RoutePattern or Journey)
   */
 
  constructor(parent) {
    this.parent = parent
    this.segments = []
  }
 
  clearGraphData(segment) {
    this.segments.forEach(function (segment) {
      segment.clearGraphData()
    })
  }
 
  /**
   * addSegment: add a new segment to the end of this NetworkPath
   */
 
  addSegment(segment) {
    this.segments.push(segment)
    segment.points.forEach(function (point) {
      point.paths.push(this)
    }, this)
  }
 
  getRenderedSegments() {
    let renderedSegments = []
    this.segments.forEach(function (pathSegment) {
      renderedSegments = renderedSegments.concat(pathSegment.renderedSegments)
    })
    return renderedSegments
  }
 
  /**
   * getPointArray
   */
 
  getPointArray() {
    const points = []
    for (let i = 0; i < this.segments.length; i++) {
      const segment = this.segments[i]
      if (
        i > 0 &&
        segment.points[0] ===
          this.segments[i - 1].points[this.segments[i - 1].points.length - 1]
      ) {
        points.concat(segment.points.slice(1))
      } else {
        points.concat(segment.points)
      }
    }
    return points
  }
}