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

          Line data    Source code
       1             : /**
       2             :  * The EntityObstructionPlacer returns all points on the obstruction of the given template at the given position and angle that meet the constraint.
       3             :  * It can be used for more concise collision avoidance.
       4             :  */
       5             : function EntitiesObstructionPlacer(entities, margin = 0, failFraction = Infinity)
       6             : {
       7           0 :         this.entities = entities;
       8           0 :         this.margin = margin;
       9           0 :         this.failFraction = failFraction;
      10             : }
      11             : 
      12           6 : EntitiesObstructionPlacer.prototype.place = function(constraint)
      13             : {
      14           0 :         let points = [];
      15             : 
      16           0 :         for (let entity of this.entities)
      17             :         {
      18           0 :                 let halfObstructionSize = getObstructionSize(entity.templateName, this.margin).div(2);
      19             : 
      20           0 :                 let obstructionCorners = [
      21             :                         new Vector2D(-halfObstructionSize.x, -halfObstructionSize.y),
      22             :                         new Vector2D(-halfObstructionSize.x, +halfObstructionSize.y),
      23             :                         new Vector2D(+halfObstructionSize.x, -halfObstructionSize.y),
      24             :                         new Vector2D(+halfObstructionSize.x, +halfObstructionSize.y)
      25           0 :                 ].map(corner => Vector2D.add(entity.GetPosition2D(), corner.rotate(-entity.rotation.y)));
      26             : 
      27           0 :                 points = points.concat(new ConvexPolygonPlacer(obstructionCorners, this.failFraction).place(constraint));
      28             :         }
      29             : 
      30           0 :         return points;
      31             : };

Generated by: LCOV version 1.14