Encapsulates a 2D vector. Allows chaining methods by returning a reference to itself @author badlogicgames@gmail.com
| 24 | /** Encapsulates a 2D vector. Allows chaining methods by returning a reference to itself |
| 25 | * @author badlogicgames@gmail.com */ |
| 26 | public class Vector2 implements Serializable, Vector<Vector2> { |
| 27 | private static final long serialVersionUID = 913902788239530931L; |
| 28 | |
| 29 | public final static Vector2 X = new Vector2(1, 0); |
| 30 | public final static Vector2 Y = new Vector2(0, 1); |
| 31 | public final static Vector2 Zero = new Vector2(0, 0); |
| 32 | public final static Vector2 One = new Vector2(1, 1); |
| 33 | |
| 34 | /** the x-component of this vector **/ |
| 35 | public float x; |
| 36 | /** the y-component of this vector **/ |
| 37 | public float y; |
| 38 | |
| 39 | /** Constructs a new vector at (0,0) */ |
| 40 | public Vector2 () { |
| 41 | } |
| 42 | |
| 43 | /** Constructs a vector with the given components |
| 44 | * @param x The x-component |
| 45 | * @param y The y-component */ |
| 46 | public Vector2 (float x, float y) { |
| 47 | this.x = x; |
| 48 | this.y = y; |
| 49 | } |
| 50 | |
| 51 | /** Constructs a vector from the given vector |
| 52 | * @param v The vector */ |
| 53 | public Vector2 (Vector2 v) { |
| 54 | set(v); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Vector2 cpy () { |
| 59 | return new Vector2(this); |
| 60 | } |
| 61 | |
| 62 | public static float len (float x, float y) { |
| 63 | return (float)Math.sqrt(x * x + y * y); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public float len () { |
| 68 | return (float)Math.sqrt(x * x + y * y); |
| 69 | } |
| 70 | |
| 71 | public static float len2 (float x, float y) { |
| 72 | return x * x + y * y; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public float len2 () { |
| 77 | return x * x + y * y; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public Vector2 set (Vector2 v) { |
| 82 | x = v.x; |
| 83 | y = v.y; |
nothing calls this directly
no outgoing calls
no test coverage detected