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 void
Add one location to anotherstatic void
adjustToRegion
(Location location) Adjust location to be within region boundsstatic ObjectCollection
asObjectCollection
(Location location) Create an ObjectCollectionstatic StateLocation
asStateLocationInNullState
(Location location) Create a StateLocation in null statestatic boolean
Check if two locations are equalstatic Location
getOpposite
(Location location) Get the opposite locationstatic Location
getOppositeTo
(Location location, Location otherLocation) Get the location opposite to another locationstatic int
getRegionH
(Location location) Get region heightstatic int
getRegionW
(Location location) Get region widthstatic org.sikuli.script.Location
getSikuliLocation
(Location location) Get Sikuli Location based on definition type (by XY or by Region)static org.sikuli.script.Location
getSikuliLocationFromRegion
(Region region, Position position, int offsetX, int offsetY) Get a Sikuli Location from a region and positionstatic org.sikuli.script.Location
getSikuliLocationFromXY
(int x, int y, int offsetX, int offsetY) Get a Sikuli Location from x,y coordinatesstatic boolean
Check if location is definedstatic boolean
isDefinedByXY
(Location location) Check if location is defined by x,y coordinatesstatic boolean
isDefinedWithRegion
(Location location) Check if location is defined with a regionstatic void
Print locationstatic void
setFromCenter
(Location location, double angle, double distance) Set location based on angle and distance from centerstatic Match
Convert location to matchstatic String
Get 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
-