File-By-File
ZoneProcessor

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's onEnter method will be called.
  • onExit(Voyager): If the robot has exited a zone (was previously inside and is now outside), the zone's onExit method will be called.
  • whileInside(Voyager): If the robot is currently inside a zone, the zone's whileInside method will be called. This occurs every time update() is invoked while the robot remains within the zone.

Constructor

  • ZoneProcessor(): Creates a new ZoneProcessor instance.

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 a Zone to 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 provided PointXY.
  • getNonContainingZones(PointXY point): Returns a list of zones that do not contain the provided PointXY.
  • update(Voyager voyager): The primary method for updating the ZoneProcessor. It takes the current Voyager instance, determines the robot's position, and triggers the onEnter, onExit, and whileInside methods of relevant zones.