/** * Constructor for class DistanceComparator. * @param location Location for comparison */ public DistanceComparator(Location location) { this.x = location.getX(); this.y = location.getY(); }
@Override public void smoothMove(Location src, Location dest, long duration) { if (duration <= 0) { mouseMove(dest.getX(), dest.getY()); return; } float x = src.getX(); float y = src.getY(); float dx = dest.getX() - src.getX(); float dy = dest.getY() - src.getY(); long start = System.currentTimeMillis(); long elapsed = 0; do { float fraction = (float) elapsed / (float) duration; mouseMove((int) (x + fraction * dx), (int) (y + fraction * dy)); delay(autoDelay); elapsed = System.currentTimeMillis() - start; } while (elapsed < duration); mouseMove(dest.x, dest.y); }
/** * Constructor for class DistanceComparator. * @param region Region for comparison */ public DistanceComparator(Region region) { this.x = region.getCenter().getX(); this.y = region.getCenter().getY(); }
/** * getCoords returns a list of coordinates of all the matches found for the element specified * @param targetImgPath is the image of the element that you want to find * @return list of coordinates of the matches found for the element specified */ public List<Point2D> getCoordsForAllMatchingElements(String targetImgPath) { Finder f = new Finder(takeScreenshot()); List<Point2D> coordsList = new ArrayList<>(); Match m; f.findAll(targetImgPath); while (f.hasNext()) { m = f.next(); coordsList.add(new Point2D.Double(m.getTarget().getX(), m.getTarget().getY())); } return coordsList; }
public Point2D getCoords(BufferedImage baseImg, String targetImgPath, double minSimilarityValue) { //set new minimum similarity Settings.MinSimilarity = minSimilarityValue; Match m; Finder f = new Finder(baseImg); Point2D coords = new Point2D.Double(-1, -1); f.find(targetImgPath); if (f.hasNext()) { m = f.next(); coords.setLocation(m.getTarget().getX(), m.getTarget().getY()); } //revert to default similarity Settings.MinSimilarity = DEFAULT_MIN_SIMILARITY; return coords; }
/** * getCoords returns the coordinates of the FIRST element that matches the specified * @param baseImg is the screenshot of the device * @param targetImgPath is the image of the element that you want to find * @return coordinates of the centre of the element found as Point2D */ public Point2D getCoords(BufferedImage baseImg, String targetImgPath) { Match m; Finder f = new Finder(baseImg); Point2D coords = new Point2D.Double(-1, -1); f.find(targetImgPath); if (f.hasNext()) { m = f.next(); coords.setLocation(m.getTarget().getX(), m.getTarget().getY()); } return coords; }