1
module ParasitemiaCore.Types
5 open System.Collections.Generic
13 type Points = HashSet<Point>
15 type Ellipse (cx
: float32
, cy
: float32
, a
: float32
, b
: float32
, alpha
: float32
) =
20 member this
.Alpha = alpha
21 member this
.Area = a
* b
* PI
23 // Does the ellipse contain the point (x, y)?
24 member this
.Contains x y
=
25 ((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
27 member this
.CutAVericalLine (y
: float32
) : bool =
28 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
30 member this
.CutAnHorizontalLine (x : float32
) : bool =
31 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
33 member this
.IsOutside (width
: float32
) (height
: float32
) =
34 this
.Cx < 0.f
|| this.Cx >= width
||
35 this.Cy < 0.f
|| this.Cy >= height
||
36 this.CutAVericalLine 0.f
|| this.CutAVericalLine width ||
37 this.CutAnHorizontalLine 0.f
|| this.CutAnHorizontalLine height
39 member this.Scale (factor
: float32
) : Ellipse =
40 Ellipse (this.Cx, this.Cy, this.A * factor
, this.B * factor
, alpha)
42 // Approximation of Ramanujan.
43 member this.Perimeter =
44 PI * (3.f
* (this.A + this.B) - sqrt
((3.f
* this.A + this.B) * (this.A + 3.f
* this.B)))
46 override this.ToString () =
47 $
"{{{nameof Ellipse}: {nameof this.Cx} = %f{this.Cx}, {nameof this.Cy} = %f{this.Cy}, {nameof this.A} = %f{this.A}, {nameof this.B} = %f{this.B}, {nameof this.Alpha} = %f{this.Alpha}}}"
49 override this.Equals (other
: obj
) =
51 | :? Ellipse as otherEllipse
->
52 otherEllipse
.Cx = this.Cx &&
53 otherEllipse
.Cy = this.Cy &&
54 otherEllipse
.A = this.A &&
55 otherEllipse
.B = this.B &&
56 otherEllipse
.Alpha = this.Alpha
59 override this.GetHashCode () = HashCode.Combine (this.Cx, this.Cy, this.A, this.B, this.Alpha)
62 type CellClass = HealthyRBC | InfectedRBC | Peculiar
70 elements
: Matrix<byte
>
74 type Line (a
: float32
, b
: float32
) =
78 type MaybeBuilder () =
79 member this.Bind (x, f
) =
84 member this.ReturnFrom x = x
86 member this.TryFinally (body
, compensation
) =
88 this.ReturnFrom (body
())
92 member this.Using (disposable
: 'a when 'a
:> IDisposable, body
) =
93 let body' = fun () -> body disposable
94 this.TryFinally (body', fun () ->
97 | disp -> disp.Dispose ())
102 member this.Return x =
105 let maybe = MaybeBuilder ()
109 | Fail of string // Error message.
111 type ResultBuilder () =
112 member this.Bind (res
, f
) =
114 | Success value
-> f value
117 member this.ReturnFrom (x) = x
119 let result = ResultBuilder ()
121 type AnalysisResult =
124 RBCSize_μm
: float<μm
>