Skip to content

Instantly share code, notes, and snippets.

@ruxo
Last active February 9, 2023 23:13
Show Gist options
  • Select an option

  • Save ruxo/cc85a7ab012e2d0b07df to your computer and use it in GitHub Desktop.

Select an option

Save ruxo/cc85a7ab012e2d0b07df to your computer and use it in GitHub Desktop.
F# Geometry types
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