summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Point2.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/Point2.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/Point2.java')
-rw-r--r--NET/worlds/scape/Point2.java129
1 files changed, 129 insertions, 0 deletions
diff --git a/NET/worlds/scape/Point2.java b/NET/worlds/scape/Point2.java
new file mode 100644
index 0000000..3b471b7
--- /dev/null
+++ b/NET/worlds/scape/Point2.java
@@ -0,0 +1,129 @@
+package NET.worlds.scape;
+
+import java.io.IOException;
+
+public class Point2 implements Persister {
+ public float x;
+ public float y;
+ private static Object classCookie = new Object();
+
+ public Point2() {
+ }
+
+ public Point2(float _x, float _y) {
+ this.set(_x, _y);
+ }
+
+ public Point2(Point2 p) {
+ this.x = p.x;
+ this.y = p.y;
+ }
+
+ public Point2 copy(Point2 b) {
+ this.x = b.x;
+ this.y = b.y;
+ return this;
+ }
+
+ public void set(float _x, float _y) {
+ this.x = _x;
+ this.y = _y;
+ }
+
+ public float length() {
+ return (float)Math.sqrt(this.x * this.x + this.y * this.y);
+ }
+
+ public Point2 normalize() {
+ float len = this.length();
+ if (len > 0.0F) {
+ this.dividedBy(len);
+ }
+
+ return this;
+ }
+
+ public Point2 negate() {
+ this.x = -this.x;
+ this.y = -this.y;
+ return this;
+ }
+
+ public Point2 plus(Point2 p) {
+ this.x = this.x + p.x;
+ this.y = this.y + p.y;
+ return this;
+ }
+
+ public Point2 plus(float v) {
+ this.x += v;
+ this.y += v;
+ return this;
+ }
+
+ public Point2 minus(float v) {
+ return this.plus(-v);
+ }
+
+ public Point2 minus(Point2 p) {
+ this.x = this.x - p.x;
+ this.y = this.y - p.y;
+ return this;
+ }
+
+ public Point2 times(float v) {
+ this.x *= v;
+ this.y *= v;
+ return this;
+ }
+
+ public Point2 times(Point2 p) {
+ this.x = this.x * p.x;
+ this.y = this.y * p.y;
+ return this;
+ }
+
+ public Point2 dividedBy(float v) {
+ this.x /= v;
+ this.y /= v;
+ return this;
+ }
+
+ public Point2 dividedBy(Point2 p) {
+ this.x = this.x / p.x;
+ this.y = this.y / p.y;
+ return this;
+ }
+
+ public float dot(Point2 p) {
+ return p.x * this.x + p.y * this.y;
+ }
+
+ @Override
+ public String toString() {
+ return this.x + "," + this.y;
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveVersion(0, classCookie);
+ s.saveFloat(this.x);
+ s.saveFloat(this.y);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ switch (r.restoreVersion(classCookie)) {
+ case 0:
+ this.x = r.restoreFloat();
+ this.y = r.restoreFloat();
+ return;
+ default:
+ throw new TooNewException();
+ }
+ }
+
+ @Override
+ public void postRestore(int version) {
+ }
+}