Skip to content

Commit 99b8fcf

Browse files
committed
integrate OrExpression in notOverlaps
1 parent 1bcb86a commit 99b8fcf

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.itarray.automotion.internal;
1+
package net.itarray.automotion.internal;
22

33
import net.itarray.automotion.internal.geometry.ConnectedIntervals;
44
import net.itarray.automotion.internal.geometry.Interval;
@@ -281,7 +281,7 @@ private void validateElementsAreNotOverlapped(List<UIElement> elements) {
281281
UIElement first = elements.get(firstIndex);
282282
for (int secondIndex = firstIndex+1; secondIndex < elements.size(); secondIndex++) {
283283
UIElement second = elements.get(secondIndex);
284-
if (!first.notOverlaps(second, context)) {
284+
if (!first.doesNotOverlap(second, context)) {
285285
context.add("Elements are overlapped");
286286
context.draw(first);
287287
break;

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,19 @@ public Expression<Boolean> overlaps(UIElement other) {
176176
);
177177
}
178178

179-
public boolean notOverlaps(UIElement other, Context context) {
180-
return Condition.greaterOrEqualTo(other.end(RIGHT)).applyTo(end(LEFT)).evaluateIn(context, RIGHT) ||
181-
Condition.greaterOrEqualTo(end(RIGHT)).applyTo(other.end(LEFT)).evaluateIn(context, RIGHT) ||
182-
Condition.greaterOrEqualTo(other.end(DOWN)).applyTo(end(UP)).evaluateIn(context, DOWN) ||
183-
Condition.greaterOrEqualTo(end(DOWN)).applyTo(other.end(UP)).evaluateIn(context, DOWN);
179+
public boolean doesNotOverlap(UIElement other, Context context) {
180+
return notOverlaps(other).evaluateIn(context, DOWN);
181+
}
182+
183+
public Expression<Boolean> notOverlaps(UIElement other) {
184+
return Expression.or(
185+
Expression.or(
186+
Condition.greaterOrEqualTo(other.end(RIGHT)).applyTo(end(LEFT)),
187+
Condition.greaterOrEqualTo(end(RIGHT)).applyTo(other.end(LEFT))),
188+
Expression.or(
189+
Condition.greaterOrEqualTo(other.end(DOWN)).applyTo(end(UP)),
190+
Condition.greaterOrEqualTo(end(DOWN)).applyTo(other.end(UP)))
191+
);
184192
}
185193

186194
private <V extends MetricSpace<V>> Expression<V> offset(UIElement page, ExtendGiving<V> direction) {
@@ -359,7 +367,7 @@ public void validateOverlappingWithElement(UIElement element, Context context) {
359367
}
360368

361369
public void validateNotOverlappingWithElement(UIElement element, Context context) {
362-
if (!notOverlaps(element, context)) {
370+
if (!notOverlaps(element).evaluateIn(context, DOWN)) {
363371
context.add(String.format("Element %s is overlapped with element %s but should not",
364372
getQuotedName(),
365373
element.getQuotedName()));

0 commit comments

Comments
 (0)