X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FUtils.fs;h=6a1333756457656aa38ab0b5df0809eede73a046;hp=2af692dd02d62948e82e4f7c74cdd962d17232de;hb=2d712781def419c9acc98368f7102b19b064f16d;hpb=97c24aa168f06f507fdff79429038d78a2c33326 diff --git a/Parasitemia/ParasitemiaCore/Utils.fs b/Parasitemia/ParasitemiaCore/Utils.fs index 2af692d..6a13337 100644 --- a/Parasitemia/ParasitemiaCore/Utils.fs +++ b/Parasitemia/ParasitemiaCore/Utils.fs @@ -1,6 +1,7 @@ module ParasitemiaCore.Utils open System +open System.Drawing open Types @@ -9,29 +10,32 @@ let inline roundInt v = v |> round |> int let inline dprintfn fmt = Printf.ksprintf System.Diagnostics.Debug.WriteLine fmt -let inline lineFromTwoPoints (p1: PointF) (p2: PointF) : Line = +let inline lineFromTwoPoints (p1 : PointF) (p2 : PointF) : 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) + Line (a, b) -let inline pointFromTwoLines (l1: Line) (l2: Line) : PointF = +let inline pointFromTwoLines (l1 : Line) (l2 : Line) : PointF = let x = -(l1.B - l2.B) / (l1.A - l2.A) let y = -(l2.A * l1.B - l1.A * l2.B) / (l1.A - l2.A) - PointF(x, y) + PointF (x, y) -let inline linePassThroughSegment (l: Line) (p1: PointF) (p2: PointF) : bool = +let inline linePassThroughSegment (l : Line) (p1 : PointF) (p2 : PointF) : bool = let p = pointFromTwoLines l (lineFromTwoPoints p1 p2) sign (p.X - p1.X) <> sign (p.X - p2.X) -let inline squaredDistanceTwoPoints (p1: PointF) (p2: PointF) = +let inline squaredDistanceTwoPoints (p1 : PointF) (p2 : PointF) = (p1.X - p2.X) ** 2.f + (p1.Y - p2.Y) ** 2.f -let inline distanceTwoPoints (p1: PointF) (p2: PointF) = +let inline distanceTwoPoints (p1 : PointF) (p2 : PointF) = 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 +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