Closed DonaldDuck313 closed 3 months ago
I'm guessing new Point(5, 5).add(new Vector(0, -1))
will do what you what. I agree that the order probably shouldn't matter though; a point plus a vector should be a point.
Function add
in class Vector
is supposed to summarize two vectors.
It defined as following
add(v: Vector): Vector;
If you want to translate point by vector, use translate
method of point:
const translated_point = new Point(5, 5).translate(new Vector(0, -1))
The result will be a Point
If you want to translate point by vector, use
translate
method of point:const translated_point = new Point(5, 5).translate(new Vector(0, -1))
The result will be a
Point
Thanks, I didn't know about that. It's not in the documentation for the Point class, could you please add it?
Translate method and other transformations are part of the Shape base class, all classes are inherited from it. So in the docs they are also in Shape, because docs are auto generated.
If I run the following code in the Javascript console:
It returns
I would expect it to return a point. I need to translate a point by a vector and get a new point, how do I do that?
Also, in general, functions for converting between points and vectors would be very useful. It would be nice if you could add a
toPoint
method to the Vector class or something equivalent.