Add generic derivations and To/FromJSON instances

This commit is contained in:
2022-07-25 22:49:18 +01:00
parent f5604ef429
commit b8e8413daa
99 changed files with 1406 additions and 517 deletions
+7 -1
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE BangPatterns #-}
module Geometry.ConvexPoly
@@ -10,6 +11,8 @@ module Geometry.ConvexPoly
, convexPolysOverlap
, pointInPolyPoints
) where
import GHC.Generics
import Data.Aeson
import Geometry.Data
import Geometry.Vector
import Geometry.LHS
@@ -23,7 +26,10 @@ data ConvexPoly = ConvexPoly
, _cpCen :: Point2
, _cpRad :: Float
}
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON ConvexPoly where
toEncoding = genericToEncoding defaultOptions
instance FromJSON ConvexPoly
pointsToPoly :: [Point2] -> ConvexPoly
pointsToPoly xs = ConvexPoly
{ _cpPoints = xs
+18
View File
@@ -1,3 +1,9 @@
{-# 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 (..)
@@ -5,13 +11,25 @@ module Geometry.Data
, 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)