ZoneProcessor
A ZoneProcessor is responsible for managing and interacting with Zone objects. It allows your robot to automatically perform actions when it enters, exits, or is inside specific areas defined by zones.
Operation
The ZoneProcessor is operated by calling its update(Voyager) method. This method should be passed the current Voyager instance, and it will handle the logic for triggering zone-related actions.
Zone Event Handling
When update(Voyager) is called, the ZoneProcessor determines the robot's current position relative to all registered zones and triggers the appropriate methods:
onEnter(Voyager): If the robot has entered a zone (was previously outside and is now inside), the zone'sonEntermethod will be called.onExit(Voyager): If the robot has exited a zone (was previously inside and is now outside), the zone'sonExitmethod will be called.whileInside(Voyager): If the robot is currently inside a zone, the zone'swhileInsidemethod will be called. This occurs every timeupdate()is invoked while the robot remains within the zone.
Constructor
ZoneProcessor(): Creates a newZoneProcessorinstance.
Static Methods
getEnteredZones(List<Zone> last, List<Zone> current): (Private) Returns a list of zones that the robot has entered by comparing the previous and current lists of containing zones.getExitedZones(List<Zone> last, List<Zone> current): (Private) Returns a list of zones that the robot has exited by comparing the previous and current lists of containing zones.
Instance Methods
addZone(String name, Zone zone): Adds aZoneto the processor's collection. Each zone must have a unique, non-null name.removeZone(String name): Removes a zone from the processor's collection based on its name.getContainingZones(PointXY point): Returns a list of zones that contain the providedPointXY.getNonContainingZones(PointXY point): Returns a list of zones that do not contain the providedPointXY.update(Voyager voyager): The primary method for updating theZoneProcessor. It takes the currentVoyagerinstance, determines the robot's position, and triggers theonEnter,onExit, andwhileInsidemethods of relevant zones.