Zone
The Zone class acts as a wrapper for a Shape, providing additional utilities and simplifying the use of generics associated with the Shape class. Zones enable your robot to perform specific actions or behave in certain ways when its position meets predefined requirements. Each zone is based on a single parent shape.
Zone Behavior
You can customize a zone's behavior by overloading the following methods:
onEnter(Voyager): Executed once when the robot enters the zone. It will not be executed again until the robot leaves and re-enters the zone.onExit(Voyager): Executed when the robot exits the zone.whileInside(Voyager): Executed every time Pathfinder'stick()method is called while the robot is inside the zone.
Constructors
Zone(Shape<?> shape, Runnable onEnter, Runnable onExit, Runnable whileInside): Creates aZonebased on aShape, with specifiedRunnableactions for entering, exiting, and being inside the zone.Zone(Shape<?> shape): Creates aZonebased on aShapewithout any predefined actions for entering, exiting, or being inside the zone.
Static Methods
inflate(Zone zone, double inflationRadius): Creates a newZoneby expanding the given zone's shape by a specifiedinflationRadius. The new zone inherits theonEnter,onExit, andwhileInsidebehaviors of the original zone.inflate(List<Zone> zones, double inflationRadius): Inflates a list of zones by a specifiedinflationRadius, returning a new list of inflated zones.
Instance Methods
getShape(): Returns the underlyingShapeof the zone.isPointInShape(PointXY point): Checks if a givenPointXYis contained within the zone's parent shape.isPointOutsideOfShape(PointXY point): Checks if a givenPointXYis not contained within the zone's parent shape.doesCollideWith(Zone zone): Checks if this zone collides with anotherZone.doesCollideWith(Shape<?> shape): Checks if this zone collides with a givenShape.onEnter(Voyager voyager): Executes theonEnteraction defined for this zone.onExit(Voyager voyager): Executes theonExitaction defined for this zone.whileInside(Voyager voyager): Executes thewhileInsideaction defined for this zone.isSolid(): Indicates whether the zone is considered "solid." Currently, this always returnstruebut is intended for future implementation.