Move SSD detected cell filtering to typed Kotlin

ober

42e7101c83cbc02ecf2eee31aff2a96e385ebae4

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index e1478e5..35b3c5c 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -489,6 +489,7 @@
                 ssdSessionFindCellById ssdSessionCellsByIds
                 ssdSessionBBoxForCellIds ssdSessionRecomputeGroup
                 appendUniqueCellIdsToGroup
+                ssdSessionAddDetectedCellsInsideArea
                 ssdSessionBoundedSsdArea ssdAreaSelectionTooSmall
                 ssdSessionStoreSsdArea ssdSessionSsdAreaOutsideCount
                 ssdSessionSetSsdArea ssdSessionPruneGroupsOutsideSsdArea
@@ -750,6 +751,16 @@
                 (begin
                   (mutable-list-add! out (nullable-get cell))
                   out)))))
+        (def (ssdSessionAddDetectedCellsInsideArea (session : SsdSession)
+                                                   (cells : (List SsdCell))) : Int32
+          (for/fold ((added (int32 0)))
+                    ((i (in-range (int32 0) (list-size cells))))
+            (let ((cell (list-ref cells i)))
+              (if (ssdSessionCellInsideSsdArea session cell)
+                (begin
+                  (mutable-list-add! (SsdSession-cells session) cell)
+                  (+ added (int32 1)))
+                added))))
         (def (ssdSessionGroupCells (session : SsdSession)
                                    (group : SsdGroup)) : (MutableList SsdCell)
           (for/fold ((out (mutable-list-empty SsdCell)))
@@ -4108,7 +4119,7 @@
        "                        detectedCells = SsdDetector.detectCells(bitmap)"
        "                        detectorSource = if (forceDetect && existingTruthGroupCount > 0) \"forced-android-plus-truth\" else \"android-fallback\""
        "                    }"
-       "                    session.cells.addAll(detectedCells.filter { ssdSessionCellInsideSsdArea(session, it) })"
+       "                    ssdSessionAddDetectedCellsInsideArea(session, detectedCells)"
        "                    session.groups.addAll(initialGroups(session.cells).take(120))"
        "                    if (existingTruth != null && existingTruthGroupCount > 0) {"
        "                        truthStore.applyTruth(session)"