Class LocationUtils
java.lang.Object
io.github.jspinak.brobot.util.location.LocationUtils
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 supportgetOpposite(): Find opposite point within regionsetFromCenter(): Position based on angle and distanceadjustToRegion(): Ensure location stays within boundsadd(): 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd one location to anotherstatic voidadjustToRegion(Location location) Adjust location to be within region boundsstatic ObjectCollectionasObjectCollection(Location location) Create an ObjectCollectionstatic StateLocationasStateLocationInNullState(Location location) Create a StateLocation in null statestatic booleanCheck if two locations are equalstatic LocationgetOpposite(Location location) Get the opposite locationstatic LocationgetOppositeTo(Location location, Location otherLocation) Get the location opposite to another locationstatic intgetRegionH(Location location) Get region heightstatic intgetRegionW(Location location) Get region widthstatic org.sikuli.script.LocationgetSikuliLocation(Location location) Get Sikuli Location based on definition type (by XY or by Region)static org.sikuli.script.LocationgetSikuliLocationFromRegion(Region region, Position position, int offsetX, int offsetY) Get a Sikuli Location from a region and positionstatic org.sikuli.script.LocationgetSikuliLocationFromXY(int x, int y, int offsetX, int offsetY) Get a Sikuli Location from x,y coordinatesstatic booleanCheck if location is definedstatic booleanisDefinedByXY(Location location) Check if location is defined by x,y coordinatesstatic booleanisDefinedWithRegion(Location location) Check if location is defined with a regionstatic voidPrint locationstatic voidsetFromCenter(Location location, double angle, double distance) Set location based on angle and distance from centerstatic MatchConvert location to matchstatic StringGet string representation of location
-
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
Get Sikuli Location based on definition type (by XY or by Region) -
isDefinedByXY
Check if location is defined by x,y coordinates -
isDefinedWithRegion
Check if location is defined with a region -
getRegionW
Get region width -
getRegionH
Get region height -
isDefined
Check if location is defined -
toMatch
Convert location to match -
asStateLocationInNullState
Create a StateLocation in null state -
asObjectCollection
Create an ObjectCollection -
getOpposite
Get the opposite location -
getOppositeTo
Get the location opposite to another location -
adjustToRegion
Adjust location to be within region bounds -
setFromCenter
Set location based on angle and distance from center -
equals
Check if two locations are equal -
add
Add one location to another -
print
Print location -
toString
Get string representation of location
-