--{-# LANGUAGE DeriveGeneric #-} {-# OPTIONS_GHC -fno-warn-orphans #-} {- | WARNING: orphan instances concerning Aeson classes and Linear.Vx datatypes have been introduced. The warnings have been disabled. -} module Geometry.Data ( module Geometry.Data , V2 (..) , V3 (..) , V4 (..) ) where import Data.Aeson import Linear.V2 import Linear.V3 import Linear.V4 type Int2 = V2 Int type Point2 = V2 Float instance ToJSON a => ToJSON (V2 a) where toEncoding = genericToEncoding defaultOptions instance FromJSON a => FromJSON (V2 a) instance ToJSON a => ToJSONKey (V2 a) instance FromJSON a => FromJSONKey (V2 a) type Point3 = V3 Float instance ToJSON a => ToJSON (V3 a) where toEncoding = genericToEncoding defaultOptions instance FromJSON a => FromJSON (V3 a) type Point4 = V4 Float instance ToJSON a => ToJSON (V4 a) where toEncoding = genericToEncoding defaultOptions instance FromJSON a => FromJSON (V4 a) type DPoint2 = (Point2,Float) toV2 :: (a,a) -> V2 a toV2 (a,b) = V2 a b toV3 :: (a,a,a) -> V3 a toV3 (a,b,c) = V3 a b c toV4 :: (a,a,a,a) -> V4 a toV4 (a,b,c,d) = V4 a b c d fromV3 :: V3 a -> (a,a,a) fromV3 (V3 a b c) = (a,b,c) uncurryV :: (a -> a -> b) -> V2 a -> b {-# INLINE uncurryV #-} uncurryV f (V2 x y) = f x y fstV2 :: V2 a -> a fstV2 (V2 x _) = x sndV2 :: V2 a -> a sndV2 (V2 _ x) = x