geojson 3.0.1 → 3.0.2
raw patch · 7 files changed
+74/−72 lines, 7 filesdep −vectorPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: vector
API changes (from Hackage documentation)
- Data.LineString: SingletonVector :: VectorToLineStringError
- Data.LineString: VectorEmpty :: VectorToLineStringError
- Data.LineString: data VectorToLineStringError
- Data.LineString: instance GHC.Classes.Eq Data.LineString.VectorToLineStringError
- Data.LineString: instance GHC.Show.Show Data.LineString.VectorToLineStringError
- Data.LinearRing: VectorTooShort :: Int -> VectorToLinearRingError a
- Data.LinearRing: data VectorToLinearRingError a
- Data.LinearRing: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.LinearRing.VectorToLinearRingError a)
- Data.LinearRing: instance GHC.Show.Show a => GHC.Show.Show (Data.LinearRing.VectorToLinearRingError a)
+ Data.LineString: SequenceEmpty :: SequenceToLineStringError
+ Data.LineString: SingletonSequence :: SequenceToLineStringError
+ Data.LineString: data SequenceToLineStringError
+ Data.LineString: instance GHC.Classes.Eq Data.LineString.SequenceToLineStringError
+ Data.LineString: instance GHC.Show.Show Data.LineString.SequenceToLineStringError
+ Data.LinearRing: SequenceTooShort :: Int -> SequenceToLinearRingError a
+ Data.LinearRing: data SequenceToLinearRingError a
+ Data.LinearRing: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.LinearRing.SequenceToLinearRingError a)
+ Data.LinearRing: instance GHC.Show.Show a => GHC.Show.Show (Data.LinearRing.SequenceToLinearRingError a)
- Data.LineString: fromSeq :: (Validate v) => Seq a -> v VectorToLineStringError (LineString a)
+ Data.LineString: fromSeq :: (Validate v) => Seq a -> v SequenceToLineStringError (LineString a)
- Data.LinearRing: FirstNotEqualToLast :: a -> a -> VectorToLinearRingError a
+ Data.LinearRing: FirstNotEqualToLast :: a -> a -> SequenceToLinearRingError a
- Data.LinearRing: fromSeq :: (Eq a, Show a, Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => Seq a -> v (NonEmpty (VectorToLinearRingError a)) (LinearRing a)
+ Data.LinearRing: fromSeq :: (Eq a, Show a, Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => Seq a -> v (NonEmpty (SequenceToLinearRingError a)) (LinearRing a)
Files
- CHANGELOG.md +6/−0
- geojson.cabal +2/−4
- src/Data/LineString.hs +19/−19
- src/Data/LinearRing.hs +13/−13
- src/Data/SeqHelper.hs +0/−2
- test/Data/LineStringTests.hs +16/−16
- test/Data/LinearRingTests.hs +18/−18
CHANGELOG.md view
@@ -1,3 +1,9 @@+# 3.0.x++## 2.0.0 -> 3.0.2++- Switch to using `Data.Sequence` instead of `Data.Vector.Storable`. + # 2.0.x ## 1.3.3 -> 2.0.0
geojson.cabal view
@@ -1,5 +1,5 @@ name: geojson-version: 3.0.1+version: 3.0.2 license: BSD3 license-file: LICENCE author: Dom De Re@@ -27,7 +27,7 @@ source-repository this type: git location: https://github.com/indicatrix/hs-geojson.git- tag: 3.0.1+ tag: 3.0.2 library hs-source-dirs: src@@ -41,7 +41,6 @@ , scientific >= 0.2.0 , transformers >= 0.3 , validation >= 1- , vector >= 0.10 exposed-modules: Data.Geospatial , Data.LinearRing , Data.LineString@@ -76,7 +75,6 @@ , tasty-quickcheck , text >= 1.2 , validation >= 1- , vector >= 0.10 other-modules: Arbitrary , Fixture , Data.LinearRingTests
src/Data/LineString.hs view
@@ -17,7 +17,7 @@ -- * Type LineString , ListToLineStringError(..)- , VectorToLineStringError(..)+ , SequenceToLineStringError(..) -- * Functions , toSeq , combineToSeq@@ -63,14 +63,14 @@ deriving (Eq) -- |--- When converting a Vector to a LineString, here is a list of things that can go wrong:+-- When converting a Sequence to a LineString, here is a list of things that can go wrong: ----- * The vector was empty--- * The vector only had one element+-- * The sequence was empty+-- * The sequence only had one element ---data VectorToLineStringError =- VectorEmpty- | SingletonVector+data SequenceToLineStringError =+ SequenceEmpty+ | SingletonSequence deriving (Eq) -- functions@@ -111,7 +111,7 @@ -- | -- create a sequence from a LineString by combining values.--- LineString 1 2 [3,4] (,) --> Vector [(1,2),(2,3),(3,4)]+-- LineString 1 2 [3,4] (,) --> Sequence [(1,2),(2,3),(3,4)] -- combineToSeq :: (a -> a -> b) -> LineString a -> Sequence.Seq b combineToSeq combine (LineString a b rest) = combine a b Sequence.<| combineRest@@ -126,7 +126,7 @@ -- | -- create a sequence from a LineString.--- LineString 1 2 [3,4] --> Vector [1,2,3,4]+-- LineString 1 2 [3,4] --> Sequence [1,2,3,4] -- toSeq :: LineString a -> Sequence.Seq a toSeq (LineString a b rest) = a Sequence.<| ( b Sequence.<| rest)@@ -136,22 +136,22 @@ -- creates a LineString out of a sequence of elements, -- if there are enough elements (needs at least 2) elements ---fromSeq :: (Validation.Validate v) => Sequence.Seq a -> v VectorToLineStringError (LineString a)+fromSeq :: (Validation.Validate v) => Sequence.Seq a -> v SequenceToLineStringError (LineString a) fromSeq v@(headS Sequence.:<| tailS) = if Sequence.null v then- Validation._Failure # SingletonVector+ Validation._Failure # SingletonSequence else fromSeq' headS tailS-fromSeq _ = Validation._Failure # VectorEmpty+fromSeq _ = Validation._Failure # SequenceEmpty {-# INLINE fromSeq #-} -fromSeq' :: (Validation.Validate v) => a -> Sequence.Seq a -> v VectorToLineStringError (LineString a)+fromSeq' :: (Validation.Validate v) => a -> Sequence.Seq a -> v SequenceToLineStringError (LineString a) fromSeq' first v@(headS Sequence.:<| tailS) = if Sequence.null v then- Validation._Failure # SingletonVector+ Validation._Failure # SingletonSequence else Validation._Success # LineString first headS tailS-fromSeq' _ _ = Validation._Failure # SingletonVector+fromSeq' _ _ = Validation._Failure # SingletonSequence {-# INLINE fromSeq' #-} -- |@@ -171,9 +171,9 @@ show ListEmpty = "List Empty" show SingletonList = "Singleton List" -instance Show VectorToLineStringError where- show VectorEmpty = "Vector Empty"- show SingletonVector = "Singleton Vector"+instance Show SequenceToLineStringError where+ show SequenceEmpty = "Sequence Empty"+ show SingletonSequence = "Singleton Sequence" instance (Show a) => Show (LineString a) where show = show . fromLineString@@ -210,7 +210,7 @@ parseError :: Value -> Maybe ListToLineStringError -> Parser b parseError v = maybe mzero (\e -> typeMismatch (show e) v) --- safeLast :: (VectorStorable.Storable a) => Sequence.Seq a -> Maybe a+-- safeLast :: (Sequence.Seq a) => Sequence.Seq a -> Maybe a -- safeLast x = if Sequence.null x then Nothing else Just $ Sequence.last x safeLast :: Sequence.Seq a -> Maybe a safeLast x = case Sequence.viewr x of
src/Data/LinearRing.hs view
@@ -19,7 +19,7 @@ -- * Type LinearRing , ListToLinearRingError(..)- , VectorToLinearRingError(..)+ , SequenceToLinearRingError(..) -- * Functions , toSeq , combineToSeq@@ -72,13 +72,13 @@ deriving (Eq) -- |--- When converting a Vector to a LinearRing there are some things that can go wrong+-- When converting a Sequence to a LinearRing there are some things that can go wrong ----- * The vector can be too short+-- * The sequence can be too short -- * The head may not be equal to the last element in the list ---data VectorToLinearRingError a =- VectorTooShort Int+data SequenceToLinearRingError a =+ SequenceTooShort Int | FirstNotEqualToLast a a deriving (Eq) @@ -133,7 +133,7 @@ -- | -- create a sequence from a LinearRing by combining values.--- LinearRing 1 2 3 [4,1] (,) --> Vector [(1,2),(2,3),(3,4),(4,1)]+-- LinearRing 1 2 3 [4,1] (,) --> Seq [(1,2),(2,3),(3,4),(4,1)] -- combineToSeq :: (a -> a -> b) -> LinearRing a -> Sequence.Seq b combineToSeq combine (LinearRing a b c rest) = combine a b Sequence.:<| (combine b c Sequence.:<| combineRest)@@ -148,19 +148,19 @@ -- | -- create a sequence from a LinearRing.--- LinearRing 1 2 3 [4,1] --> Vector [1,2,3,4,1)]+-- LinearRing 1 2 3 [4,1] --> Seq [1,2,3,4,1)] -- toSeq :: LinearRing a -> Sequence.Seq a toSeq (LinearRing a b c rest) = a Sequence.:<| (b Sequence.:<| (c Sequence.:<| rest)) {-# INLINE toSeq #-} -- |--- creates a LinearRing out of a vector of elements,+-- creates a LinearRing out of a sequence of elements, -- if there are enough elements (needs at least 3) elements -- -- fromSeq (x:y:z:ws@(_:_)) = _Success # LinearRing x y z (fromListDropLast ws) -- fromSeq xs = _Failure # return (ListTooShort (length xs))-fromSeq :: (Eq a, Show a, Validation.Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => Sequence.Seq a -> v (NonEmpty (VectorToLinearRingError a)) (LinearRing a)+fromSeq :: (Eq a, Show a, Validation.Validate v, Functor (v (NonEmpty (ListToLinearRingError a)))) => Sequence.Seq a -> v (NonEmpty (SequenceToLinearRingError a)) (LinearRing a) fromSeq as = case as of (first Sequence.:<| (second Sequence.:<| (third Sequence.:<| rest@(_ Sequence.:|> lastS)))) ->@@ -173,8 +173,8 @@ Validation._Success # LinearRing first second third Sequence.empty else Validation._Failure # pure (FirstNotEqualToLast first third)- v -> Validation._Failure # pure (VectorTooShort (Sequence.length v))- _ -> Validation._Failure # pure (VectorTooShort 0)+ v -> Validation._Failure # pure (SequenceTooShort (Sequence.length v))+ _ -> Validation._Failure # pure (SequenceTooShort 0) {-# INLINE fromSeq #-} -- |@@ -199,8 +199,8 @@ show (ListTooShort n) = "List too short: (length = " ++ show n ++ ")" show (HeadNotEqualToLast h l) = "head (" ++ show h ++ ") /= last(" ++ show l ++ ")" -instance (Show a) => Show (VectorToLinearRingError a) where- show (VectorTooShort n) = "Vector too short: (length = " ++ show n ++ ")"+instance (Show a) => Show (SequenceToLinearRingError a) where+ show (SequenceTooShort n) = "Sequence too short: (length = " ++ show n ++ ")" show (FirstNotEqualToLast h l) = "head (" ++ show h ++ ") /= last(" ++ show l ++ ")" instance Functor LinearRing where
src/Data/SeqHelper.hs view
@@ -4,8 +4,6 @@ -- Copyright : (C) 2014-2018 HS-GeoJSON Project -- License : BSD-style (see the file LICENSE.md) -- Maintainer : Andrew Newman------ see Section 2.1.1 /Position/ in the GeoJSON Spec ------------------------------------------------------------------- module Data.SeqHelper ( sequenceHead
test/Data/LineStringTests.hs view
@@ -29,9 +29,9 @@ specTests = do specs <- sequence [ testSpec "Data.LineString.fromList" testFromList- , testSpec "Data.LineString.fromSeq" testFromVector- , testSpec "Data.LineString.toSeq" testToVector- , testSpec "Data.LineString.combineToVector" testCombineToVector+ , testSpec "Data.LineString.fromSeq" testFromSequence+ , testSpec "Data.LineString.toSeq" testToSequence+ , testSpec "Data.LineString.combineToSequence" testCombineToSequence ] pure $ testGroup "Data.LineStringTests.Spec" specs @@ -83,30 +83,30 @@ LineString.fromList ([] :: [Int]) `shouldBe` Failure LineString.ListEmpty LineString.fromList ([0] :: [Int]) `shouldBe` Failure LineString.SingletonList -testFromVector :: Spec-testFromVector =- describe "fromVector" $ do- it "creates a LineString out of a Vector of elements" $ do+testFromSequence :: Spec+testFromSequence =+ describe "fromSeq" $ do+ it "creates a LineString out of a Sequence of elements" $ do LineString.fromSeq (Sequence.fromList [0, 1] :: (Sequence.Seq Int)) `shouldBe` Success (LineString.makeLineString 0 1 Sequence.empty) LineString.fromSeq (Sequence.fromList [0, 1, 2] :: (Sequence.Seq Int)) `shouldBe` Success (LineString.makeLineString 0 1 (Sequence.fromList [2])) LineString.fromSeq (Sequence.fromList [0, 1, 2, 4, 5, 0] :: (Sequence.Seq Int)) `shouldBe` Success (LineString.makeLineString 0 1 (Sequence.fromList [2, 4, 5, 0])) context "when provided with invalid input" $ it "fails" $ do- LineString.fromSeq (Sequence.fromList [] :: (Sequence.Seq Int)) `shouldBe` Failure LineString.VectorEmpty- LineString.fromSeq (Sequence.fromList [0] :: (Sequence.Seq Int)) `shouldBe` Failure LineString.SingletonVector+ LineString.fromSeq (Sequence.fromList [] :: (Sequence.Seq Int)) `shouldBe` Failure LineString.SequenceEmpty+ LineString.fromSeq (Sequence.fromList [0] :: (Sequence.Seq Int)) `shouldBe` Failure LineString.SingletonSequence -testCombineToVector :: Spec-testCombineToVector =- describe "combineToVector" $+testCombineToSequence :: Spec+testCombineToSequence =+ describe "combineToSeq" $ it "combine a LineString using PointXY" $ do LineString.combineToSeq BasicTypes.PointXY (LineString.makeLineString 0 1 Sequence.empty) `shouldBe` Sequence.fromList [BasicTypes.PointXY 0 1] LineString.combineToSeq BasicTypes.PointXY (LineString.makeLineString 0 1 (Sequence.fromList [2])) `shouldBe` Sequence.fromList [BasicTypes.PointXY 0 1, BasicTypes.PointXY 1 2] LineString.combineToSeq BasicTypes.PointXY (LineString.makeLineString 0 1 (Sequence.fromList [2, 4, 5, 0])) `shouldBe` Sequence.fromList [BasicTypes.PointXY 0 1, BasicTypes.PointXY 1 2, BasicTypes.PointXY 2 4, BasicTypes.PointXY 4 5, BasicTypes.PointXY 5 0] -testToVector :: Spec-testToVector =- describe "toVector" $- it "from a LineString to a vector" $ do+testToSequence :: Spec+testToSequence =+ describe "toSeq" $+ it "from a LineString to a Sequence" $ do LineString.toSeq (LineString.makeLineString 0 1 Sequence.empty) `shouldBe` Sequence.fromList ([0, 1] :: [Int]) LineString.toSeq (LineString.makeLineString 0 1 (Sequence.fromList [2])) `shouldBe` Sequence.fromList ([0, 1, 2] :: [Int]) LineString.toSeq (LineString.makeLineString 0 1 (Sequence.fromList [2, 4, 5, 0])) `shouldBe` Sequence.fromList ([0, 1, 2, 4, 5, 0] :: [Int])
test/Data/LinearRingTests.hs view
@@ -31,9 +31,9 @@ specTests = do specs <- sequence [ testSpec "Data.LinearRing.fromList" testFromList- , testSpec "Data.LinearRing.fromSeq" testFromVector- , testSpec "Data.LinearRing.combineToVector" testCombineToVector- , testSpec "Data.LinearRing.testToVector" testToVector+ , testSpec "Data.LinearRing.fromSeq" testFromSequence+ , testSpec "Data.LinearRing.combineToSequence" testCombineToSequence+ , testSpec "Data.LinearRing.testToSequence" testToSequence ] pure $ testGroup "Data.LinearRingTests.Spec" specs @@ -97,33 +97,33 @@ LinearRing.fromList [0, 1] `shouldBe` Validation.Failure (LinearRing.ListTooShort 2 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.ListToLinearRingError Int)) LinearRing.fromList [0, 1, 2] `shouldBe` Validation.Failure (LinearRing.ListTooShort 3 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.ListToLinearRingError Int)) -testFromVector :: Spec-testFromVector =- describe "fromVector" $ do- it "creates a LinearRing out of a vector of elements" $ do+testFromSequence :: Spec+testFromSequence =+ describe "fromSeq" $ do+ it "creates a LinearRing out of a Sequence of elements" $ do LinearRing.fromSeq (Sequence.fromList ([0, 1, 0] :: [Int])) `shouldBe` Validation.Success (LinearRing.makeLinearRing 0 1 0 Sequence.empty) LinearRing.fromSeq (Sequence.fromList ([0, 1, 2, 0] :: [Int])) `shouldBe` Validation.Success (LinearRing.makeLinearRing 0 1 2 (Sequence.fromList [0])) LinearRing.fromSeq (Sequence.fromList ([0, 1, 2, 4, 0] :: [Int])) `shouldBe` Validation.Success (LinearRing.makeLinearRing 0 1 2 (Sequence.fromList [4, 0])) LinearRing.fromSeq (Sequence.fromList ([0, 1, 2, 4, 5, 0]:: [Int])) `shouldBe` Validation.Success (LinearRing.makeLinearRing 0 1 2 (Sequence.fromList [4, 5, 0])) context "when provided with invalid input" $ it "fails" $ do- LinearRing.fromSeq (Sequence.fromList []) `shouldBe` Validation.Failure (LinearRing.VectorTooShort 0 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.VectorToLinearRingError Int))- LinearRing.fromSeq (Sequence.fromList [0]) `shouldBe` Validation.Failure (LinearRing.VectorTooShort 1 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.VectorToLinearRingError Int))- LinearRing.fromSeq (Sequence.fromList [0, 1]) `shouldBe` Validation.Failure (LinearRing.VectorTooShort 2 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.VectorToLinearRingError Int))- LinearRing.fromSeq (Sequence.fromList [0, 1, 2]) `shouldBe` Validation.Failure (LinearRing.FirstNotEqualToLast 0 2 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.VectorToLinearRingError Int))+ LinearRing.fromSeq (Sequence.fromList []) `shouldBe` Validation.Failure (LinearRing.SequenceTooShort 0 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.SequenceToLinearRingError Int))+ LinearRing.fromSeq (Sequence.fromList [0]) `shouldBe` Validation.Failure (LinearRing.SequenceTooShort 1 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.SequenceToLinearRingError Int))+ LinearRing.fromSeq (Sequence.fromList [0, 1]) `shouldBe` Validation.Failure (LinearRing.SequenceTooShort 2 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.SequenceToLinearRingError Int))+ LinearRing.fromSeq (Sequence.fromList [0, 1, 2]) `shouldBe` Validation.Failure (LinearRing.FirstNotEqualToLast 0 2 ListNonEmpty.:| [] :: ListNonEmpty.NonEmpty (LinearRing.SequenceToLinearRingError Int)) -testCombineToVector :: Spec-testCombineToVector =- describe "combineToVector" $+testCombineToSequence :: Spec+testCombineToSequence =+ describe "combineToSeq" $ it "combine a LinearRing using tuples" $ do LinearRing.combineToSeq BasicTypes.PointXY (LinearRing.makeLinearRing 0 1 2 Sequence.empty) `shouldBe` Sequence.fromList [BasicTypes.PointXY 0 1, BasicTypes.PointXY 1 2] LinearRing.combineToSeq BasicTypes.PointXY (LinearRing.makeLinearRing 0 1 2 (Sequence.fromList [4])) `shouldBe` Sequence.fromList [BasicTypes.PointXY 0 1, BasicTypes.PointXY 1 2, BasicTypes.PointXY 2 4] LinearRing.combineToSeq BasicTypes.PointXY (LinearRing.makeLinearRing 0 1 2 (Sequence.fromList [4,5])) `shouldBe` Sequence.fromList [BasicTypes.PointXY 0 1, BasicTypes.PointXY 1 2, BasicTypes.PointXY 2 4, BasicTypes.PointXY 4 5] -testToVector :: Spec-testToVector =- describe "toVector" $- it "from a LinearRing to a vector" $ do+testToSequence :: Spec+testToSequence =+ describe "toSeq" $+ it "from a LinearRing to a Sequence" $ do LinearRing.toSeq (LinearRing.makeLinearRing 0 1 0 Sequence.empty) `shouldBe` Sequence.fromList ([0, 1, 0] :: [Int]) LinearRing.toSeq (LinearRing.makeLinearRing 0 1 2 (Sequence.fromList [0])) `shouldBe` Sequence.fromList ([0, 1, 2, 0] :: [Int]) LinearRing.toSeq (LinearRing.makeLinearRing 0 1 2 (Sequence.fromList [4,0])) `shouldBe` Sequence.fromList ([0, 1, 2, 4, 0] :: [Int])