Class LocationUtils

java.lang.Object
io.github.jspinak.brobot.util.location.LocationUtils

public class LocationUtils extends Object
Comprehensive utility methods for Location manipulation and calculations in Brobot.

LocationUtils provides a rich set of static methods for working with Location objects, supporting both absolute (x,y) and relative (region-based) location representations. These utilities handle conversions, calculations, and transformations while maintaining the dual nature of Location objects in the framework.

Operation categories:

  • Conversions: Transform between Brobot and SikuliX location representations
  • Type Checking: Determine if locations are absolute or relative
  • Calculations: Geometric operations like opposites, additions, angles
  • Transformations: Convert locations to matches, state objects, collections
  • Utilities: Validation, comparison, string representation

Location type handling:

  • Absolute (XY): Defined by x,y coordinates directly
  • Relative (Region): Defined by position within a region
  • Methods adapt behavior based on location type
  • Supports conversion between types when needed

Key operations:

  • getSikuliLocation(): Convert to SikuliX format with offset support
  • getOpposite(): Find opposite point within region
  • setFromCenter(): Position based on angle and distance
  • adjustToRegion(): Ensure location stays within bounds
  • add(): Combine locations with type awareness

Integration features:

  • Creates StateLocation objects for state-based operations
  • Generates ObjectCollections for action execution
  • Converts to Match objects for result compatibility
  • Supports null state operations for stateless contexts

Geometric calculations:

  • Polar coordinate support (angle/distance from center)
  • Opposite point calculations (reflection)
  • Vector addition with type-aware semantics
  • Boundary enforcement for relative locations

In the model-based approach, LocationUtils enables sophisticated spatial reasoning about point locations while abstracting the complexity of dual representation modes. This flexibility allows the framework to work efficiently with both fixed screen coordinates and adaptive region-based positions.

Since:
1.0
See Also:
  • Constructor Details

    • LocationUtils

      public LocationUtils()
  • Method Details

    • getSikuliLocationFromXY

      public static org.sikuli.script.Location getSikuliLocationFromXY(int x, int y, int offsetX, int offsetY)
      Get a Sikuli Location from x,y coordinates
    • getSikuliLocationFromRegion

      public static org.sikuli.script.Location getSikuliLocationFromRegion(Region region, Position position, int offsetX, int offsetY)
      Get a Sikuli Location from a region and position
    • getSikuliLocation

      public static org.sikuli.script.Location getSikuliLocation(Location location)
      Get Sikuli Location based on definition type (by XY or by Region)
    • isDefinedByXY

      public static boolean isDefinedByXY(Location location)
      Check if location is defined by x,y coordinates
    • isDefinedWithRegion

      public static boolean isDefinedWithRegion(Location location)
      Check if location is defined with a region
    • getRegionW

      public static int getRegionW(Location location)
      Get region width
    • getRegionH

      public static int getRegionH(Location location)
      Get region height
    • isDefined

      public static boolean isDefined(Location location)
      Check if location is defined
    • toMatch

      public static Match toMatch(Location location)
      Convert location to match
    • asStateLocationInNullState

      public static StateLocation asStateLocationInNullState(Location location)
      Create a StateLocation in null state
    • asObjectCollection

      public static ObjectCollection asObjectCollection(Location location)
      Create an ObjectCollection
    • getOpposite

      public static Location getOpposite(Location location)
      Get the opposite location
    • getOppositeTo

      public static Location getOppositeTo(Location location, Location otherLocation)
      Get the location opposite to another location
    • adjustToRegion

      public static void adjustToRegion(Location location)
      Adjust location to be within region bounds
    • setFromCenter

      public static void setFromCenter(Location location, double angle, double distance)
      Set location based on angle and distance from center
    • equals

      public static boolean equals(Location location1, Location location2)
      Check if two locations are equal
    • add

      public static void add(Location location, Location locationToAdd)
      Add one location to another
    • print

      public static void print(Location location)
      Print location
    • toString

      public static String toString(Location location)
      Get string representation of location