Tweak use location

This commit is contained in:
2025-06-30 01:02:27 +01:00
parent d88aed10c7
commit 8a00450e3f
9 changed files with 226 additions and 210 deletions
+41 -20
View File
@@ -1,47 +1,67 @@
--{-# 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
module Geometry.Data (
module Geometry.Data,
V2 (..),
V3 (..),
V4 (..),
) where
import Data.Aeson
import qualified Linear.Quaternion as Q
import Linear.V2
import Linear.V3
import Linear.V4
type Int2 = V2 Int
type Int2 = V2 Int
type Point2 = V2 Float
instance ToJSON a => ToJSON (V2 a) where
toEncoding = genericToEncoding defaultOptions
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
toEncoding = genericToEncoding defaultOptions
instance FromJSON a => FromJSON (V3 a)
type Point4 = V4 Float
instance ToJSON a => ToJSON (V4 a) where
toEncoding = genericToEncoding defaultOptions
toEncoding = genericToEncoding defaultOptions
instance FromJSON a => FromJSON (V4 a)
type DPoint2 = (Point2,Float)
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
type QFloat = Q.Quaternion Float
fromV3 :: V3 a -> (a,a,a)
fromV3 (V3 a b c) = (a,b,c)
type Point3Q = (Point3, QFloat)
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 #-}
@@ -49,5 +69,6 @@ uncurryV f (V2 x y) = f x y
fstV2 :: V2 a -> a
fstV2 (V2 x _) = x
sndV2 :: V2 a -> a
sndV2 (V2 _ x) = x