Convert Vector2D code to Scala.