LCOV - code coverage report
Current view: top level - maps/random/rmgen/placer/noncentered - RandomPathPlacer.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 1 17 5.9 %
Date: 2023-04-02 12:52:40 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /**
       2             :  * Creates a winded path between the given two vectors.
       3             :  * Uses a random angle at each step, so it can be more random than the sin form of the PathPlacer.
       4             :  * Omits the given offset after the start and before the end.
       5             :  */
       6             : function RandomPathPlacer(pathStart, pathEnd, pathWidth, offset, blended)
       7             : {
       8           0 :         this.pathStart = Vector2D.add(pathStart, Vector2D.sub(pathEnd, pathStart).normalize().mult(offset)).round();
       9           0 :         this.pathEnd = pathEnd;
      10           0 :         this.offsetSquared = Math.square(offset);
      11           0 :         this.blended = blended;
      12           0 :         this.diskPlacer = new DiskPlacer(pathWidth);
      13           0 :         this.maxPathLength = fractionToTiles(2);
      14             : }
      15             : 
      16           6 : RandomPathPlacer.prototype.place = function(constraint)
      17             : {
      18           0 :         let pathLength = 0;
      19           0 :         let points = [];
      20           0 :         let position = this.pathStart;
      21             : 
      22           0 :         while (position.distanceToSquared(this.pathEnd) >= this.offsetSquared && pathLength++ < this.maxPathLength)
      23             :         {
      24           0 :                 position.add(
      25             :                         new Vector2D(1, 0).rotate(
      26             :                                 -getAngle(this.pathStart.x, this.pathStart.y, this.pathEnd.x, this.pathEnd.y) +
      27             :                                 -Math.PI / 2 * (randFloat(-1, 1) + (this.blended ? 0.5 : 0)))).round();
      28             : 
      29           0 :                 this.diskPlacer.setCenterPosition(position);
      30             : 
      31           0 :                 for (let point of this.diskPlacer.place(constraint))
      32           0 :                         if (points.every(p => !Vector2D.isEqualTo(p, point)))
      33           0 :                                 points.push(point);
      34             :         }
      35             : 
      36           0 :         return points;
      37             : };

Generated by: LCOV version 1.14