Class MapTools
public class MapTools
extends java.lang.Object
Unless you're really interested in exactly HOW Pathfinder works, you can entirely ignore this file. The only method that does anything you need to be concerned with is the getCells() method.
This, like much of the other code in the revamped version of Pathfinder, is a little bit outdated and purposeless. If you have the time to, it would be (very greatly) appreciated if you could go through this file, clean everything up a bit, and maybe add a little bit of that oh-so-sexy documentation you love to see.
- Since:
- 0.1.0
- Author:
- Colin Robertson
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MapTools.Area
Class used for representing the area of a zone. -
Constructor Summary
Constructors Constructor Description MapTools()
-
Method Summary
Modifier and Type Method Description static org.xguzm.pathfinding.grid.GridCell[][]
createCells(Map map, int sizeX, int sizeY, int specificity)
Create a new two-dimensional array of GridCell elements based on a provided field map.static Circle
createNewCircle(Zone zone, double width, double height)
Create a new circle.static Rectangle
createNewRectangle(Zone zone, double width, double height)
Create a new rectangle based on an old zone and the robot's size.static Zone
createNewZone(Zone zone, Shape shape)
Create a new zone based on a previous zone and a new shape.static org.xguzm.pathfinding.grid.GridCell[][]
createSmallCells(Map map, int minX, int minY, int maxX, int maxY, int scale)
Create a (much smaller) two-dimensional array of grid cells for use in finding a single path.static org.xguzm.pathfinding.grid.GridCell[][]
getCells(Map map, int fieldX, int fieldY, int fieldSpecificity, double robotX, double robotY)
Get a 2d GridCell array based on an inputted map.static org.xguzm.pathfinding.grid.GridCell[][]
getSmallCells(Map map, int minX, int minY, int maxX, int maxY, int scale, double rX, double rY)
Get a 2d array of cells based on several inputted parameters.static me.wobblyyyy.edt.DynamicArray<Zone>
getZonesInArea(Map map, MapTools.Area area)
Get a list of all of the zones contained in an area.static boolean
isAreaEmpty(Map map, MapTools.Area area)
Is a given area completely void of any zones?static Map
scaleMap(Map map, double length, double width)
Scale a map so that the zones are compatible with the pathfinder.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
MapTools
public MapTools()
-
-
Method Details
-
scaleMap
Scale a map so that the zones are compatible with the pathfinder.By default, zones are... well, their normal sizes. However, if we were to use the pathfinding system with these normally-sized zones, we'd run into tons upon tons of different collisions. By scaling the zones up so that they can't possibly touch the robot, we prevent these collisions, which, is, in fact, pretty darn cool.
- Parameters:
map
- the original map.length
- the robot's LENGTH.width
- the robot's WIDTH.- Returns:
- a new map with scaled zones.
-
createSmallCells
public static org.xguzm.pathfinding.grid.GridCell[][] createSmallCells(Map map, int minX, int minY, int maxX, int maxY, int scale)Create a (much smaller) two-dimensional array of grid cells for use in finding a single path.- Parameters:
map
- the field's map.minX
- the path's minimum X value.minY
- the path's minimum Y value.maxX
- the path's maximum X value.maxY
- the path's maximum Y value.scale
- the field's scale/specificity.- Returns:
- a two-dimensional array for use in a navigation grid.
-
createCells
public static org.xguzm.pathfinding.grid.GridCell[][] createCells(Map map, int sizeX, int sizeY, int specificity)Create a new two-dimensional array of GridCell elements based on a provided field map.- Parameters:
map
- a map of the field. Note that this map MUST be properly scaled prior to this method - if the map isn't properly scaled, you're not gonna get the results you want.sizeX
- the field's X dimension (array size).sizeY
- the field's Y dimension (array size).specificity
- the field's integer scale factor.- Returns:
- a two-dimensional array of grid cells representing the map.
-
getCells
public static org.xguzm.pathfinding.grid.GridCell[][] getCells(Map map, int fieldX, int fieldY, int fieldSpecificity, double robotX, double robotY)Get a 2d GridCell array based on an inputted map.- Parameters:
map
- an inputted field map.fieldX
- the X size of the cell array.fieldY
- the Y size of the cell array.fieldSpecificity
- the field's specific scalar factor.robotX
- the robot's X size. X/Y are the same here.robotY
- the robot's Y size. X/Y are the same here.- Returns:
- a 2d GridCell array representing the field.
-
getSmallCells
public static org.xguzm.pathfinding.grid.GridCell[][] getSmallCells(Map map, int minX, int minY, int maxX, int maxY, int scale, double rX, double rY)Get a 2d array of cells based on several inputted parameters.DISPOSABLE INSTANCE!
- Parameters:
map
- the field's map.minX
- the minimum X value.minY
- the minimum Y value.maxX
- the maximum X value.maxY
- the maximum Y value.scale
- the scale of the field.rX
- robot's X.rY
- robot's Y.- Returns:
- small grid for navigation.
-
createNewZone
Create a new zone based on a previous zone and a new shape.- Parameters:
zone
- the original zone.shape
- the new shape.- Returns:
- the new zone.
-
createNewRectangle
Create a new rectangle based on an old zone and the robot's size.- Parameters:
zone
- the old rectangle zone.width
- the width of the robot.height
- the height of the robot.- Returns:
- a new rectangle.
-
createNewCircle
Create a new circle.- Parameters:
zone
- old zone.width
- robot width.height
- robot height.- Returns:
- new circle.
-
getZonesInArea
Get a list of all of the zones contained in an area.The sampling method behind this is in need of some serious improvement. Simply testing 16 points isn't anywhere near as accurate as testing to see if any of the shapes are or are not inside of the given zone.
- Parameters:
map
- the map to check against. (unscaled)area
- the area to check. (unscaled)- Returns:
- a list of all of the zones inside a given area.
-
isAreaEmpty
Is a given area completely void of any zones?Non-solid zones aren't counted here - for example, the field, which is the largest (and sometimes only) non-solid zone on the field, isn't counted when deciding whether or not a zone is empty.
- Parameters:
map
- the field's map. (unscaled)area
- the area of the field to test. (unscaled)- Returns:
- whether or not the given area is empty.
-