add X and Y vector constructors

This commit is contained in:
faiface 2017-03-14 13:27:18 +01:00
parent fa57a41d2a
commit a2b9bb5b5a
1 changed files with 11 additions and 1 deletions

View File

@ -34,11 +34,21 @@ import (
// x := u.Unit().Dot(v.Unit())
type Vec complex128
// V returns a new 2d vector with the given coordinates.
// V returns a new 2D vector with the given coordinates.
func V(x, y float64) Vec {
return Vec(complex(x, y))
}
// X returns a 2D vector with coordinates (x, 0).
func X(x float64) Vec {
return V(x, 0)
}
// Y returns a 2D vector with coordinates (0, y).
func Y(y float64) Vec {
return V(0, y)
}
// String returns the string representation of the vector u.
//
// u := pixel.V(4.5, -1.3)