Work on selection sets

This commit is contained in:
2026-05-13 15:33:57 +01:00
parent 9df23c27c2
commit 2d731ae1ba
5 changed files with 311 additions and 242 deletions
+30
View File
@@ -8,6 +8,9 @@ module Dodge.SelectionSections (
inverseSelSecYint,
posSelSecYint,
inverseSelNumPos,
ssLookupGE,
ssLookupLE,
sssSelectionSlice,
) where
import Control.Applicative
@@ -149,6 +152,22 @@ ssLookupGT' i sss = do
Just (j', si) -> return (i', j', si)
Nothing -> ssLookupGT' i' sss
ssLookupGE :: XInfinity (Int,Int) -> IMSS a -> Maybe (Int,Int,SelectionItem a)
ssLookupGE x sss = case x of
NegInf -> ssLookupMin sss
PosInf -> Nothing
NonInf (i,j) -> case sss ^? ix i . ssItems . ix j of
Nothing -> ssLookupGT i j sss
Just s -> Just (i,j,s)
ssLookupLE :: XInfinity (Int,Int) -> IMSS a -> Maybe (Int,Int,SelectionItem a)
ssLookupLE x sss = case x of
NegInf -> Nothing
PosInf -> ssLookupMax sss
NonInf (i,j) -> case sss ^? ix i . ssItems . ix j of
Nothing -> ssLookupLT i j sss
Just s -> Just (i,j,s)
ssLookupGE' :: Int -> IMSS a -> Maybe (Int, Int, SelectionItem a)
ssLookupGE' i sss = do
(i', ss) <- IM.lookupGE i sss
@@ -213,3 +232,14 @@ inverseSelSecYintXPosCheck cfig ldp x yint sss = do
inverseSelNumPos :: Config -> LDParams -> Point2 -> IMSS a -> Maybe (XInfinity (Int, Int))
inverseSelNumPos cfig ldp (V2 x y) =
inverseSelSecYintXPosCheck cfig ldp x (posSelSecYint cfig ldp y)
sssSelectionSlice :: IMSS a -> XInfinity (Int,Int) -> XInfinity (Int,Int) -> IMSS a
sssSelectionSlice sss x1 x2 = fromMaybe mempty $ do
let (xmin,xmax) | x1 < x2 = (x1,x2)
| otherwise = (x2,x1)
(mini,minj,_) <- ssLookupGE xmin sss
(maxi,maxj,_) <- ssLookupLE xmax sss
return $ fst (IM.split (maxi+1) . snd $ IM.split (mini-1) sss)
& ix mini . ssItems %~ snd . IM.split (minj-1)
& ix maxi . ssItems %~ fst . IM.split (maxj+1)