-
Notifications
You must be signed in to change notification settings - Fork 0
/
prelude.fs
26 lines (21 loc) · 1.01 KB
/
prelude.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module prelude
[<Measure>]
type m
[<Measure>]
type s
[<Measure>]
type kg
[<Measure>]
type N = kg * m / (s^2)
type Vector2< [<Measure>] 'm> = { x:float<'m>; y:float<'m> }
with
static member Diag (k:float<'m>) : Vector2<'m> = { x=k; y=k }
static member (~-) (v:Vector2<'m>) : Vector2<'m> = { x= -v.x; y= -v.y }
static member (+) (v1:Vector2<'m>, v2:Vector2<'m>) : Vector2<'m> = { x=v1.x+v2.x; y=v1.y+v2.y }
static member (+) (v1:Vector2<'m>, k:float<'m>) : Vector2<'m> = v1 + Vector2.Diag k
static member (-) (v1:Vector2<'m>, v2:Vector2<'m>) : Vector2<'m> = v1 + (-v2)
static member (*) (v1:Vector2<'m>, v2:Vector2<'n>) : Vector2<'m * 'n> = { x=v1.x*v2.x; y=v1.y*v2.y }
static member (*) (v1:Vector2<'m>, k:float<'n>) : Vector2<'m * 'n> = v1 * Vector2.Diag k
static member (/) (v1:Vector2<'m>, v2:Vector2<'n>) : Vector2<'m / 'n> = { x=v1.x/v2.x; y=v1.y/v2.y }
static member (/) (v1:Vector2<'m>, k:float<'n>) : Vector2<'m / 'n> = v1 / Vector2.Diag k
member v.Length : float<'m> = sqrt(v.x * v.x + v.y * v.y)