// Map produces a vector that is within the bounds of the // rectangular manifold of toroidal space, given a vector // that is on the torus but may be outside these bounds. func (t Torus) Map(v *mat64.Vector) { x := v.At(0, 0) y := v.At(1, 0) remx := x right := t.W / 2 if math.Abs(x) > right { remx = math.Mod(t.W, -x) } remy := y top := t.H / 2 if math.Abs(y) > top { remy = math.Mod(t.H, -y) } v.SetVec(0, remx) v.SetVec(1, remy) }