Move SSD selection snap policy to typed Kotlin

ober

f1a83d9178aa2802abbe4c2c2777a96d621e2c18

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 3395c45..afdcfa2 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -1175,7 +1175,8 @@
                 rotatedDisplayWidth rotatedDisplayHeight
                 rotatedDisplayWidthFloat rotatedDisplayHeightFloat
                 viewportCenterOffsetDelta nextRotationDegrees
-                touchMoveExceeded)
+                touchMoveExceeded shouldCollectSelectionMatches
+                selectionUsesRawRect selectionHasMatches)
         (type Int32)
         (type Float32)
         (type FloatArray)
@@ -1200,6 +1201,12 @@
             (begin
               (mutable-list-add! ids (SsdCell-id (list-ref cells i)))
               ids)))
+        (def (shouldCollectSelectionMatches (snapSelectionToCells : Bool)) : Bool
+          snapSelectionToCells)
+        (def (selectionUsesRawRect (snapSelectionToCells : Bool)) : Bool
+          (not snapSelectionToCells))
+        (def (selectionHasMatches (matchingCount : Int32)) : Bool
+          (> matchingCount (int32 0)))
         (def (clampFloat32 (value : Float32)
                            (minimum : Float32)
                            (maximum : Float32)) : Float32
@@ -7397,10 +7404,10 @@
 	       "            onStatus?.invoke(\"Selection ignored: drag a larger area\")"
 	       "            return"
 	       "        }"
-	       "        val matching = if (snapSelectionToCells) selectionMatchingCells(sess.cells, rect) else mutableListOf()"
-	       "        val snapped = if (!snapSelectionToCells) {"
+	       "        val matching = if (shouldCollectSelectionMatches(snapSelectionToCells)) selectionMatchingCells(sess.cells, rect) else mutableListOf()"
+	       "        val snapped = if (selectionUsesRawRect(snapSelectionToCells)) {"
 	       "            rect"
-	       "        } else if (matching.isNotEmpty()) {"
+	       "        } else if (selectionHasMatches(matching.size)) {"
 	       "            bboxForCells(matching)"
        "        } else {"
        "            bitmap?.let {"