Allow a Vector to be set from any XY.

I'm tempted to make add/subtract/scale take XY as well, but I'm not sure I love
that. Part of the point (pardon the pun) of having Point and Vector is to use
the types to prevent one from performing nonsensical operations. For example,
you lerp between two vectors, lerping between a Vector and a Point would be
weird; sloppy at best, most likely wrong. Adding/subtracting a point to/from a
vector feels like it's in the wrong category as well, so perhaps it's best to
continue to prevent that via the type system.

If you really have a Point (or some other XY) that represents a vector, then I
guess I'm fine with forcing you to either put it into a Vector to get the
convenient math, or to pull out its x/y components manually. Then again, that
also feels overly paternal. Blah.
This commit is contained in:
Michael Bayne
2015-05-30 10:38:28 -07:00
parent 70b83fd521
commit 0447064ea9
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -105,7 +105,7 @@ public class Vector extends AbstractVector
/** Copies the elements of another vector. /** Copies the elements of another vector.
* @return a reference to this vector, for chaining. */ * @return a reference to this vector, for chaining. */
public Vector set (IVector other) { public Vector set (XY other) {
return set(other.x(), other.y()); return set(other.x(), other.y());
} }
+1 -1
View File
@@ -105,7 +105,7 @@ public class Vector extends AbstractVector
/** Copies the elements of another vector. /** Copies the elements of another vector.
* @return a reference to this vector, for chaining. */ * @return a reference to this vector, for chaining. */
public Vector set (IVector other) { public Vector set (XY other) {
return set(other.x(), other.y()); return set(other.x(), other.y());
} }