From 79c15e2e8649bd9bb2a4149235128d64d7d708f1 Mon Sep 17 00:00:00 2001 From: Robbie Gleichman Date: Sat, 24 Dec 2016 16:05:15 -0800 Subject: [PATCH] Reflect the angles of the inner icons for nestedGuardPortAngles. --- app/Icons.hs | 50 ++++++++++++++++++++++++++++++++---------------- app/Rendering.hs | 2 +- todo.md | 2 -- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app/Icons.hs b/app/Icons.hs index d964774..7333151 100644 --- a/app/Icons.hs +++ b/app/Icons.hs @@ -16,8 +16,9 @@ module Icons import Diagrams.Prelude hiding ((&), (#), Name) import Data.List(find) -import Data.Maybe(catMaybes, listToMaybe) +import Data.Maybe(catMaybes, listToMaybe, isJust, fromJust) import Data.Either(partitionEithers) +import qualified Control.Arrow as Arrow import Types(Icon(..), SpecialQDiagram, SpecialBackend, SpecialNum, NodeName, Port(..), LikeApplyFlavor(..)) import DrawingColors(colorScheme, ColorStyle(..)) @@ -77,36 +78,51 @@ guardPortAngles (Port port) = case port of findNestedIcon :: NodeName -> Icon -> Maybe Icon findNestedIcon name icon = case icon of - NestedApply _ args -> findIcon name args - NestedPApp args -> findIcon name args + NestedApply _ args -> snd <$> findIcon name args + NestedPApp args -> snd <$> findIcon name args _ -> Nothing -findIcon :: NodeName -> [Maybe (NodeName, Icon)] -> Maybe Icon +findIcon :: NodeName -> [Maybe (NodeName, Icon)] -> Maybe (Int, Icon) findIcon name args = icon where - filteredArgs = catMaybes args - nameMatches (n, _) = n == name - icon = case filteredArgs of - [] -> Nothing - _ -> case find nameMatches filteredArgs of - Nothing -> listToMaybe $ catMaybes $ fmap (findNestedIcon name . snd) filteredArgs - Just (_, finalIcon) -> Just finalIcon + numberedArgs = zip ([0,1..] :: [Int]) args + filteredArgs = Arrow.second fromJust <$> filter (isJust . snd) numberedArgs + nameMatches (_, (n, _)) = n == name + icon = case find nameMatches filteredArgs of + Nothing -> listToMaybe $ catMaybes $ fmap findSubSubIcon filteredArgs + Just (argNum, (_, finalIcon)) -> Just (argNum, finalIcon) + where + findSubSubIcon (argNum, (_, icon)) = case findNestedIcon name icon of + Nothing -> Nothing + Just x -> Just (argNum, x) -nestedApplyPortAngles :: Floating n => [Maybe (NodeName, Icon)] -> Port -> Maybe NodeName -> [Angle n] +nestedApplyPortAngles :: SpecialNum n => [Maybe (NodeName, Icon)] -> Port -> Maybe NodeName -> [Angle n] nestedApplyPortAngles args port maybeNodeName = case maybeNodeName of Nothing -> applyPortAngles port Just name -> case findIcon name args of Nothing -> [] - Just icon -> getPortAngles icon port Nothing + Just (argNum, icon) -> getPortAngles icon port Nothing + +reflectXAngle :: SpecialNum n => Angle n -> Angle n +reflectXAngle x = reflectedAngle where + normalizedAngle = normalizeAngle x + reflectedAngle = (-) <$> halfTurn <*> normalizedAngle -- TODO reflect the angles for the right side sub-icons -nestedGuardPortAngles :: Floating n => [Maybe (NodeName, Icon)] -> Port -> Maybe NodeName -> [Angle n] -nestedGuardPortAngles args port maybeNodeName = case maybeNodeName of +nestedGuardPortAngles :: SpecialNum n => [Maybe (NodeName, Icon)] -> Port -> Maybe NodeName -> [Angle n] +nestedGuardPortAngles args port@(Port portInt) maybeNodeName = case maybeNodeName of Nothing -> guardPortAngles port Just name -> case findIcon name args of Nothing -> [] - Just icon -> getPortAngles icon port Nothing + -- TODO Don't use hardcoded numbers + -- The arguments correspond to ports [0, 2, 3, 4 ...] + Just (argNum, icon) -> if odd argNum && argNum >= 1 + -- The icon will be reflected + then fmap reflectXAngle subAngles + else subAngles --fmap reflectXAngle subAngles + where + subAngles = getPortAngles icon port Nothing -getPortAngles :: (Floating n) => Icon -> Port -> Maybe NodeName -> [Angle n] +getPortAngles :: SpecialNum n => Icon -> Port -> Maybe NodeName -> [Angle n] getPortAngles icon port maybeNodeName = case icon of ApplyAIcon _ -> applyPortAngles port ComposeIcon _ -> applyPortAngles port diff --git a/app/Rendering.hs b/app/Rendering.hs index 3074c24..ec66a93 100644 --- a/app/Rendering.hs +++ b/app/Rendering.hs @@ -134,7 +134,7 @@ nameAndPortToName (NameAndPort name mPort) = case mPort of Nothing -> toName name Just port -> name .> port -findPortAngles :: Floating n => (NodeName, Icon) -> NameAndPort -> [Angle n] +findPortAngles :: SpecialNum n => (NodeName, Icon) -> NameAndPort -> [Angle n] findPortAngles (nodeName, nodeIcon) (NameAndPort diaName mPort) = case mPort of Nothing -> [] Just port -> foundAngles where diff --git a/todo.md b/todo.md index 84a4afa..5964a49 100644 --- a/todo.md +++ b/todo.md @@ -1,8 +1,6 @@ # Todo ## Todo Now -* Reflect the angles of the inner icons for nestedGuardPortAngles - * Change the PApp icon so that from left to right it looks like: list of args, constructor name, result. If there is only one arg, then the arg port can have an additional angle of (1/2 turn). * Consider adding binding variable names to the lambda icon and match icon. Don't display the name if it is only one character.