Line data Source code
1 : /** 2 : * HeightPlacer constants determining whether the extrema should be included by the placer too. 3 : */ 4 6 : const Elevation_ExcludeMin_ExcludeMax = 0; 5 6 : const Elevation_IncludeMin_ExcludeMax = 1; 6 6 : const Elevation_ExcludeMin_IncludeMax = 2; 7 6 : const Elevation_IncludeMin_IncludeMax = 3; 8 : 9 : /** 10 : * The HeightPlacer provides all points between the minimum and maximum elevation that meet the Constraint, 11 : * even if they are far from the passable area of the map. 12 : */ 13 : function HeightPlacer(mode, minElevation, maxElevation) 14 : { 15 0 : this.withinHeightRange = 16 0 : mode == Elevation_ExcludeMin_ExcludeMax ? position => g_Map.getHeight(position) > minElevation && g_Map.getHeight(position) < maxElevation : 17 0 : mode == Elevation_IncludeMin_ExcludeMax ? position => g_Map.getHeight(position) >= minElevation && g_Map.getHeight(position) < maxElevation : 18 0 : mode == Elevation_ExcludeMin_IncludeMax ? position => g_Map.getHeight(position) > minElevation && g_Map.getHeight(position) <= maxElevation : 19 0 : mode == Elevation_IncludeMin_IncludeMax ? position => g_Map.getHeight(position) >= minElevation && g_Map.getHeight(position) <= maxElevation : 20 : undefined; 21 : 22 0 : if (!this.withinHeightRange) 23 0 : throw new Error("Invalid HeightPlacer mode: " + mode); 24 : } 25 : 26 6 : HeightPlacer.prototype.place = function(constraint) 27 : { 28 0 : let mapSize = g_Map.getSize(); 29 : 30 0 : return getPointsInBoundingBox(getBoundingBox([new Vector2D(0, 0), new Vector2D(mapSize - 1, mapSize - 1)])).filter( 31 0 : point => this.withinHeightRange(point) && constraint.allows(point)); 32 : };