conveyal/transitive.js

View on GitHub
lib/graph/edge.js

Summary

Maintainability
F
1 wk
Test Coverage

File edge.js has 630 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { forEach } from 'lodash'

import {
  ccw,
  distance,
Severity: Major
Found in lib/graph/edge.js - About 1 day to fix

    Edge has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class Edge {
      /**
       * Initialize a new edge
       * @constructor
       * @param {Point[]} pointArray - the internal Points for this Edge
    Severity: Minor
    Found in lib/graph/edge.js - About 5 hrs to fix

      Function getRenderCoords has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        getRenderCoords(fromOffsetPx, toOffsetPx, display, forward) {
          const isBase = fromOffsetPx === 0 && toOffsetPx === 0
      
          if (!this.baseRenderCoords && !isBase) {
            this.calculateBaseRenderCoords(display)
      Severity: Major
      Found in lib/graph/edge.js - About 3 hrs to fix

        Function getRenderCoords has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          getRenderCoords(fromOffsetPx, toOffsetPx, display, forward) {
            const isBase = fromOffsetPx === 0 && toOffsetPx === 0
        
            if (!this.baseRenderCoords && !isBase) {
              this.calculateBaseRenderCoords(display)
        Severity: Minor
        Found in lib/graph/edge.js - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function calculateGeometry has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          calculateGeometry(cellSize, angleConstraint) {
            // if(!this.hasTransit()) angleConstraint = 5;
            angleConstraint = angleConstraint || 45
        
            this.angleConstraintR = (angleConstraint * Math.PI) / 180
        Severity: Minor
        Found in lib/graph/edge.js - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function calculateGeometry has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          calculateGeometry(cellSize, angleConstraint) {
            // if(!this.hasTransit()) angleConstraint = 5;
            angleConstraint = angleConstraint || 45
        
            this.angleConstraintR = (angleConstraint * Math.PI) / 180
        Severity: Major
        Found in lib/graph/edge.js - About 2 hrs to fix

          Function getGeometricCoords has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            getGeometricCoords(fromOffsetPx, toOffsetPx, display, forward) {
              const coords = []
          
              // reverse the coords array if needed
              const geomCoords = forward
          Severity: Major
          Found in lib/graph/edge.js - About 2 hrs to fix

            Function calculateWorldLengthAndMidpoint has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              calculateWorldLengthAndMidpoint() {
                const allPoints = [this.fromVertex.point].concat(this.pointArray, [
                  this.toVertex.point
                ])
                this.worldLength = 0
            Severity: Minor
            Found in lib/graph/edge.js - About 1 hr to fix

              Function coordAlongRefEdge has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                coordAlongRefEdge(targetDistance, coords, refCoordinates = coords) {
                  // our current location along the edge (in world units)
                  let currentLocation = 0
                  for (let i = 1; i < refCoordinates.length; i++) {
                    const distanceToNextCoord = refCoordinates[i].len
              Severity: Minor
              Found in lib/graph/edge.js - About 1 hr to fix

                Function calculateWorldLengthAndMidpoint has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  calculateWorldLengthAndMidpoint() {
                    const allPoints = [this.fromVertex.point].concat(this.pointArray, [
                      this.toVertex.point
                    ])
                    this.worldLength = 0
                Severity: Minor
                Found in lib/graph/edge.js - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function equalVectors has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                function equalVectors(x1, y1, x2, y2, tol) {
                Severity: Minor
                Found in lib/graph/edge.js - About 35 mins to fix

                  Function coordAlongRefEdge has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    coordAlongRefEdge(targetDistance, coords, refCoordinates = coords) {
                      // our current location along the edge (in world units)
                      let currentLocation = 0
                      for (let i = 1; i < refCoordinates.length; i++) {
                        const distanceToNextCoord = refCoordinates[i].len
                  Severity: Minor
                  Found in lib/graph/edge.js - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    adjustFromAngle() {
                      const isCcw = ccw(
                        this.tx,
                        this.ty,
                        this.tx + this.tvx,
                  Severity: Major
                  Found in lib/graph/edge.js and 1 other location - About 1 day to fix
                  lib/graph/edge.js on lines 259..282

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 254.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    adjustToAngle() {
                      const isCcw = ccw(
                        this.fx,
                        this.fy,
                        this.fx + this.fvx,
                  Severity: Major
                  Found in lib/graph/edge.js and 1 other location - About 1 day to fix
                  lib/graph/edge.js on lines 289..312

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 254.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        if (i < geomCoords.length - 1) {
                          const nextCoord = geomCoords[i + 1]
                          const x2 = display.xScale.compute(nextCoord[0])
                          const y2 = display.yScale.compute(nextCoord[1])
                          if (x2 === x1 && y2 === y1) return
                  Severity: Major
                  Found in lib/graph/edge.js and 1 other location - About 3 hrs to fix
                  lib/graph/edge.js on lines 466..476

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 108.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        if (i > 0) {
                          const prevCoord = geomCoords[i - 1]
                          const x0 = display.xScale.compute(prevCoord[0])
                          const y0 = display.yScale.compute(prevCoord[1])
                          if (x1 === x0 && y1 === y0) return
                  Severity: Major
                  Found in lib/graph/edge.js and 1 other location - About 3 hrs to fix
                  lib/graph/edge.js on lines 479..489

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 108.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        } else if (!fromVector && toVector) {
                          // the last point in the geomCoords sequence
                          rightVector = normalizeVector({
                            x: toVector.y,
                            y: -toVector.x
                  Severity: Major
                  Found in lib/graph/edge.js and 1 other location - About 1 hr to fix
                  lib/graph/edge.js on lines 491..517

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 68.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        if (fromVector && !toVector) {
                          // the first point in the geomCoords sequence
                          rightVector = normalizeVector({
                            x: fromVector.y,
                            y: -fromVector.x
                  Severity: Major
                  Found in lib/graph/edge.js and 1 other location - About 1 hr to fix
                  lib/graph/edge.js on lines 499..517

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 68.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      if (alignmentId.substring(0, 2) === '90') {
                        min = Math.min(p1.y, p2.y)
                        max = Math.max(p1.y, p2.y)
                      } else {
                  Severity: Minor
                  Found in lib/graph/edge.js and 1 other location - About 50 mins to fix
                  lib/graph/edge.js on lines 425..428

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 51.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      } else {
                        min = Math.min(p1.x, p2.x)
                        max = Math.max(p1.x, p2.x)
                      }
                  Severity: Minor
                  Found in lib/graph/edge.js and 1 other location - About 50 mins to fix
                  lib/graph/edge.js on lines 422..425

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 51.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                          const dist = distance(
                            allPoints[i].worldX,
                            allPoints[i].worldY,
                            allPoints[i + 1].worldX,
                            allPoints[i + 1].worldY
                  Severity: Minor
                  Found in lib/graph/edge.js and 1 other location - About 40 mins to fix
                  lib/graph/edge.js on lines 67..72

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 48.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                        this.worldLength += distance(
                          allPoints[i].worldX,
                          allPoints[i].worldY,
                          allPoints[i + 1].worldX,
                          allPoints[i + 1].worldY
                  Severity: Minor
                  Found in lib/graph/edge.js and 1 other location - About 40 mins to fix
                  lib/graph/edge.js on lines 83..88

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 48.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                              y:
                                allPoints[i].worldY +
                                t * (allPoints[i + 1].worldY - allPoints[i].worldY)
                  Severity: Minor
                  Found in lib/graph/edge.js and 1 other location - About 30 mins to fix
                  lib/graph/edge.js on lines 94..96

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 45.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                              x:
                                allPoints[i].worldX +
                                t * (allPoints[i + 1].worldX - allPoints[i].worldX),
                  Severity: Minor
                  Found in lib/graph/edge.js and 1 other location - About 30 mins to fix
                  lib/graph/edge.js on lines 97..99

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 45.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status