vector.go 394 B

123456789101112131415161718192021222324252627
  1. package geometry
  2. type Vector struct {
  3. X float32
  4. Y float32
  5. }
  6. type V = Vector
  7. type P = Vector
  8. type Point = Vector
  9. func NewVector(x, y float32) Vector {
  10. p := Vector{ x, y }
  11. return p
  12. }
  13. func (v1 * Vector) Add(v2 Vector) * Vector {
  14. v1.X += v2.X
  15. v1.Y += v2.Y
  16. return v1
  17. }
  18. func (v1 Vector) Sum(v2 Vector) Vector {
  19. return NewVector(v1.X + v2.X, v1.Y + v2.Y)
  20. }