# HG changeset patch # User postspectacular # Date 1326688346 0 # Node ID 94bd573365f09c8b732a0153d969a4c319952b0c # Parent 426cf1202f880a35fb3666ca1e9e2b0860baf56f updating ReadonlyVec2D/Vec2D.min()/max() & minSelf()/maxSelf() to work with ReadonlyVec2D, updating Vec2D.angleBetween() to workaround float rounding errors diff -r 426cf1202f880a35fb3666ca1e9e2b0860baf56f -r 94bd573365f09c8b732a0153d969a4c319952b0c src.core/toxi/geom/ReadonlyVec2D.java --- a/src.core/toxi/geom/ReadonlyVec2D.java Mon Jan 16 04:30:19 2012 +0000 +++ b/src.core/toxi/geom/ReadonlyVec2D.java Mon Jan 16 04:32:26 2012 +0000 @@ -400,7 +400,7 @@ * @param v * @return result as new vector */ - public Vec2D max(Vec2D v); + public Vec2D max(ReadonlyVec2D v); /** * Constructs a new vector consisting of the smallest components of both @@ -410,7 +410,7 @@ * comparing vector * @return result as new vector */ - public Vec2D min(Vec2D v); + public Vec2D min(ReadonlyVec2D v); /** * Scales vector uniformly and returns result as new vector. diff -r 426cf1202f880a35fb3666ca1e9e2b0860baf56f -r 94bd573365f09c8b732a0153d969a4c319952b0c src.core/toxi/geom/Vec2D.java --- a/src.core/toxi/geom/Vec2D.java Mon Jan 16 04:30:19 2012 +0000 +++ b/src.core/toxi/geom/Vec2D.java Mon Jan 16 04:32:26 2012 +0000 @@ -107,8 +107,9 @@ * * @return result as new vector */ - public static final Vec2D max(Vec2D a, Vec2D b) { - return new Vec2D(MathUtils.max(a.x, b.x), MathUtils.max(a.y, b.y)); + public static final Vec2D max(ReadonlyVec2D a, ReadonlyVec2D b) { + return new Vec2D(MathUtils.max(a.x(), b.x()), MathUtils.max(a.y(), + b.y())); } /** @@ -122,8 +123,9 @@ * * @return result as new vector */ - public static final Vec2D min(Vec2D a, Vec2D b) { - return new Vec2D(MathUtils.min(a.x, b.x), MathUtils.min(a.y, b.y)); + public static final Vec2D min(ReadonlyVec2D a, ReadonlyVec2D b) { + return new Vec2D(MathUtils.min(a.x(), b.x()), MathUtils.min(a.y(), + b.y())); } /** @@ -252,7 +254,7 @@ } else { theta = dot(v); } - return (float) Math.acos(theta); + return (float) Math.acos(MathUtils.clipNormalized(theta)); } public Vec3D bisect(Vec2D b) { @@ -734,8 +736,8 @@ return x * x + y * y; } - public final Vec2D max(Vec2D v) { - return new Vec2D(MathUtils.max(x, v.x), MathUtils.max(y, v.y)); + public final Vec2D max(ReadonlyVec2D v) { + return new Vec2D(MathUtils.max(x, v.x()), MathUtils.max(y, v.y())); } /** @@ -744,14 +746,14 @@ * @param v * @return itself */ - public final Vec2D maxSelf(Vec2D v) { - x = MathUtils.max(x, v.x); - y = MathUtils.max(y, v.y); + public final Vec2D maxSelf(ReadonlyVec2D v) { + x = MathUtils.max(x, v.x()); + y = MathUtils.max(y, v.y()); return this; } - public final Vec2D min(Vec2D v) { - return new Vec2D(MathUtils.min(x, v.x), MathUtils.min(y, v.y)); + public final Vec2D min(ReadonlyVec2D v) { + return new Vec2D(MathUtils.min(x, v.x()), MathUtils.min(y, v.y())); } /** @@ -760,9 +762,9 @@ * @param v * @return itself */ - public final Vec2D minSelf(Vec2D v) { - x = MathUtils.min(x, v.x); - y = MathUtils.min(y, v.y); + public final Vec2D minSelf(ReadonlyVec2D v) { + x = MathUtils.min(x, v.x()); + y = MathUtils.min(y, v.y()); return this; }