blob: 76203955db33148e21c76768b1dc80e86798d174 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package coffee.liz.ecs.math;
import java.util.function.Function;
/**
* Cartesian vectors.
*
* @param <T>
* the numeric type of vector components
*/
public interface Vec2<T> {
/**
* @return the x coordinate
*/
T getX();
/**
* @return the y coordinate
*/
T getY();
/**
* Adds another vector to this vector.
*
* @param other
* the vector to add
* @return a new vector with the result
*/
Vec2<T> plus(final Vec2<T> other);
/**
* Subtracts another vector from this vector.
*
* @param other
* the vector to subtract
* @return a new vector with the result
*/
Vec2<T> minus(final Vec2<T> other);
/**
* Scales this vector by the given factors.
*
* @param scaleX
* the x scale factor
* @param scaleY
* the y scale factor
* @return a new scaled vector
*/
Vec2<T> scale(final T scaleX, final T scaleY);
/**
* Scales this vector by the given vector.
*
* @param scale
* scale vec.
* @return a new scaled vector
*/
default Vec2<T> scale(final Vec2<T> scale) {
return scale(scale.getX(), scale.getY());
}
/**
* Length of the vector.
*
* @return length.
*/
float length();
/**
* @return Vec2<Integer> components of {@link Vec2<T>}
*/
Vec2<Integer> intValue();
/**
* @return Vec2<Float> components of {@link Vec2<T>}
*/
Vec2<Float> floatValue();
/**
* @param xTransform
* transform of x component.
* @param yTransform
* transform of y component.
* @return transformed vec applying {@param xTransform} to x component,
* {@param yTransform} to y component.
*/
Vec2<T> transform(final Function<T, T> xTransform, final Function<T, T> yTransform);
}
|