Skip to content

Commit e3b63f5

Browse files
committed
remove usages of deprecated Pointf.Origin
1 parent 692e8f9 commit e3b63f5

File tree

6 files changed

+37
-33
lines changed

6 files changed

+37
-33
lines changed

src/main/java/tech/fastj/graphics/display/Camera.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class Camera {
1717
/** A camera with no transformations. */
1818
public static final Camera Default = new Camera();
1919

20+
private static final Pointf OriginInstance = Pointf.origin();
21+
2022
private final Transform2D transform;
2123

2224
/** Constructs a {@code Camera} with default transformations. */
@@ -197,7 +199,7 @@ public AffineTransform getTransformation() {
197199
* @param rotationMod float parameter that the {@code Camera} will be rotated by.
198200
*/
199201
public void rotate(float rotationMod) {
200-
rotate(rotationMod, Pointf.Origin);
202+
rotate(rotationMod, OriginInstance);
201203
}
202204

203205
/**

src/main/java/tech/fastj/graphics/game/Text2D.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class Text2D extends GameObject {
3535
/** {@code String} representing default text -- an empty string. */
3636
public static final String DefaultText = "";
3737

38+
private static final Pointf OriginInstance = Pointf.origin();
39+
3840
private String text;
3941
private Paint fillPaint;
4042
private Font font;
@@ -169,7 +171,7 @@ public void render(Graphics2D g) {
169171
g.setFont(font);
170172
g.setPaint(fillPaint);
171173

172-
g.drawString(text, Pointf.Origin.x, font.getSize2D());
174+
g.drawString(text, OriginInstance.x, font.getSize2D());
173175

174176
g.setTransform(oldTransform);
175177
g.setFont(oldFont);

src/test/java/unittest/testcases/graphics/DrawableTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void checkCollision_betweenPolygon2D_andModel2D() {
4141
Pointf[] square = DrawUtil.createBox(0f, 0f, 50f);
4242
Polygon2D polygon2D = Polygon2D.fromPoints(square);
4343

44-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
44+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
4545
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
4646
Polygon2D[] polygons = {
4747
Polygon2D.fromPoints(square1),
@@ -75,7 +75,7 @@ void checkCollision_betweenText2D_andModel2D() {
7575
String text = "Hello, world!";
7676
Text2D text2D = Text2D.fromText(text);
7777

78-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
78+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
7979
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
8080
Polygon2D[] polygons = {
8181
Polygon2D.fromPoints(square1),

src/test/java/unittest/testcases/graphics/game/Model2DTests.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Model2DTests {
1818

1919
@Test
2020
void checkModel2DCreation_withPolygon2DArrayParam() {
21-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
21+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
2222
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
2323

2424
Polygon2D[] polygons = {
@@ -37,7 +37,7 @@ void checkModel2DCreation_withPolygon2DArrayParam() {
3737

3838
@Test
3939
void checkModel2DCreation_withPolygon2DArrayParam_andRandomlyGeneratedShowParam() {
40-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
40+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
4141
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
4242

4343
Polygon2D[] polygons = {
@@ -58,7 +58,7 @@ void checkModel2DCreation_withPolygon2DArrayParam_andRandomlyGeneratedShowParam(
5858

5959
@Test
6060
void checkModel2DCreation_withPolygon2DArrayParam_andRandomlyGeneratedShowParam_andRandomlyGeneratedTransformParams() {
61-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
61+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
6262
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
6363

6464
Polygon2D[] polygons = {
@@ -86,7 +86,7 @@ void checkModel2DCreation_withPolygon2DArrayParam_andRandomlyGeneratedShowParam_
8686

8787
@Test
8888
void checkModel2DCreation_withPolygon2DArrayParam_andRandomlyGeneratedShowParam_andRandomlyGeneratedTransformParams_usingMethodChaining() {
89-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
89+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
9090
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
9191

9292
Polygon2D[] polygons = {
@@ -116,7 +116,7 @@ void checkModel2DCreation_withPolygon2DArrayParam_andRandomlyGeneratedShowParam_
116116

117117
@Test
118118
void checkModel2DBoundsCreation_shouldMatchExpected() {
119-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
119+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
120120
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
121121

122122
Polygon2D[] polygons = {
@@ -138,7 +138,7 @@ void checkModel2DBoundsCreation_shouldMatchExpected() {
138138

139139
@Test
140140
void checkModel2DTranslation_shouldMatchExpected() {
141-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
141+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
142142
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
143143
Pointf randomTranslation = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
144144

@@ -165,7 +165,7 @@ void checkModel2DTranslation_shouldMatchExpected() {
165165

166166
@Test
167167
void checkModel2DRotation_aroundOrigin_shouldMatchExpected() {
168-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
168+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
169169
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
170170
float randomRotation = Maths.random(-5000f, 5000f);
171171

@@ -174,15 +174,15 @@ void checkModel2DRotation_aroundOrigin_shouldMatchExpected() {
174174
Polygon2D.fromPoints(square2)
175175
};
176176
for (Polygon2D polygon2D : expectedPolygons) {
177-
polygon2D.rotate(randomRotation, Pointf.Origin);
177+
polygon2D.rotate(randomRotation, Pointf.origin());
178178
}
179179

180180
Polygon2D[] actualPolygons = {
181181
Polygon2D.fromPoints(square1),
182182
Polygon2D.fromPoints(square2)
183183
};
184184
Model2D model2D = Model2D.fromPolygons(actualPolygons);
185-
model2D.rotate(randomRotation, Pointf.Origin);
185+
model2D.rotate(randomRotation, Pointf.origin());
186186

187187
for (Polygon2D polygon2D : expectedPolygons) {
188188
assertEquals(polygon2D.getRotation(), model2D.getRotation(), "The rotation of the Model2D should equal to the rotation of the Polygon2Ds.");
@@ -192,7 +192,7 @@ void checkModel2DRotation_aroundOrigin_shouldMatchExpected() {
192192

193193
@Test
194194
void checkModel2DRotation_aroundModelCenter_shouldMatchExpected() {
195-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
195+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
196196
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
197197
Pointf expectedModelCenter = Pointf.subtract(square2[2], square1[0]).divide(2f).add(square1[0]);
198198
float randomRotation = Maths.random(-5000f, 5000f);
@@ -220,7 +220,7 @@ void checkModel2DRotation_aroundModelCenter_shouldMatchExpected() {
220220

221221
@Test
222222
void checkModel2DRotation_aroundRandomCenter_shouldMatchExpected() {
223-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
223+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
224224
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
225225
Pointf randomCenter = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
226226
float randomRotation = Maths.random(-5000f, 5000f);
@@ -248,7 +248,7 @@ void checkModel2DRotation_aroundRandomCenter_shouldMatchExpected() {
248248

249249
@Test
250250
void checkModel2DScaling_aroundOrigin_shouldMatchExpected() {
251-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
251+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
252252
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
253253
Pointf randomScaling = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
254254

@@ -257,15 +257,15 @@ void checkModel2DScaling_aroundOrigin_shouldMatchExpected() {
257257
Polygon2D.fromPoints(square2)
258258
};
259259
for (Polygon2D polygon2D : expectedPolygons) {
260-
polygon2D.scale(randomScaling, Pointf.Origin);
260+
polygon2D.scale(randomScaling, Pointf.origin());
261261
}
262262

263263
Polygon2D[] actualPolygons = {
264264
Polygon2D.fromPoints(square1),
265265
Polygon2D.fromPoints(square2)
266266
};
267267
Model2D model2D = Model2D.fromPolygons(actualPolygons);
268-
model2D.scale(randomScaling, Pointf.Origin);
268+
model2D.scale(randomScaling, Pointf.origin());
269269

270270
for (Polygon2D polygon2D : expectedPolygons) {
271271
assertEquals(polygon2D.getScale(), model2D.getScale(), "The scale of the Model2D should equal to the scale of the Polygon2Ds.");
@@ -275,7 +275,7 @@ void checkModel2DScaling_aroundOrigin_shouldMatchExpected() {
275275

276276
@Test
277277
void checkModel2DScaling_aroundModelCenter_shouldMatchExpected() {
278-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
278+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
279279
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
280280
Pointf randomScaling = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
281281
Pointf expectedModelCenter = Pointf.subtract(square2[2], square1[0]).divide(2f).add(square1[0]);
@@ -303,7 +303,7 @@ void checkModel2DScaling_aroundModelCenter_shouldMatchExpected() {
303303

304304
@Test
305305
void checkModel2DScaling_aroundRandomCenter_shouldMatchExpected() {
306-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
306+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
307307
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
308308
Pointf randomScaling = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
309309
Pointf randomCenter = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
@@ -331,7 +331,7 @@ void checkModel2DScaling_aroundRandomCenter_shouldMatchExpected() {
331331

332332
@Test
333333
void checkModel2DScaling_usingScaleAsFloat_shouldMatchExpected() {
334-
Pointf[] square1 = DrawUtil.createBox(Pointf.Origin, 50f);
334+
Pointf[] square1 = DrawUtil.createBox(Pointf.origin(), 50f);
335335
Pointf[] square2 = DrawUtil.createBox(Pointf.origin().add(25f), 50f);
336336
float randomScaling = Maths.random(-50f, 50f);
337337
Pointf expectedModelCenter = Pointf.subtract(square2[2], square1[0]).divide(2f).add(square1[0]);

src/test/java/unittest/testcases/graphics/game/Polygon2DTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void checkPolygon2DCreation_withPointfArrayParam_andRandomlyGeneratedRenderStyle
129129

130130
@Test
131131
void checkModifyPointsOfPolygon2D_withTransformResetting() {
132-
Pointf[] squarePoints = DrawUtil.createBox(Pointf.Origin, 5f);
132+
Pointf[] squarePoints = DrawUtil.createBox(Pointf.origin(), 5f);
133133
Pointf translationBeforeReset = new Pointf(Maths.random(0f, 1f), Maths.random(0f, 1f));
134134
float rotationBeforeReset = Maths.random(0f, 100f);
135135
Pointf scaleBeforeReset = new Pointf(Maths.random(0f, 1f), Maths.random(0f, 1f));
@@ -150,7 +150,7 @@ void checkModifyPointsOfPolygon2D_withTransformResetting() {
150150

151151
@Test
152152
void checkModifyPointsOfPolygon2D_withoutTransformResetting() {
153-
Pointf[] squarePoints = DrawUtil.createBox(Pointf.Origin, 5f);
153+
Pointf[] squarePoints = DrawUtil.createBox(Pointf.origin(), 5f);
154154
Pointf translationBeforeReset = new Pointf(Maths.random(0f, 1f), Maths.random(0f, 1f));
155155
float rotationBeforeReset = Maths.random(0f, 100f);
156156
Pointf scaleBeforeReset = new Pointf(Maths.random(0f, 1f), Maths.random(0f, 1f));
@@ -171,7 +171,7 @@ void checkModifyPointsOfPolygon2D_withoutTransformResetting() {
171171

172172
@Test
173173
void checkPolygon2DTranslation_shouldMatchExpected() {
174-
Pointf[] originalPoints = DrawUtil.createBox(Pointf.Origin, 5f);
174+
Pointf[] originalPoints = DrawUtil.createBox(Pointf.origin(), 5f);
175175
Pointf randomTranslation = new Pointf(
176176
Maths.random(0f, 1f),
177177
Maths.random(0f, 1f)
@@ -197,7 +197,7 @@ void checkPolygon2DRotation_aroundOrigin_shouldMatchExpected() {
197197
float cosOfRotation = (float) Math.cos(randomRotationInRadians);
198198
float sinOfRotation = (float) Math.sin(randomRotationInRadians);
199199
float size = 5f;
200-
Pointf[] originalPoints = DrawUtil.createBox(Pointf.Origin, size);
200+
Pointf[] originalPoints = DrawUtil.createBox(Pointf.origin(), size);
201201

202202
Pointf[] expectedRotatedPoints = {
203203
new Pointf(
@@ -219,7 +219,7 @@ void checkPolygon2DRotation_aroundOrigin_shouldMatchExpected() {
219219
};
220220

221221
Polygon2D polygon2D = Polygon2D.fromPoints(originalPoints);
222-
polygon2D.rotate(randomRotationInDegrees, Pointf.Origin);
222+
polygon2D.rotate(randomRotationInDegrees, Pointf.origin());
223223
Pointf[] actualRotatedPoints = polygon2D.getPoints();
224224

225225
assertArrayEquals(expectedRotatedPoints, actualRotatedPoints, "The actual Pointf array, which has been rotated about the origin, should match the expected Pointf array.");
@@ -232,7 +232,7 @@ void checkPolygon2DRotation_aroundPolygonCenter_shouldMatchExpected() {
232232
float cosOfRotation = (float) Math.cos(randomRotationInRadians);
233233
float sinOfRotation = (float) Math.sin(randomRotationInRadians);
234234
float size = 5f;
235-
Pointf[] originalPoints = DrawUtil.createBox(Pointf.Origin, size);
235+
Pointf[] originalPoints = DrawUtil.createBox(Pointf.origin(), size);
236236

237237
Pointf[] pointsAtOrigin = {
238238
originalPoints[0].copy().subtract(size / 2f),
@@ -275,7 +275,7 @@ void checkPolygon2DRotation_aroundRandomPoint_shouldMatchExpected() {
275275
float sinOfRotation = (float) Math.sin(randomRotationInRadians);
276276
float size = 5f;
277277
Pointf randomCenter = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
278-
Pointf[] originalPoints = DrawUtil.createBox(Pointf.Origin, size);
278+
Pointf[] originalPoints = DrawUtil.createBox(Pointf.origin(), size);
279279

280280
Pointf[] pointsAtOrigin = {
281281
originalPoints[0].copy().subtract(randomCenter),
@@ -313,7 +313,7 @@ void checkPolygon2DRotation_aroundRandomPoint_shouldMatchExpected() {
313313
void checkPolygon2DScaling_aroundOrigin_shouldMatchExpected() {
314314
Pointf randomScaling = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
315315
float size = 5f;
316-
Pointf[] originalPoints = DrawUtil.createBox(Pointf.Origin, size);
316+
Pointf[] originalPoints = DrawUtil.createBox(Pointf.origin(), size);
317317

318318
Pointf newScale = Pointf.add(randomScaling, Transform2D.DefaultScale);
319319
Pointf[] expectedScaledPoints = {
@@ -324,7 +324,7 @@ void checkPolygon2DScaling_aroundOrigin_shouldMatchExpected() {
324324
};
325325

326326
Polygon2D polygon2D = Polygon2D.fromPoints(originalPoints);
327-
polygon2D.scale(randomScaling, Pointf.Origin);
327+
polygon2D.scale(randomScaling, Pointf.origin());
328328
Pointf[] actualScaledPoints = polygon2D.getPoints();
329329
assertArrayEquals(expectedScaledPoints, actualScaledPoints, "The actual Pointf array, which has been scaled, should match the expected Pointf array.");
330330
}
@@ -333,7 +333,7 @@ void checkPolygon2DScaling_aroundOrigin_shouldMatchExpected() {
333333
void checkPolygon2DScaling_aroundPolygonCenter_shouldMatchExpected() {
334334
Pointf randomScaling = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
335335
float size = 5f;
336-
Pointf[] originalPoints = DrawUtil.createBox(Pointf.Origin, size);
336+
Pointf[] originalPoints = DrawUtil.createBox(Pointf.origin(), size);
337337

338338
Pointf newScale = Pointf.add(randomScaling, Transform2D.DefaultScale);
339339
Pointf[] pointsAtOrigin = {
@@ -360,7 +360,7 @@ void checkPolygon2DScaling_aroundRandomPoint_shouldMatchExpected() {
360360
Pointf randomCenter = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
361361
Pointf randomScaling = new Pointf(Maths.random(-50f, 50f), Maths.random(-50f, 50f));
362362
float size = 5f;
363-
Pointf[] originalPoints = DrawUtil.createBox(Pointf.Origin, size);
363+
Pointf[] originalPoints = DrawUtil.createBox(Pointf.origin(), size);
364364

365365
Pointf newScale = Pointf.add(randomScaling, Transform2D.DefaultScale);
366366
Pointf[] pointsAtOrigin = {

src/test/java/unittest/testcases/graphics/game/Text2DTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void checkRotateText2D_shouldMatchExpected() {
170170

171171
Text2D text2D = Text2D.fromText(text);
172172

173-
assertDoesNotThrow(() -> text2D.rotate(randomRotation, Pointf.Origin), "Rotating Text2D objects is implemented, and should not throw an exception.");
173+
assertDoesNotThrow(() -> text2D.rotate(randomRotation, Pointf.origin()), "Rotating Text2D objects is implemented, and should not throw an exception.");
174174
assertEquals(randomRotation, text2D.getRotation(), "The actual rotation should match the expected rotation.");
175175
});
176176
}

0 commit comments

Comments
 (0)