Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am shaddysignal on github.
* I am shaddysignal (https://keybase.io/shaddysignal) on keybase.
* I have a public key ASBxYJ17PuMRiZKh9Q-nZoBgPjj2mrgdXtzBLOIUX3CuIgo
To claim this, I am signing this object:
@shaddysignal
shaddysignal / Vector2.scala
Created March 25, 2016 13:43
snippet for generic vector
case class Vector2[T: Numeric](x: T, y: T) {
private val ops: Numeric[T] = implicitly[Numeric[T]]
import ops._
val length = math.sqrt(toDouble(plus(times(x, x), times(y, y))))
val norm = Vector2(toDouble(x) / length, toDouble(y) / length)
def *(s: T): Vector2[T] =
Vector2(times(s, this.x), times(s, this.y)) // Vector(s * x, s * y)