Skip to content

Commit a69d5f6

Browse files
committed
composite directions
1 parent e1dda03 commit a69d5f6

File tree

2 files changed

+52
-36
lines changed

2 files changed

+52
-36
lines changed

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

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,14 @@
44
import org.openqa.selenium.Point;
55
import org.openqa.selenium.WebElement;
66

7-
import java.util.function.Function;
7+
import static net.itarray.automotion.internal.geometry.Direction.DOWN;
8+
import static net.itarray.automotion.internal.geometry.Direction.RIGHT;
89

910
public class Rectangle {
1011
private final Vector origin;
1112
private final Vector corner;
1213

13-
public static final ExtendGiving<Vector> ORIGIN_CORNER = new ExtendGiving<Vector>() {
14-
@Override
15-
public String extendName() {
16-
return "size";
17-
}
18-
19-
@Override
20-
public String beginName() {
21-
return "top left";
22-
}
23-
24-
@Override
25-
public String endName() {
26-
return "bottom right";
27-
}
28-
29-
@Override
30-
public Vector begin(Rectangle rectangle) {
31-
return rectangle.getOrigin();
32-
}
33-
34-
@Override
35-
public Vector end(Rectangle rectangle) {
36-
return rectangle.getCorner();
37-
}
38-
39-
@Override
40-
public Function<Vector, Vector> transform() {
41-
return v -> v;
42-
}
43-
};
44-
45-
14+
public static final ExtendGiving<Vector> ORIGIN_CORNER = new VectorExtendGiving(RIGHT, DOWN);
4615

4716
public static Rectangle rectangle(WebElement webElement) {
4817
Point location = webElement.getLocation();
@@ -77,7 +46,7 @@ public boolean intersects(Direction direction, Rectangle other) {
7746
}
7847

7948
public boolean intersects(Rectangle other) {
80-
return intersects(Direction.RIGHT, other) && intersects(Direction.DOWN, other);
49+
return intersects(RIGHT, other) && intersects(DOWN, other);
8150
}
8251

8352
public boolean contains(Direction direction, Rectangle other) {
@@ -86,12 +55,13 @@ public boolean contains(Direction direction, Rectangle other) {
8655
}
8756

8857
public boolean contains(Rectangle other) {
89-
return contains(Direction.RIGHT, other) && contains(Direction.DOWN, other);
58+
return contains(RIGHT, other) && contains(DOWN, other);
9059
}
9160

9261
@Override
9362
public String toString() {
9463
Vector extend = corner.minus(origin);
9564
return String.format("[(%s,%s) - %sx%s]", origin.getX(), origin.getY(), extend.getX(), extend.getY());
9665
}
66+
9767
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package net.itarray.automotion.internal.geometry;
2+
3+
import java.util.function.Function;
4+
5+
import static java.lang.String.format;
6+
7+
public class VectorExtendGiving implements ExtendGiving<Vector> {
8+
9+
private final Direction x;
10+
private final Direction y;
11+
12+
public VectorExtendGiving(Direction x, Direction y) {
13+
this.x = x;
14+
this.y = y;
15+
}
16+
17+
@Override
18+
public String extendName() {
19+
return "size";
20+
}
21+
22+
@Override
23+
public String beginName() {
24+
return format("%s %s", x.beginName(), y.beginName());
25+
}
26+
27+
@Override
28+
public String endName() {
29+
return format("%s %s", x.endName(), y.endName());
30+
}
31+
32+
@Override
33+
public Vector begin(Rectangle rectangle) {
34+
return new Vector(x.begin(rectangle), y.begin(rectangle));
35+
}
36+
37+
@Override
38+
public Vector end(Rectangle rectangle) {
39+
return new Vector(x.end(rectangle), y.end(rectangle));
40+
}
41+
42+
@Override
43+
public Function<Vector, Vector> transform() {
44+
return v -> new Vector(x.transform().apply(v), y.transform().apply(v));
45+
}
46+
}

0 commit comments

Comments
 (0)