Skip to content

Commit 5f70e5b

Browse files
committed
tolerance for ends
1 parent 178cb5b commit 5f70e5b

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ private static String defaultName(WebElement webElement) {
8686
String.valueOf(size.getHeight()));
8787
}
8888

89-
public Scalar getBegin(Direction direction) {
89+
public <V extends MetricSpace<V>> V getBegin(ExtendGiving<V> direction) {
9090
return direction.begin(rectangle);
9191
}
9292

93-
public Scalar getEnd(Direction direction) {
93+
public <V extends MetricSpace<V>> V getEnd(ExtendGiving<V> direction) {
9494
return direction.end(rectangle);
9595
}
9696

@@ -126,10 +126,6 @@ public Vector getCorner() {
126126
return rectangle.getCorner();
127127
}
128128

129-
private boolean hasEqualEnd(UIElement other, Direction direction) {
130-
return getEnd(direction).equals(other.getEnd(direction));
131-
}
132-
133129
private <V extends MetricSpace<V>> boolean hasEqualExtendAs(UIElement other, ExtendGiving<V> direction, Context context) {
134130
Expression<Boolean> equal = Expression.equalTo(
135131
ElementPropertyExpression.extend(direction, this),
@@ -244,7 +240,11 @@ public void validateBottomAlignedWith(UIElement element, Context context, Errors
244240
}
245241

246242
private void validateEqualEnd(Direction direction, UIElement element, Context context, Errors errors) {
247-
if (!hasEqualEnd(element, direction)) {
243+
boolean valid = Expression.equalTo(
244+
ElementPropertyExpression.end(direction, this),
245+
ElementPropertyExpression.end(direction, element)
246+
).evaluateIn(context, direction);
247+
if (!valid) {
248248
errors.add(String.format("Element %s has not the same %s offset as element %s",
249249
getQuotedName(),
250250
direction.endName(),

src/main/java/net/itarray/automotion/internal/geometry/ExtendGiving.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package net.itarray.automotion.internal.geometry;
22

33
public interface ExtendGiving<V extends MetricSpace<V>> {
4+
String beginName();
5+
String endName();
46
String extendName();
7+
58
V begin(Rectangle rectangle);
69
V end(Rectangle rectangle);
710
default V extend(Rectangle rectangle) {

src/main/java/net/itarray/automotion/internal/geometry/Rectangle.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ public String extendName() {
1414
return "size";
1515
}
1616

17+
@Override
18+
public String beginName() {
19+
return "top left";
20+
}
21+
22+
@Override
23+
public String endName() {
24+
return "bottom right";
25+
}
26+
1727
@Override
1828
public Vector begin(Rectangle rectangle) {
1929
return rectangle.getOrigin();

src/main/java/net/itarray/automotion/internal/properties/ElementPropertyExpression.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public static <V extends MetricSpace<V>> ElementPropertyExpression<V> extend(Ext
2323
" of element %s", direction.extendName());
2424
}
2525

26+
public static <V extends MetricSpace<V>> ElementPropertyExpression<V> end(ExtendGiving<V> direction, UIElement element) {
27+
return new ElementPropertyExpression<>(element, e -> e.getEnd(direction), direction.endName() +
28+
" of element %s", direction.extendName());
29+
}
30+
2631
@Override
2732
public <V extends MetricSpace<V>> T evaluateIn(Context context, ExtendGiving<V> direction) {
2833
return property.evaluateOn(element);

0 commit comments

Comments
 (0)