X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FEEOver.fs;h=6862dc523d09f80039b4054f3bae69ecb83bcfbd;hb=bb642da712542095d8c5ead2d0d036470eb040b9;hp=a1358e99cf4a027e87e66dc0de9712d012685730;hpb=4bfa3cbdc6145e6944f02e24829ab2ef3a851ac1;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/EEOver.fs b/Parasitemia/ParasitemiaCore/EEOver.fs index a1358e9..6862dc5 100644 --- a/Parasitemia/ParasitemiaCore/EEOver.fs +++ b/Parasitemia/ParasitemiaCore/EEOver.fs @@ -1,8 +1,9 @@ -module ParasitemiaCore.EEOver +// Translation from https://github.com/chraibi/EEOver. +module ParasitemiaCore.EEOver open System -let private EPS = 1.0e-5 +let private EPS = 1.0e-7 let inline private ellipse2tr (x: float) (y: float) (aa: float) (bb: float) (cc: float) (dd: float) (ee: float) (ff: float) : float = aa * x * x + bb * x * y + cc * y * y + dd * x + ee * y + ff @@ -207,7 +208,6 @@ let private threeintpts (xint: float[]) (yint: float[]) (a1: float) (b1: float) () twointpts xint yint a1 b1 phi_1 a2 b2 h2_tr k2_tr phi_2 aa bb cc dd ee ff - let private fourintpts (xint: float[]) (yint: float[]) (a1: float) (b1: float) (phi_1: float) (a2: float) (b2: float) (h2_tr: float) (k2_tr: float) (phi_2: float) (aa: float) (bb: float) (cc: float) (dd: float) (ee: float) (ff: float) : float = let a1b1 = a1 * b1 let a2b2 = a2 * b2 @@ -301,28 +301,28 @@ let private fourintpts (xint: float[]) (yint: float[]) (a1: float) (b1: float) ( if area5 < 0.0 then #if DEBUG_LOG - printf "\n\t\t-------------> area5 is negativ (%f). Add: pi*A2*B2=%f <------------\n" area5 area_2 + printf "\n\t\t-------------> area5 is negative (%f). Add: pi*A2*B2=%f <------------\n" area5 area_2 #endif area5 <- area5 + area_2 if area4 < 0.0 then #if DEBUG_LOG - printf "\n\t\t-------------> area4 is negativ (%f). Add: pi*A2*B2=%f <------------\n" area4 area_2 + printf "\n\t\t-------------> area4 is negative (%f). Add: pi*A2*B2=%f <------------\n" area4 area_2 #endif area4 <- area4 + area_2 if area3 < 0.0 then #if DEBUG_LOG - printf "\n\t\t-------------> area3 is negativ (%f). Add: pi*A2*B2=%f <------------\n" area3 area_1 + printf "\n\t\t-------------> area3 is negative (%f). Add: pi*A2*B2=%f <------------\n" area3 area_1 #endif area3 <- area3 + area_1 if area2 < 0.0 then #if DEBUG_LOG - printf "\n\t\t-------------> area2 is negativ (%f). Add: pi*A2*B2=%f <------------\n" area2 area_1 + printf "\n\t\t-------------> area2 is negative (%f). Add: pi*A2*B2=%f <------------\n" area2 area_1 #endif area2 <- area2 + area_1 @@ -509,7 +509,9 @@ let private biquadroots (p: float[]) (r: float[,]) = quad () -// Return a tuple (area, x intersections, y intersections) +/// +/// Return a tuple (area, x intersections, y intersections). +/// let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float32 * float32[] * float32[]) option = let h1, k1, a1, b1, phi_1 = float e1.Cx, float e1.Cy, float e1.A, float e1.B, float e1.Alpha let h2, k2, a2, b2, phi_2 = float e2.Cx, float e2.Cy, float e2.A, float e2.B, float e2.Alpha @@ -518,8 +520,8 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float32 * float32[] then None else - let phi_1 = phi_1 % Math.PI //(if phi_1 > Math.PI / 2.0 then phi_1 - Math.PI else phi_1) % Math.PI - let phi_2 = phi_2 % Math.PI //(if phi_2 > Math.PI / 2.0 then phi_2 - Math.PI else phi_2) % Math.PI + let phi_1 = phi_1 % Math.PI + let phi_2 = phi_2 % Math.PI let h2_tr, k2_tr, phi_2r = let cosphi = cos phi_1 let sinphi = sin phi_1 @@ -647,8 +649,8 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float32 * float32[] let x2 = -x1 #if DEBUG_LOG - printf "\tx1=%f, y1=%f, A=%f. B=%f ---> ellipse2tr(x1)= %f\n" x1 ychk.[i] a1 b1 (ellipse2tr x1 ychk.[i] aa bb cc dd ee ff) - printf "\tx2=%f, y1=%f, A=%f. B=%f ---> ellipse2tr(x2) %f\n" x2 ychk.[i] a1 b1 (ellipse2tr x2 ychk.[i] aa bb cc dd ee ff) + printf "\n\tx1=%f, y1=%f, A=%f. B=%f ---> ellipse2tr(x1)= %f\n" x1 ychk.[i] a1 b1 (ellipse2tr x1 ychk.[i] aa bb cc dd ee ff) + printf "\tx2=%f, y1=%f, A=%f. B=%f ---> ellipse2tr(x2)= %f\n" x2 ychk.[i] a1 b1 (ellipse2tr x2 ychk.[i] aa bb cc dd ee ff) #endif if abs (ellipse2tr x1 ychk.[i] aa bb cc dd ee ff) < EPS @@ -690,7 +692,6 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float32 * float32[] #endif i <- i + 1 - if returnValue = -1.0 then None @@ -713,8 +714,13 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float32 * float32[] | 3 -> threeintpts xint yint a1 b1 phi_1 a2 b2 h2_tr k2_tr phi_2 aa bb cc dd ee ff | 4 -> fourintpts xint yint a1 b1 phi_1 a2 b2 h2_tr k2_tr phi_2 aa bb cc dd ee ff | _ -> -1.0 - if nintpts = 0 - then Some (float32 area, [||], [||]) + + if area = -1.0 + then + None + elif nintpts = 0 + then + Some (float32 area, [||], [||]) else let xTransform : float32[] = Array.zeroCreate nintpts let yTransform : float32[] = Array.zeroCreate nintpts