Created
April 1, 2014 10:52
-
-
Save ToJans/9911763 to your computer and use it in GitHub Desktop.
This should do it for ranges
This file contains hidden or 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
type Range(min: decimal,max: decimal) = | |
member this.min = min | |
member this.max = max | |
static member (*) (r: Range, d: decimal) = Range(r.min * d,r.max * d) | |
static member (*) (d: decimal, r: Range) = r*d | |
static member (/) (r: Range, d: decimal) = Range(r.min / d,r.max / d) | |
static member (/) (d: decimal, r: Range) = r/d | |
static member (+) (r: Range, d: decimal) = Range(r.min + d,r.max + d) | |
static member (+) (d: decimal, r: Range) = r+d | |
static member (-) (r: Range, d: decimal) = Range(r.min - d,r.max - d) | |
static member (-) (d: decimal, r: Range) = r-d | |
static member (*) (l: Range, r: Range) = Range(Seq.min [l.min;r.min], Seq.max [l.max;r.max]) | |
static member (/) (l: Range, r: Range) = Range(Seq.max [l.min;r.min], Seq.min [l.max;r.max]) | |
member this.bounded(d: decimal) = [Seq.max [this.min;d] ;this.max] |> Seq.min | |
type Position(value: decimal, range: Range) = | |
member this.value = value | |
member this.range = range | |
static member (*) (r:Position, d: decimal) = Position(r.range.bounded(r.value*d), r.range) | |
static member (*) (d: decimal, r:Position) = r * d | |
static member (/) (r:Position, d: decimal) = Position(r.range.bounded(r.value/d), r.range) | |
static member (/) (d: decimal, r:Position) = r / d | |
static member (+) (r:Position, d: decimal) = Position(r.range.bounded(r.value+d), r.range) | |
static member (+) (d: decimal, r:Position) = r + d | |
static member (-) (r:Position, d: decimal) = Position(r.range.bounded(r.value-d), r.range) | |
static member (-) (d: decimal, r:Position) = r - d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment