LCOV - code coverage report
Current view: top level - maps/random/rmgen/placer/centered - DiskPlacer.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 19 19 100.0 %
Date: 2023-04-02 12:52:40 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Returns all points on a disk at the given location that meet the constraint.
       3             :  */
       4             : function DiskPlacer(radius, centerPosition = undefined)
       5             : {
       6           7 :         this.radiusSquared = Math.square(radius);
       7           7 :         this.radius = radius;
       8           7 :         this.centerPosition = undefined;
       9             : 
      10           7 :         if (centerPosition)
      11           7 :                 this.setCenterPosition(centerPosition);
      12             : }
      13             : 
      14           6 : DiskPlacer.prototype.setCenterPosition = function(position)
      15             : {
      16           7 :         this.centerPosition = deepfreeze(position.clone().round());
      17             : };
      18             : 
      19           6 : DiskPlacer.prototype.place = function(constraint)
      20             : {
      21           7 :         let points = [];
      22             : 
      23           7 :         const xMin = Math.floor(Math.max(0, this.centerPosition.x - this.radius));
      24           7 :         const yMin = Math.floor(Math.max(0, this.centerPosition.y - this.radius));
      25           7 :         const xMax = Math.ceil(Math.min(g_Map.getSize() - 1, this.centerPosition.x + this.radius));
      26           7 :         const yMax = Math.ceil(Math.min(g_Map.getSize() - 1, this.centerPosition.y + this.radius));
      27             : 
      28           7 :         let it = new Vector2D();
      29           7 :         for (it.x = xMin; it.x <= xMax; ++it.x)
      30         220 :                 for (it.y = yMin; it.y <= yMax; ++it.y)
      31             :                 {
      32       31228 :                         if (this.centerPosition.distanceToSquared(it) <= this.radiusSquared && constraint.allows(it))
      33       23889 :                                 points.push(it.clone());
      34             :                 }
      35             : 
      36           7 :         return points;
      37             : };

Generated by: LCOV version 1.14