|
13 | 13 | */ |
14 | 14 | public class Point { |
15 | 15 |
|
16 | | - /** {@code Point} representing the origin as an {@code int}: {@code (0, 0)}. */ |
| 16 | + /** |
| 17 | + * {@code Point} representing the origin as an {@code int}: {@code (0, 0)}. |
| 18 | + * |
| 19 | + * @deprecated As an object, users are likely to accidentally modify this value. Furthermore, Java will likely not |
| 20 | + * receive <a href="https://openjdk.java.net/jeps/401" target="_blank">primitive objects</a> any time soon, so this |
| 21 | + * value will be removed very soon. Use {@link Point#origin()} instead. |
| 22 | + */ |
| 23 | + @Deprecated |
17 | 24 | public static final Point Origin = new Point(); |
18 | 25 |
|
19 | 26 | /** The x value of the {@link Point}. */ |
@@ -81,54 +88,61 @@ public Point(int xVal, int yVal) { |
81 | 88 | } |
82 | 89 |
|
83 | 90 | /** |
84 | | - * {@code Point} representing a 2D graph's origin as a pair of {@code integer}s: {@code (0, 0)}. |
| 91 | + * {@code Point} representing a 2D graph's origin as a pair of {@code integer}s: {@code (0, 0)}. Each returned |
| 92 | + * instance is a newly created object. |
85 | 93 | * |
86 | | - * @return The {@code origin} instance. |
| 94 | + * @return An {@code origin} instance. |
| 95 | + * @since 1.6.0 |
87 | 96 | */ |
88 | 97 | public static Point origin() { |
89 | 98 | return new Point(); |
90 | 99 | } |
91 | 100 |
|
92 | 101 | /** |
93 | | - * {@code Point} representing a unit vector in a 2D graph as a pair of {@code integer}s: {@code (0, 0)}. |
| 102 | + * {@code Point} representing a unit vector in a 2D graph as a pair of {@code integer}s: {@code (0, 0)}. Each |
| 103 | + * returned instance is a newly created object. |
94 | 104 | * |
95 | | - * @return The {@code unit} vector instance. |
| 105 | + * @return A {@code unit} vector instance. |
96 | 106 | */ |
97 | 107 | public static Point unit() { |
98 | 108 | return new Point(1); |
99 | 109 | } |
100 | 110 |
|
101 | 111 | /** |
102 | | - * {@code Point} representing an up vector in a 2D graph as a pair of {@code integer}s: {@code (0, -1)}. |
| 112 | + * {@code Point} representing an up vector in a 2D graph as a pair of {@code integer}s: {@code (0, -1)}. Each |
| 113 | + * returned instance is a newly created object. |
103 | 114 | * |
104 | | - * @return The {@code up} vector instance. |
| 115 | + * @return An {@code up} vector instance. |
105 | 116 | */ |
106 | 117 | public static Point up() { |
107 | 118 | return new Point(0, -1); |
108 | 119 | } |
109 | 120 |
|
110 | 121 | /** |
111 | | - * {@code Point} representing a down vector in a 2D graph as a pair of {@code integer}s: {@code (0, 1)}. |
| 122 | + * {@code Point} representing a down vector in a 2D graph as a pair of {@code integer}s: {@code (0, 1)}. Each |
| 123 | + * returned instance is a newly created object. |
112 | 124 | * |
113 | | - * @return The {@code down} vector instance. |
| 125 | + * @return A {@code down} vector instance. |
114 | 126 | */ |
115 | 127 | public static Point down() { |
116 | 128 | return new Point(0, 1); |
117 | 129 | } |
118 | 130 |
|
119 | 131 | /** |
120 | | - * {@code Point} representing a left vector in a 2D graph as a pair of {@code integer}s: {@code (-1, 0)}. |
| 132 | + * {@code Point} representing a left vector in a 2D graph as a pair of {@code integer}s: {@code (-1, 0)}. Each |
| 133 | + * returned instance is a newly created object. |
121 | 134 | * |
122 | | - * @return The {@code left} vector instance. |
| 135 | + * @return A {@code left} vector instance. |
123 | 136 | */ |
124 | 137 | public static Point left() { |
125 | 138 | return new Point(-1, 0); |
126 | 139 | } |
127 | 140 |
|
128 | 141 | /** |
129 | | - * {@code Point} representing a right vector in a 2D graph as a pair of {@code integer}s: {@code (1, 0)}. |
| 142 | + * {@code Point} representing a right vector in a 2D graph as a pair of {@code integer}s: {@code (1, 0)}. Each |
| 143 | + * returned instance is a newly created object. |
130 | 144 | * |
131 | | - * @return The {@code right} vector instance. |
| 145 | + * @return A {@code right} vector instance. |
132 | 146 | */ |
133 | 147 | public static Point right() { |
134 | 148 | return new Point(1, 0); |
@@ -317,8 +331,8 @@ public static int cross(Point p, Point p1) { |
317 | 331 | * @return The calculated distance. |
318 | 332 | */ |
319 | 333 | public static float distance(Point p, Point p1) { |
320 | | - float differenceX = p1.x - p.x; |
321 | | - float differenceY = p1.y - p.y; |
| 334 | + float differenceX = (float) p1.x - p.x; |
| 335 | + float differenceY = (float) p1.y - p.y; |
322 | 336 | return (float) Math.sqrt(differenceX * differenceX + differenceY * differenceY); |
323 | 337 | } |
324 | 338 |
|
|
0 commit comments