From ca3801a90a4a3a455b4d550e77b43be3e4c955f7 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Sun, 9 Jul 2023 00:05:38 -0700 Subject: [PATCH] Planar direction subtype --- src/Swarm/Game/Location.hs | 2 +- src/Swarm/Language/Syntax.hs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Swarm/Game/Location.hs b/src/Swarm/Game/Location.hs index c9b69b7d7d..203f87f52b 100644 --- a/src/Swarm/Game/Location.hs +++ b/src/Swarm/Game/Location.hs @@ -44,7 +44,7 @@ import Data.Map qualified as M import Data.Yaml (FromJSON (parseJSON), ToJSON (toJSON)) import Linear (Additive (..), V2 (..), negated, norm, perp, unangle) import Linear.Affine (Affine (..), Point (..), origin) -import Swarm.Language.Syntax (AbsoluteDir (..), Direction (..), RelativeDir (..), PlanarRelativeDir (..), isCardinal) +import Swarm.Language.Syntax (AbsoluteDir (..), Direction (..), PlanarRelativeDir (..), RelativeDir (..), isCardinal) import Swarm.Util qualified as Util -- $setup diff --git a/src/Swarm/Language/Syntax.hs b/src/Swarm/Language/Syntax.hs index 899a09c279..31288b1dd9 100644 --- a/src/Swarm/Language/Syntax.hs +++ b/src/Swarm/Language/Syntax.hs @@ -157,6 +157,8 @@ instance FromJSONKey AbsoluteDir where data RelativeDir = DPlanar PlanarRelativeDir | DDown deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON) +-- | Caution: Do not alter this ordering, as there exist functions that depend on it +-- (e.g. "nearestDirection" and "relativeTo"). data PlanarRelativeDir = DForward | DLeft | DBack | DRight deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON, Enum, Bounded) @@ -165,7 +167,7 @@ data PlanarRelativeDir = DForward | DLeft | DBack | DRight data Direction = DAbsolute AbsoluteDir | DRelative RelativeDir deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON) --- | Direction name is generated from Direction data constuctor +-- | Direction name is generated from Direction data constructor -- e.g. DLeft becomes "left" directionSyntax :: Direction -> Text directionSyntax d = toLower . T.tail . from $ case d of