Add a logger assembly and split the main assembly in two : the UI and the parasitemia...
[master-thesis.git] / Parasitemia / ParasitemiaCore / Utils.fs
1 module ParasitemiaCore.Utils
2
3 open Types
4
5 let inline roundInt v = v |> round |> int
6
7 let inline dprintfn fmt =
8 Printf.ksprintf System.Diagnostics.Debug.WriteLine fmt
9
10 let inline lineFromTwoPoints (p1: PointD) (p2: PointD) : Line =
11 let a = (p1.Y - p2.Y) / (p1.X - p2.X)
12 let b = -(p2.X * p1.Y - p1.X * p2.Y) / (p1.X - p2.X)
13 Line(a, b)
14
15 let inline pointFromTwoLines (l1: Line) (l2: Line) : PointD =
16 let x = -(l1.B - l2.B) / (l1.A - l2.A)
17 let y = -(l2.A * l1.B - l1.A * l2.B) / (l1.A - l2.A)
18 PointD(x, y)
19
20 let inline linePassThroughSegment (l: Line) (p1: PointD) (p2: PointD) : bool =
21 let p = pointFromTwoLines l (lineFromTwoPoints p1 p2)
22 sign (p.X - p1.X) <> sign (p.X - p2.X)
23
24 let inline squaredDistanceTwoPoints (p1: PointD) (p2: PointD) =
25 (p1.X - p2.X) ** 2.f + (p1.Y - p2.Y) ** 2.f
26
27 let inline distanceTwoPoints (p1: PointD) (p2: PointD) =
28 squaredDistanceTwoPoints p1 p2 |> sqrt
29
30 let countCells (cells: Cell list) : int * int =
31 cells |> List.fold (fun (total, infected) { cellClass = cellClass } ->
32 match cellClass with
33 | HealthyRBC -> (total + 1, infected)
34 | InfectedRBC -> (total + 1, infected + 1)
35 | Peculiar -> (total, infected)) (0, 0)