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