@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Point other = (Point) obj; return x == other.getX() && y == other.getY(); } }
/** * Creates Point object by given Point object. Sets the X and Y values to be equal to the parameter's. * * @param point * - a {@link Point} needed for the constructor */ public Point(Point point) { this(point.getX(), point.getY()); }
/** * Adds the given vector to the current one. * * @param aVector * - vector added to the current one. */ public void addVector(Point aVector) { x += aVector.getX(); y += aVector.getY(); }
/** * Subtracts the given vector from the current one. * * @param aVector * - vector subtracted from the current one. */ public void subtractVector(Point aVector) { x -= aVector.getX(); y -= aVector.getY(); }
private static String pointToString(Point point) { return String.format("[%d,%d]", point.getX(), point.getY()); }
/** * Check if a {@link Point} is inside the bounds. * * @param point * - a {@link Point} that needs to be contained in the bounds * @return true if the bounds contain the point, false otherwise */ public boolean contains(Point point) { Point lowerRightCorner = getLowerRightCorner(); boolean containsPointX = point.getX() >= upperLeftCorner.getX() && point.getX() <= lowerRightCorner.getX(); boolean containsPointY = point.getY() >= upperLeftCorner.getY() && point.getY() <= lowerRightCorner.getY(); return containsPointX && containsPointY; }
/** * Gets the given point equivalent relative to the bounds upper left corner. * * @param point * - a {@link Point} for which to get the point equivalent relative to the bounds upper left corner * @return the point equivalent relative to the bounds upper left corner */ public Point getRelativePoint(Point point) { int relativePointX = point.getX() - upperLeftCorner.getX(); int relativePointY = point.getY() - upperLeftCorner.getY(); Point relativePoint = new Point(relativePointX, relativePointY); return relativePoint; }
/** * Calculates the coordinates of a vector with start point A and end point B. * * @param pointA * - start point of the vector. * @param pointB * - end point of the vector. * @return the coordinates of a vector with start point A and end point B. */ public static Point getVector(Point pointA, Point pointB) { int vectorX = pointB.getX() - pointA.getX(); int vectorY = pointB.getY() - pointA.getY(); Point vector = new Point(vectorX, vectorY); return vector; }
/** * Creates new Bounds instance given upper left and lower right corners. * * @param upperLeftCorner * - the upper left corner of the bounds * @param lowerRightCorner * - the lower left corner of the bounds */ public Bounds(Point upperLeftCorner, Point lowerRightCorner) { int calculatedWidth = lowerRightCorner.getX() - upperLeftCorner.getX(); int calculatedHeight = lowerRightCorner.getY() - upperLeftCorner.getY(); this.upperLeftCorner = new Point(upperLeftCorner); this.width = calculatedWidth; this.height = calculatedHeight; }
/** * Gets lower left corner. * * @return the lower left corner of the bounds */ public Point getLowerLeftCorner() { int lowerLeftCornerX = upperLeftCorner.getX(); int lowerLeftCornerY = upperLeftCorner.getY() + height; Point lowerLeftCorner = new Point(lowerLeftCornerX, lowerLeftCornerY); return lowerLeftCorner; }
/** * Returns the 2D distance to another point. * * @param toPoint * - point to calculate distance to. * @return the 2D distance to another point. */ public double distance(Point toPoint) { return distance(toPoint.getX(), toPoint.getY()); }
/** * Gets lower right corner. * * @return the lower right corner of the bounds */ public Point getLowerRightCorner() { int lowerRightCornerX = upperLeftCorner.getX() + width; int lowerRightCornerY = upperLeftCorner.getY() + height; Point lowerRightCorner = new Point(lowerRightCornerX, lowerRightCornerY); return lowerRightCorner; }
/** * Gets upper right corner. * * @return the upper right corner of the bounds */ public Point getUpperRightCorner() { int upperRightCornerX = upperLeftCorner.getX() + width; int upperRightCornerY = upperLeftCorner.getY(); Point upperRightCorner = new Point(upperRightCornerX, upperRightCornerY); return upperRightCorner; }
/** * Gets bounds center. * * @return the center point of the bounds */ public Point getCenter() { int centerX = upperLeftCorner.getX() + width / 2; int centerY = upperLeftCorner.getY() + height / 2; Point center = new Point(centerX, centerY); return center; }
/** * Sets the location of the Point object. * * @param point * - new location for the point. */ public void setLocation(Point point) { setLocation(point.getX(), point.getY()); }
public String constructAttributeSelector(CssAttribute attribute, Object propertyValue) { String propertyStringValue; if (propertyValue instanceof Bounds) { Bounds bounds = (Bounds) propertyValue; Point firstBound = bounds.getUpperLeftCorner(); Point secondBound = bounds.getLowerRightCorner(); propertyStringValue = String.format(BOUNDS_FORMAT, firstBound.getX(), firstBound.getY(), secondBound.getX(), secondBound.getY()); } else { propertyStringValue = propertyValue.toString(); } return String.format(queryString, attribute.getHtmlAttributeName(), propertyStringValue); } }
/** * Check if certain {@link Bounds} parameter is inside the bounds. * * @param bounds * - a {@link Bounds} parameter that needs to be contained in the bounds * @return true if the bounds contain the bounds parameter, false otherwise */ public boolean contains(Bounds bounds) { Point boundsUpperLeftCorner = bounds.getUpperLeftCorner(); int boundsWidth = bounds.getWidth(); int boundsHeight = bounds.getHeight(); boolean containsUpperLeftCorner = contains(boundsUpperLeftCorner); boolean containsWidth = boundsUpperLeftCorner.getX() + boundsWidth <= upperLeftCorner.getX() + width; boolean containsHeight = boundsUpperLeftCorner.getY() + boundsHeight <= upperLeftCorner.getY() + height; return containsUpperLeftCorner && containsWidth && containsHeight; }
/** * Constructs a {@link Timeline} that, when drawn, results in a circular trajectory. * * @param center * - the coordinates of the circle origin (as a {@link Point}) * @param radius * - radius of the circle * @param startTime * - the moment in time at which the first {@link Anchor} should be reached * @param totalDuration * - the total duration of the resulting generated gesture (in milliseconds) * @param inSteps * - amount of {@link Anchor} instances that the generated {@link Timeline} should contain * @return the resulting populated {@link Timeline} instance */ public static Timeline createCircle(Point center, float radius, int startTime, int totalDuration, int inSteps) { final float FULL_RADIANS = (float) (Math.PI * 2.0f); Timeline result = new Timeline(); final float STEP_ANGLE_RAD = FULL_RADIANS / inSteps; final float INSURANCE_ANGLE = 0.2f; for (float rotRad = 0; rotRad < INSURANCE_ANGLE + FULL_RADIANS; rotRad += STEP_ANGLE_RAD) { int x = (int) (center.getX() + Math.cos(rotRad) * radius); int y = (int) (center.getY() + Math.sin(rotRad) * radius); int timeProgress = (int) (totalDuration * (rotRad / FULL_RADIANS)); Anchor point = new Anchor(x, y, startTime + timeProgress); result.add(point); } return result; }
/** * Simulates a pinch in on the element. NOTE emulator devices may not detect pinch gestures on UI elements with size * smaller than 100x100dp. * * @return <code>true</code> if the pinch in is successful, <code>false</code> if it fails * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean pinchIn() { revalidateThrowing(); Bounds elementBounds = propertiesContainer.getBounds(); final int BOUNDS_OFFSET_DENOMINATOR = 10; final int WIDTH_OFFSET = elementBounds.getWidth() / BOUNDS_OFFSET_DENOMINATOR; final int HEIGHT_OFFSET = elementBounds.getHeight() / BOUNDS_OFFSET_DENOMINATOR; // starting the pinch at a distance from the exact bounds of the element so that it will not affect other UI // elements Point lowerRight = elementBounds.getLowerRightCorner(); int firstFingerInitialX = lowerRight.getX() - WIDTH_OFFSET; int firstFingerInitialY = lowerRight.getY() - HEIGHT_OFFSET; Point firstFingerInitial = new Point(firstFingerInitialX, firstFingerInitialY); Point upperLeft = elementBounds.getUpperLeftCorner(); int secondFingerInitialX = upperLeft.getX() + WIDTH_OFFSET; int secondFingerInitialY = upperLeft.getY() + HEIGHT_OFFSET; Point secondFingerInitial = new Point(secondFingerInitialX, secondFingerInitialY); boolean result = (boolean) communicator.sendAction(RoutingAction.GESTURE_PINCH_IN, firstFingerInitial, secondFingerInitial); return result; }
|| (selectorBoundsUpperCorner.getX() != accessibilityNodeBounds.left) || (selectorBoundsUpperCorner.getY() != accessibilityNodeBounds.top)) { return false;