public abstract class BreadthFirstSearch extends java.lang.Object implements Operation
visit(com.sk89q.worldedit.Vector)
. The search continues
to a certain adjacent point provided that the method
isVisitable(com.sk89q.worldedit.Vector, com.sk89q.worldedit.Vector)
returns true for that point.
As an abstract implementation, this class can be used to implement functionality that starts at certain points and extends outward from those points.
Modifier | Constructor and Description |
---|---|
protected |
BreadthFirstSearch(RegionFunction function)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addAxes()
Add the directions along the axes as directions to visit.
|
protected void |
addDiagonal()
Add the diagonal directions as directions to visit.
|
void |
cancel()
Abort the current task.
|
int |
getAffected()
Get the number of affected objects.
|
protected java.util.Collection<Vector> |
getDirections()
Get the list of directions will be visited.
|
protected abstract boolean |
isVisitable(Vector from,
Vector to)
Return whether the given 'to' block should be visited, starting from the
'from' block.
|
Operation |
resume(RunContext run)
Complete the next step.
|
void |
visit(Vector position)
Add the given location to the list of locations to visit, provided
that it has not been visited.
|
protected BreadthFirstSearch(RegionFunction function)
function
- the function to apply to visited blocksprotected java.util.Collection<Vector> getDirections()
Directions are Vector
s that determine
what adjacent points area available. Vectors should not be
unit vectors. An example of a valid direction is
new Vector(1, 0, 1)
.
The list of directions can be cleared.
protected void addAxes()
protected void addDiagonal()
public void visit(Vector position)
isVisitable(com.sk89q.worldedit.Vector, com.sk89q.worldedit.Vector)
.
This method should be used before the search begins, because if the position does fail the test, and the search has already visited it (because it is connected to another root point), the search will mark the position as "visited" and a call to this method will do nothing.
position
- the positionprotected abstract boolean isVisitable(Vector from, Vector to)
from
- the origin blockto
- the block under questionpublic int getAffected()
public Operation resume(RunContext run) throws WorldEditException
Operation
resume
in interface Operation
run
- describes information about the current runWorldEditException
- an errorpublic void cancel()
Operation
Operation.resume(RunContext)
should not be called at any point in the
future. This method should not be called after successful completion of
the operation. This method must be called if the operation is
interrupted before completion.