Last active
February 9, 2023 23:13
-
-
Save ruxo/cc85a7ab012e2d0b07df to your computer and use it in GitHub Desktop.
F# Geometry types
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 Rect = | |
| { Left:int; Top:int; Width:int; Height:int } | |
| with | |
| static member create(w, h) = { Left=0; Top=0; Width=w; Height=h } | |
| static member create(l,t,r,b) = { Left=l; Top=t; Width=(r-l)+1; Height=(b-t)+1 } | |
| static member shrink n r = { Left=r.Left+n; Top=r.Top+n; Width=r.Width-2*n; Height=r.Height-2*n } | |
| static member scan r = | |
| seq { | |
| for y = r.Top to r.Top+r.Height-1 do | |
| for x = r.Left to r.Left+r.Width-1 do | |
| yield x,y | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment