From 0447064ea9e68350738f44b27a83a91807027de6 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 30 May 2015 10:38:28 -0700 Subject: [PATCH] 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. --- src/main/java/pythagoras/d/Vector.java | 2 +- src/main/java/pythagoras/f/Vector.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/pythagoras/d/Vector.java b/src/main/java/pythagoras/d/Vector.java index 1dad4e7..7e35290 100644 --- a/src/main/java/pythagoras/d/Vector.java +++ b/src/main/java/pythagoras/d/Vector.java @@ -105,7 +105,7 @@ public class Vector extends AbstractVector /** Copies the elements of another vector. * @return a reference to this vector, for chaining. */ - public Vector set (IVector other) { + public Vector set (XY other) { return set(other.x(), other.y()); } diff --git a/src/main/java/pythagoras/f/Vector.java b/src/main/java/pythagoras/f/Vector.java index 62faecd..698b80c 100644 --- a/src/main/java/pythagoras/f/Vector.java +++ b/src/main/java/pythagoras/f/Vector.java @@ -105,7 +105,7 @@ public class Vector extends AbstractVector /** Copies the elements of another vector. * @return a reference to this vector, for chaining. */ - public Vector set (IVector other) { + public Vector set (XY other) { return set(other.x(), other.y()); }