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) { } }