5440115735887c0fe3a266241b5274557c5e3f9e
1
module ParasitemiaCore.Types
5 open System.Collections.Generic
12 type Points = HashSet<Point>
14 type Ellipse (cx
: float32
, cy
: float32
, a
: float32
, b
: float32
, alpha
: float32
) =
19 member this
.Alpha = alpha
20 member this
.Area = a
* b
* PI
22 // Does the ellipse contain the point (x, y)?
23 member this
.Contains x y
=
24 ((x - cx
) * cos
alpha + (y
- cy
) * sin
alpha) ** 2.f
/ a
** 2.f
+ ((x - cx
) * sin
alpha - (y
- cy
) * cos
alpha) ** 2.f
/ b
** 2.f
<= 1.f
26 member this
.CutAVericalLine (y
: float32
) : bool =
27 a
** 2.f
+ b
** 2.f
- 2.f
* y
** 2.f
+ 4.f
* y
* cx
- 2.f
* cx
** 2.f
+ a
** 2.f
* cos
(2.f
* alpha) - b
** 2.f
* cos
(2.f
* alpha) > 0.f
29 member this
.CutAnHorizontalLine (x: float32
) : bool =
30 a
** 2.f
+ b
** 2.f
- 2.f
* x ** 2.f
+ 4.f
* x * cy
- 2.f
* cy
** 2.f
- a
** 2.f
* cos
(2.f
* alpha) + b
** 2.f
* cos
(2.f
* alpha) > 0.f
32 member this
.isOutside
(width
: float32
) (height
: float32
) =
33 this
.Cx < 0.f
|| this.Cx >= width
||
34 this.Cy < 0.f
|| this.Cy >= height
||
35 this.CutAVericalLine 0.f
|| this.CutAVericalLine width ||
36 this.CutAnHorizontalLine 0.f
|| this.CutAnHorizontalLine height
38 member this.Scale (factor
: float32
) : Ellipse =
39 Ellipse(this.Cx, this.Cy, this.A * factor
, this.B * factor
, alpha)
41 // Approximation of Ramanujan.
42 member this.Perimeter =
43 PI * (3.f
* (this.A + this.B) - sqrt
((3.f
* this.A + this.B) * (this.A + 3.f
* this.B)))
45 override this.ToString () =
46 sprintf
"(cx: %A, cy: %A, a: %A, b: %A, alpha: %A)" this.Cx this.Cy this.A this.B this.Alpha
48 type CellClass = HealthyRBC | InfectedRBC | Peculiar
55 elements
: Matrix<byte
> }
58 type Line (a
: float32
, b
: float32
) =
62 type MaybeBuilder () =
63 member this.Bind (x, f
) =
68 member this.ReturnFrom (x) = x
70 member this.TryFinally (body
, compensation
) =
72 this.ReturnFrom(body
())
76 member this.Using (disposable
: 'a when 'a
:> IDisposable, body
) =
77 let body' = fun () -> body disposable
78 this.TryFinally(body', fun () ->
81 | disp -> disp.Dispose())
86 member this.Return (x) =
89 let maybe = MaybeBuilder()
93 | Fail of string // Error message.
95 type ResultBuilder () =
96 member this.Bind (res
, f
) =
98 | Success value
-> f value
101 member this.ReturnFrom (x) = x
103 let result = ResultBuilder()