Skip to content

Commit e022a60

Browse files
committed
based validateSuccessor on expression evaluation
1 parent 657c632 commit e022a60

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,24 @@ private <V extends MetricSpace<V>> Expression<V> offset(UIElement page, ExtendGi
183183
return Expression.signedDistance(end(direction), page.end(direction), direction);
184184
}
185185

186+
@Deprecated
186187
private boolean hasSuccessor(Direction direction, UIElement possibleSuccessor) {
187188
return signedDistanceToSuccessor(direction, possibleSuccessor).isGreaterOrEqualTo(scalar(0));
188189
}
189190

191+
@Deprecated
190192
private Scalar signedDistanceToSuccessor(Direction direction, UIElement successor) {
191193
return direction.signedDistance(direction.end(rectangle), direction.begin(successor.rectangle));
192194
}
193195

194196
// todo: used only in PageValidator - no tolerance yet
197+
@Deprecated
195198
public boolean hasRightElement(UIElement rightElement) {
196199
return hasSuccessor(RIGHT, rightElement);
197200
}
198201

199202
// todo: used only in PageValidator - no tolerance yet
203+
@Deprecated
200204
public boolean hasBelowElement(UIElement bottomElement) {
201205
return hasSuccessor(DOWN, bottomElement);
202206
}
@@ -264,6 +268,10 @@ public <V extends MetricSpace<V>> Expression<V> end(ExtendGiving<V> direction) {
264268
return ElementPropertyExpression.end(direction, this);
265269
}
266270

271+
public <V extends MetricSpace<V>> Expression<V> begin(ExtendGiving<V> direction) {
272+
return ElementPropertyExpression.begin(direction, this);
273+
}
274+
267275
public void validateSameSize(UIElement element, Context context) {
268276
validateSameExtend(ORIGIN_CORNER, element, context);
269277
}
@@ -328,7 +336,7 @@ public void validateIsAbove(UIElement element, Condition<Scalar> condition, Cont
328336
}
329337

330338
public void validateSuccessor(Direction direction, UIElement toBeValidatedSuccessor, Condition<Scalar> condition, Context context) {
331-
ConstantExpression<Scalar> signedDistance = new ConstantExpression<>(signedDistanceToSuccessor(direction, toBeValidatedSuccessor));
339+
Expression<Scalar> signedDistance = Expression.signedDistance(end(direction), toBeValidatedSuccessor.begin(direction), direction);
332340
if (!condition.isSatisfiedOn(signedDistance, context, direction)) {
333341
context.add(String.format("%s element aligned not properly. Expected margin should be %s. Actual margin is %s",
334342
direction.afterName(),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public static <V extends MetricSpace<V>> Expression<V> end(ExtendGiving<V> direc
2828
" of element %s", direction.extendName());
2929
}
3030

31+
public static <V extends MetricSpace<V>> Expression<V> begin(ExtendGiving<V> direction, UIElement element) {
32+
return new ElementPropertyExpression<>(element, e -> e.getBegin(direction), direction.beginName() +
33+
" of element %s", direction.extendName());
34+
}
35+
3136
@Override
3237
public <V extends MetricSpace<V>> T evaluateIn(Context context, ExtendGiving<V> direction) {
3338
return property.evaluateOn(element);

0 commit comments

Comments
 (0)