Represents a 2D vector with double-precision. @author RGreenlees @author Kai Burjack with modifications and additions for Field
| 47 | * with modifications and additions for Field |
| 48 | */ |
| 49 | @SafeToToString |
| 50 | public class Vec2 implements OverloadedMath, Externalizable, Supplier<Vec2>, Mutable, Serializable_safe, fieldlinker.AsMap_callable { |
| 51 | |
| 52 | private static final long serialVersionUID = 1L; |
| 53 | |
| 54 | /** |
| 55 | * The x component of the vector. |
| 56 | */ |
| 57 | public double x; |
| 58 | /** |
| 59 | * The y component of the vector. |
| 60 | */ |
| 61 | public double y; |
| 62 | |
| 63 | /** |
| 64 | * Create a new {@link Vec2} and initialize its components to zero. |
| 65 | */ |
| 66 | public Vec2() { |
| 67 | } |
| 68 | |
| 69 | public Vec2(List<Number> from) { |
| 70 | this(from.get(0).doubleValue(), from.get(1).doubleValue()); |
| 71 | } |
| 72 | |
| 73 | public Vec2(List<Number> from, int offset) { |
| 74 | this(from.get(offset).doubleValue(), from.get(offset + 1).doubleValue()); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Create a new {@link Vec2} and initialize both of its components with the given value. |
| 79 | * |
| 80 | * @param d the value of both components |
| 81 | */ |
| 82 | public Vec2(double d) { |
| 83 | this(d, d); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Create a new {@link Vec2} and initialize its components to the given values. |
| 88 | * |
| 89 | * @param x the x value |
| 90 | * @param y the y value |
| 91 | */ |
| 92 | public Vec2(double x, double y) { |
| 93 | this.x = x; |
| 94 | this.y = y; |
| 95 | } |
| 96 | |
| 97 | protected Vec2(Object... args) { |
| 98 | if (args.length == 0) { |
| 99 | } else if (args.length == 1) { |
| 100 | this.x = this.y = ((Number) args[0]).floatValue(); |
| 101 | } else if (args.length > 1) { |
| 102 | this.x = ((Number) args[0]).floatValue(); |
| 103 | this.y = ((Number) args[1]).floatValue(); |
| 104 | } |
| 105 | } |
| 106 |
no outgoing calls
no test coverage detected