This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |