@@ -178,18 +178,10 @@ public boolean notOverlaps(UIElement other, Context context) {
178178 Condition .greaterOrEqualTo (getBottom ()).isSatisfiedOn (other .getTop (), context , DOWN );
179179 }
180180
181- private <V extends MetricSpace <V >> V getOffset (ExtendGiving <V > direction , UIElement page , Context context ) {
182- return offset (page , direction ).evaluateIn (context , direction );
183- }
184-
185181 private <V extends MetricSpace <V >> Expression <V > offset (UIElement page , ExtendGiving <V > direction ) {
186182 return Expression .signedDistance (end (direction ), page .end (direction ), direction );
187183 }
188184
189- private Expression <Boolean > equalOppositeOffsets (Direction direction , UIElement page ) {
190- return equalTo (offset (page , direction ), offset (page , direction .opposite ()));
191- }
192-
193185 private boolean hasSuccessor (Direction direction , UIElement possibleSuccessor ) {
194186 return signedDistanceToSuccessor (direction , possibleSuccessor ).isGreaterOrEqualTo (scalar (0 ));
195187 }
@@ -380,14 +372,15 @@ public void validateBottomOffset(Condition condition, UIElement page, Context co
380372 }
381373
382374 public void validateOffset (Direction direction , Condition condition , UIElement page , Context context ) {
383- if (!getOffset (direction , page , context ).satisfies (condition , context , direction )) {
375+ Expression <Scalar > offset = offset (page , direction );
376+ if (!offset .evaluateIn (context , direction ).satisfies (condition , context , direction )) {
384377 context .add (
385378 String .format ("Expected %s offset of element %s to be %s. Actual %s offset is: %s" ,
386379 direction .endName (),
387380 getQuotedName (),
388381 condition .getDescription (context , direction ),
389382 direction .endName (),
390- getOffset ( direction , page , context ).toStringWithUnits (PIXELS )));
383+ offset . evaluateIn ( context , direction ).toStringWithUnits (PIXELS )));
391384 }
392385 }
393386
@@ -401,16 +394,18 @@ public void validateCenteredOnHorizontally(UIElement page, Context context) {
401394
402395 private void validateCentered (Direction direction , UIElement page , Context context ) {
403396 Direction opposite = direction .opposite ();
404- Expression <Boolean > expression = equalOppositeOffsets (direction , page );
397+ Expression <Scalar > offset = offset (page , direction );
398+ Expression <Scalar > oppositeOffset = offset (page , opposite );
399+ Expression <Boolean > expression = equalTo (offset , oppositeOffset );
405400 if (!expression .evaluateIn (context , direction )) {
406401 context .add (String .format ("Element %s has not equal %s and %s offset. %s offset is %s, %s is %s" ,
407402 getQuotedName (),
408403 opposite .endName (),
409404 direction .endName (),
410405 capitalize (opposite .endName ()),
411- getOffset ( opposite , page , context ).toStringWithUnits (PIXELS ),
406+ oppositeOffset . evaluateIn ( context , opposite ).toStringWithUnits (PIXELS ),
412407 direction .endName (),
413- getOffset ( direction , page , context ).toStringWithUnits (PIXELS )));
408+ offset . evaluateIn ( context , direction ).toStringWithUnits (PIXELS )));
414409 context .draw (this );
415410 }
416411 }
0 commit comments