X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FUtils.fs;h=d6fa2f0b7f60eda2cbe068df73746f41b280b8e2;hp=de166647bcc389add7c347196e66a453ce0b1f4b;hb=e76da913cd58078ad2479357b2430ed62a6e0777;hpb=d9a6e072ecf299db691c05bb559a71265f812ba3 diff --git a/Parasitemia/Parasitemia/Utils.fs b/Parasitemia/Parasitemia/Utils.fs index de16664..d6fa2f0 100644 --- a/Parasitemia/Parasitemia/Utils.fs +++ b/Parasitemia/Parasitemia/Utils.fs @@ -2,6 +2,8 @@ open System.Diagnostics +open Types + let roundInt = int << round let inline dprintfn fmt = @@ -16,4 +18,27 @@ let logTime (m: string) (f: unit -> 'a) : 'a = let res = f () sw.Stop() log <| sprintf "%A (time: %A ms)" m sw.ElapsedMilliseconds - res \ No newline at end of file + res + +let inline lineFromTwoPoints (p1: PointD) (p2: PointD) : Line = + let a = (p1.Y - p2.Y) / (p1.X - p2.X) + let b = -(p2.X * p1.Y - p1.X * p2.Y) / (p1.X - p2.X) + Line(a, b) + +let inline pointFromTwoLines (l1: Line) (l2: Line) : PointD = + let x = -(l1.B - l2.B) / (l1.A - l2.A) + let y = -(l2.A * l1.B - l1.A * l2.B) / (l1.A - l2.A) + PointD(x, y) + +let inline squaredDistanceTwoPoints (p1: PointD) (p2: PointD) = + (p1.X - p2.X) ** 2.0 + (p1.Y - p2.Y) ** 2.0 + +let distanceTwoPoints (p1: PointD) (p2: PointD) = + squaredDistanceTwoPoints p1 p2 |> sqrt + +let countCells (cells: Cell list) : int * int = + cells |> List.fold (fun (total, infected) { cellClass = cellClass } -> + match cellClass with + | HealthyRBC -> (total + 1, infected) + | InfectedRBC -> (total + 1, infected + 1) + | Peculiar -> (total, infected)) (0, 0) \ No newline at end of file