LCOV - code coverage report
Current view: top level - maps/random/rmgen/placer/noncentered - RandomPathPlacer.js (source / functions) Coverage Total Hit
Test: lcov.info Lines: 5.9 % 17 1
Test Date: 2026-11-22 03:02:19 Functions: 0.0 % 3 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            7 : RandomPathPlacer.prototype.place = function(constraint)
      17              : {
      18            0 :         let pathLength = 0;
      19            0 :         const points = [];
      20            0 :         const 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 (const 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 2.0-1