improved some docks, added default value for getAlmostPoint wiggle
This commit is contained in:
parent
72346ee6e6
commit
99556be92f
@ -14,29 +14,56 @@ import kotlin.random.Random
|
||||
* Classes that implement this can serve as desktop automation controllers.
|
||||
*/
|
||||
interface DesktopController {
|
||||
|
||||
/**
|
||||
* Gets the current pointer/mouse location on the desktop.
|
||||
*
|
||||
* @return The current [Point] location of the mouse pointer.
|
||||
* This returns a [Point] representing the x, y coordinates of the mouse pointer on the screen.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* ```
|
||||
* val mouseLocation = getPointerLocation()
|
||||
*
|
||||
* println(mouseLocation) // Might print "Point[x=1920,y=1080]"
|
||||
* ```
|
||||
*
|
||||
* @return The current [Point] location of the mouse pointer on the screen.
|
||||
*/
|
||||
fun getPointerLocation(): Point {
|
||||
return MouseInfo.getPointerInfo().location
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a "wiggly" point near the given point.
|
||||
* Gets a point near the given [point], with some random wiggle.
|
||||
*
|
||||
* This takes in a target [Point] and [WiggleParams] and returns a new
|
||||
* point that is randomly offset from the target point based on the
|
||||
* wiggle parameters.
|
||||
* This generates a new point that is randomly offset from the given [point]
|
||||
* by an amount controlled by the given [WiggleParams].
|
||||
*
|
||||
* This is useful for adding variance to mouse movements.
|
||||
* Usage example:
|
||||
*
|
||||
* @param point The target point to wiggle around
|
||||
* @param params The wiggle parameters
|
||||
* @return A new [Point] randomly offset from the target point.
|
||||
* ```
|
||||
* val base = Point(10, 20)
|
||||
* val params = WiggleParams(xWiggle = 5, yWiggle = 5)
|
||||
* val randomPoint = getAlmostPoint(base, params)
|
||||
*
|
||||
* // randomPoint might be (8, 22)
|
||||
* ```
|
||||
*
|
||||
* Alternatively, params may be omitted to use the default WiggleParams values
|
||||
* ```
|
||||
* val base = Point(10, 20)
|
||||
* val randomPoint = getAlmostPoint(base)
|
||||
*
|
||||
* // randomPoint might be (8, 22)
|
||||
* ```
|
||||
*
|
||||
* @param point The base point to start from
|
||||
* @param params The wiggle parameters that control the random offset amount
|
||||
* @return A new [Point] near the given point with some random wiggle applied
|
||||
*/
|
||||
fun getAlmostPoint(point: Point, params: WiggleParams): Point {
|
||||
fun getAlmostPoint(point: Point, params: WiggleParams = WiggleParams()): Point {
|
||||
val xDel = Random.nextInt(0, params.xWiggle)
|
||||
val yDel = Random.nextInt(0, params.yWiggle)
|
||||
val xDir = if (Random.nextDouble() > 0.5) {
|
||||
|
||||
@ -19,8 +19,7 @@ class AutomatonTest {
|
||||
@Test
|
||||
fun `Automaton extends DesktopController`() {
|
||||
val automaton = mock(Automaton::class.java)
|
||||
|
||||
verify(automaton).getPointerLocation()
|
||||
verify(automaton).getAlmostPoint(Point(100, 100))
|
||||
// Asserts Automaton extends DesktopController
|
||||
}
|
||||
|
||||
|
||||
@ -66,9 +66,9 @@ internal class TemporalControllerTest {
|
||||
val end = System.currentTimeMillis()
|
||||
val elapsed = end - start
|
||||
|
||||
val lowerBound = duration - variance / 2
|
||||
val upperBound = duration + variance / 2
|
||||
|
||||
val lowerBound = (duration - variance / 2) - 1
|
||||
val upperBound = (duration + variance / 2) + 20
|
||||
println("elapsed: $elapsed, [$lowerBound, $upperBound]")
|
||||
assertTrue(elapsed >= lowerBound)
|
||||
assertTrue(elapsed <= upperBound)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user