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 7 : EntitiesObstructionPlacer.prototype.place = function(constraint)
13 : {
14 0 : let points = [];
15 :
16 0 : for (const entity of this.entities)
17 : {
18 0 : const halfObstructionSize = getObstructionSize(entity.templateName, this.margin).div(2);
19 :
20 0 : const 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 : };
|