Skip to content

Commit 4dc589c

Browse files
committed
tolerance for doNotOverlap
1 parent 0fabb9d commit 4dc589c

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private void validateElementsAreNotOverlapped(List<UIElement> elements) {
278278
UIElement first = elements.get(firstIndex);
279279
for (int secondIndex = firstIndex+1; secondIndex < elements.size(); secondIndex++) {
280280
UIElement second = elements.get(secondIndex);
281-
if (first.overlaps(second)) {
281+
if (first.overlaps(second, getContext())) {
282282
errors.add("Elements are overlapped");
283283
errors.draw(first);
284284
break;

src/main/java/net/itarray/automotion/internal/UIElement.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,27 @@ public boolean hasSameSizeAs(UIElement other, Context context) {
148148
return hasEqualExtendAs(other, Rectangle.ORIGIN_CORNER, context);
149149
}
150150

151-
public boolean overlaps(UIElement other) {
152-
return rectangle.intersects(other.rectangle);
151+
public Scalar getLeft() {
152+
return getOrigin().getX();
153+
}
154+
155+
public Scalar getRight() {
156+
return getCorner().getX();
157+
}
158+
159+
public Scalar getTop() {
160+
return getOrigin().getY();
161+
}
162+
163+
public Scalar getBottom() {
164+
return getCorner().getY();
165+
}
166+
167+
public boolean overlaps(UIElement other, Context context) {
168+
return Condition.lessThan(other.getRight()).isSatisfiedOn(getLeft(), context, RIGHT) &&
169+
Condition.lessThan(getRight()).isSatisfiedOn(other.getLeft(), context, RIGHT) &&
170+
Condition.lessThan(other.getBottom()).isSatisfiedOn(getTop(), context, DOWN) &&
171+
Condition.lessThan(getBottom()).isSatisfiedOn(other.getTop(), context, DOWN);
153172
}
154173

155174
public Scalar getOffset(Direction direction, UIElement page) {
@@ -305,17 +324,17 @@ public void validateSuccessor(Direction direction, UIElement toBeValidatedSucces
305324
}
306325
}
307326

308-
public void validateOverlappingWithElement(UIElement element, Errors errors) {
309-
if (!overlaps(element)) {
327+
public void validateOverlappingWithElement(UIElement element, Context context, Errors errors) {
328+
if (!overlaps(element, context)) {
310329
errors.add(String.format("Element %s is not overlapped with element %s but should be",
311330
getQuotedName(),
312331
element.getQuotedName()));
313332
errors.draw(element);
314333
}
315334
}
316335

317-
public void validateNotOverlappingWithElement(UIElement element, Errors errors) {
318-
if (overlaps(element)) {
336+
public void validateNotOverlappingWithElement(UIElement element, Context context, Errors errors) {
337+
if (overlaps(element, context)) {
319338
errors.add(String.format("Element %s is overlapped with element %s but should not",
320339
getQuotedName(),
321340
element.getQuotedName()));

src/main/java/net/itarray/automotion/internal/UIValidatorBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public UIValidatorBase isAbove(WebElement element, Condition<Scalar> distanceCon
154154
*/
155155
@Override
156156
public UIValidatorBase isNotOverlapping(WebElement element, String readableName) {
157-
rootElement.validateNotOverlappingWithElement(asElement(element, readableName), errors);
157+
rootElement.validateNotOverlappingWithElement(asElement(element, readableName), getContext(), errors);
158158
return this;
159159
}
160160

@@ -167,7 +167,7 @@ public UIValidatorBase isNotOverlapping(WebElement element, String readableName)
167167
*/
168168
@Override
169169
public UIValidatorBase isOverlapping(WebElement element, String readableName) {
170-
rootElement.validateOverlappingWithElement(asElement(element, readableName), errors);
170+
rootElement.validateOverlappingWithElement(asElement(element, readableName), getContext(), errors);
171171
return this;
172172
}
173173

@@ -180,7 +180,7 @@ public UIValidatorBase isOverlapping(WebElement element, String readableName) {
180180
@Override
181181
public UIValidatorBase isNotOverlapping(List<WebElement> elements) {
182182
for (WebElement element : elements) {
183-
rootElement.validateNotOverlappingWithElement(asElement(element), errors);
183+
rootElement.validateNotOverlappingWithElement(asElement(element), getContext(), errors);
184184
}
185185
return this;
186186
}

src/main/java/net/itarray/automotion/validation/ChunkUIElementValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public interface ChunkUIElementValidator {
105105
})
106106
ChunkUIElementValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize);
107107

108-
ChunkUIElementValidator doNotOverlap(); // tolerance
108+
ChunkUIElementValidator doNotOverlap();
109109

110110
ChunkUIElementValidator areInsideOf(WebElement containerElement, String readableContainerName);
111111

0 commit comments

Comments
 (0)