Fix some approximation issues.
[master-thesis.git] / Parasitemia / ParasitemiaCore / EEOver.fs
index a1358e9..7db9687 100644 (file)
@@ -2,7 +2,7 @@
 
 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
@@ -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
 
@@ -518,8 +518,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 +647,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
@@ -713,8 +713,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