packages feed

numhask-space 0.11.0.1 → 0.11.1.0

raw patch · 10 files changed

+150/−162 lines, 10 filesdep ~containersdep ~distributivedep ~numhask

Dependency ranges changed: containers, distributive, numhask, random, semigroupoids, text, vector

Files

ChangeLog.md view
@@ -1,3 +1,8 @@+0.11.1.0+===+* Rect and Point show instances include negative brackets.+* removed NegativeLiterals as a requirement.+ 0.11.0.0 === * fixes for numhask-0.11
LICENSE view
@@ -1,4 +1,4 @@-Copyright Tony Day (c) 2016+Copyright (c) 2016, Tony Day  All rights reserved. 
numhask-space.cabal view
@@ -1,122 +1,120 @@-cabal-version:      3.0-name:               numhask-space-version:            0.11.0.1-synopsis:           Numerical spaces.+cabal-version: 3.0+name: numhask-space+version: 0.11.1.0+license: BSD-3-Clause+license-file: LICENSE+copyright: Tony Day (c) 2016+category: math+author: Tony Day+maintainer: tonyday567@gmail.com+homepage: https://github.com/tonyday567/numhask-space#readme+bug-reports: https://github.com/tonyday567/numhask-space/issues+synopsis: Numerical spaces. description:-  @numhask-space@ provides support for spaces where [space](https://en.wikipedia.org/wiki/Space_(mathematics\)) is defined as a set of numbers with a lower and upper bound.+    @numhask-space@ provides support for spaces where [space](https://en.wikipedia.org/wiki/Space_(mathematics\)) is defined as a set of numbers with a lower and upper bound. -  == Usage+    == Usage -  >>> {-# LANGUAGE RebindableSyntax #-}-  >>> import NumHask.Prelude-  >>> import NumHask.Space+    >>> {-# LANGUAGE RebindableSyntax #-}+    >>> import NumHask.Prelude+    >>> import NumHask.Space  -category:           mathematics-homepage:           https://github.com/tonyday567/numhask-space#readme-bug-reports:        https://github.com/tonyday567/numhask-space/issues-author:             Tony Day-maintainer:         tonyday567@gmail.com-copyright:          Tony Day-license:            BSD-3-Clause-license-file:       LICENSE-build-type:         Simple-tested-with:-  GHC ==8.10.7 || ==9.2.8 || ==9.4.5 || ==9.6.2+build-type: Simple+tested-with: GHC ==8.10.7 || ==9.2.8 || ==9.4.5 || ==9.6.2 extra-doc-files: ChangeLog.md  source-repository head-  type:     git-  location: https://github.com/tonyday567/numhask-space+    type: git+    location: https://github.com/tonyday567/numhask-space +common ghc-options-stanza+    ghc-options:+        -Wall+        -Wcompat+        -Widentities+        -Wincomplete-record-updates+        -Wincomplete-uni-patterns+        -Wpartial-fields+        -Wredundant-constraints+ common ghc2021-stanza-  if impl(ghc >=9.2)-    default-language:-      GHC2021-  if impl(ghc <9.2)-    default-language:-      Haskell2010-    default-extensions:-      BangPatterns-      BinaryLiterals-      ConstrainedClassMethods-      ConstraintKinds-      DeriveDataTypeable-      DeriveFoldable-      DeriveFunctor-      DeriveGeneric-      DeriveLift-      DeriveTraversable-      DoAndIfThenElse-      EmptyCase-      EmptyDataDecls-      EmptyDataDeriving-      ExistentialQuantification-      ExplicitForAll-      FlexibleContexts-      FlexibleInstances-      ForeignFunctionInterface-      GADTSyntax-      GeneralisedNewtypeDeriving-      HexFloatLiterals-      ImplicitPrelude-      InstanceSigs-      KindSignatures-      MonomorphismRestriction-      MultiParamTypeClasses-      NamedFieldPuns-      NamedWildCards-      NumericUnderscores-      PatternGuards-      PolyKinds-      PostfixOperators-      RankNTypes-      RelaxedPolyRec-      ScopedTypeVariables-      StandaloneDeriving-      StarIsType-      TraditionalRecordSyntax-      TupleSections-      TypeApplications-      TypeOperators-      TypeSynonymInstances-  if impl(ghc <9.2) && impl(ghc >=8.10)-    default-extensions:-      ImportQualifiedPost-      StandaloneKindSignatures+    if impl ( ghc >= 9.2 )+        default-language: GHC2021 -common ghc-options-stanza-  ghc-options:-    -Wall-    -Wcompat-    -Wincomplete-record-updates-    -Wincomplete-uni-patterns-    -Wredundant-constraints-    -Widentities-    -Wpartial-fields+    if impl ( ghc < 9.2 )+        default-language: Haskell2010+        default-extensions:+            BangPatterns+            BinaryLiterals+            ConstrainedClassMethods+            ConstraintKinds+            DeriveDataTypeable+            DeriveFoldable+            DeriveFunctor+            DeriveGeneric+            DeriveLift+            DeriveTraversable+            DoAndIfThenElse+            EmptyCase+            EmptyDataDecls+            EmptyDataDeriving+            ExistentialQuantification+            ExplicitForAll+            FlexibleContexts+            FlexibleInstances+            ForeignFunctionInterface+            GADTSyntax+            GeneralisedNewtypeDeriving+            HexFloatLiterals+            ImplicitPrelude+            InstanceSigs+            KindSignatures+            MonomorphismRestriction+            MultiParamTypeClasses+            NamedFieldPuns+            NamedWildCards+            NumericUnderscores+            PatternGuards+            PolyKinds+            PostfixOperators+            RankNTypes+            RelaxedPolyRec+            ScopedTypeVariables+            StandaloneDeriving+            StarIsType+            TraditionalRecordSyntax+            TupleSections+            TypeApplications+            TypeOperators+            TypeSynonymInstances -library-  import: ghc2021-stanza-  import: ghc-options-stanza-  hs-source-dirs: src-  build-depends:-    , adjunctions    >=4.0 && <5-    , base           >=4.7 && <5-    , containers     ^>=0.6-    , distributive   >=0.2.2 && <1-    , numhask        >=0.11 && <0.12-    , random         ^>=1.2-    , semigroupoids  >=5 && <6.1-    , tdigest        >=0.2.1 && <0.4-    , text           >=1.2.3.1 && <3-    , time           >=1.9.1 && <1.13-    , vector         >=0.12 && <0.14+    if impl ( ghc < 9.2 ) && impl ( ghc >= 8.10 )+        default-extensions:+            ImportQualifiedPost+            StandaloneKindSignatures -  exposed-modules:-    NumHask.Space-    NumHask.Space.Histogram-    NumHask.Space.Point-    NumHask.Space.Range-    NumHask.Space.Rect-    NumHask.Space.Time-    NumHask.Space.Types+library+    import: ghc-options-stanza+    import: ghc2021-stanza+    hs-source-dirs: src+    build-depends:+        , adjunctions   >=4.0 && <5+        , base          >=4.7 && <5+        , containers    >=0.6 && <0.8+        , distributive  >=0.4 && <0.7+        , numhask       >=0.10 && <0.13+        , random        >=1.2 && <1.3+        , semigroupoids >=5.3 && <6.1+        , tdigest       >=0.2.1 && <0.4+        , text          >=1.2 && <2.2+        , time          >=1.9.1 && <1.13+        , vector        >=0.12.3 && <0.14+    exposed-modules:+        NumHask.Space+        NumHask.Space.Histogram+        NumHask.Space.Point+        NumHask.Space.Range+        NumHask.Space.Rect+        NumHask.Space.Time+        NumHask.Space.Types
src/NumHask/Space.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE NegativeLiterals #-} {-# LANGUAGE RebindableSyntax #-}  -- | Mathematics does not rigorously define a [space](https://en.wikipedia.org/wiki/Space_(mathematics\)), leaving library devs free to explore.@@ -63,14 +62,3 @@ -- - A time span is a 'Space' containing moments of time. -- -- - A 'Histogram' is a divided 'Range' with a count of elements within each division.---- $extensions--- > :t Point 1.0 -1.0--- Point 1.0 -1.0---   :: (Subtractive a, FromRatio a Integer,---       FromRatio (a -> Point a) Integer) =>---      a -> Point a------ > :set -XNegativeLiterals--- > :t Point 1.0 -1.0--- Point 1.0 -1.0 :: FromRatio a Integer => Point a
src/NumHask/Space/Histogram.hs view
@@ -29,6 +29,7 @@ import NumHask.Space.Types  -- $setup+-- >>> :set -XRebindableSyntax -- >>> import NumHask.Prelude -- >>> import NumHask.Space 
src/NumHask/Space/Point.hs view
@@ -31,9 +31,9 @@ import System.Random.Stateful  -- $setup+-- >>> :set -XRebindableSyntax -- >>> import NumHask.Prelude -- >>> import NumHask.Space--- >>> :set -XFlexibleContexts  -- | A 2-dimensional Point of a's --@@ -62,17 +62,16 @@   }   deriving (Eq, Generic) -instance (Show a) => Show (Point a) where-  show (Point a b) = "Point " <> show a <> " " <> show b--instance Functor Point where-  fmap f (Point a b) = Point (f a) (f b)- instance Eq1 Point where   liftEq f (Point a b) (Point c d) = f a c && f b d -instance Show1 Point where-  liftShowsPrec sp _ d (Point a b) = showsBinaryWith sp sp "Point" d a b+instance (Ord a, Additive a, Show a) => Show (Point a) where+  show (Point a b) = "Point " <> wrap a <> " " <> wrap b+    where+      wrap x = bool (show x) ("(" <> show x <> ")") (x < zero)++instance Functor Point where+  fmap f (Point a b) = Point (f a) (f b)  instance Applicative Point where   pure a = Point a a
src/NumHask/Space/Range.hs view
@@ -20,7 +20,6 @@ -- $setup -- -- >>> :set -XFlexibleContexts--- >>> :set -XGADTs -- >>> import NumHask.Prelude -- >>> import NumHask.Space @@ -57,14 +56,11 @@ data Range a = Range a a   deriving (Eq, Generic) -instance (Show a) => Show (Range a) where-  show (Range a b) = "Range " <> show a <> " " <> show b- instance Eq1 Range where   liftEq f (Range a b) (Range c d) = f a c && f b d -instance Show1 Range where-  liftShowsPrec sp _ d (Range a b) = showsBinaryWith sp sp "Range" d a b+instance (Show a) => Show (Range a) where+  show (Range a b) = "Range " <> show a <> " " <> show b  instance Functor Range where   fmap f (Range a b) = Range (f a) (f b)
src/NumHask/Space/Rect.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE NegativeLiterals #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE RebindableSyntax #-} {-# LANGUAGE TypeFamilies #-}@@ -36,27 +35,27 @@  -- $setup ----- >>> :set -XFlexibleContexts+-- >>> :set -XRebindableSyntax -- >>> import NumHask.Prelude -- >>> import NumHask.Space  -- | a rectangular space often representing a finite 2-dimensional or XY plane. -- -- >>> one :: Rect Double--- Rect -0.5 0.5 -0.5 0.5+-- Rect (-0.5) 0.5 (-0.5) 0.5 -- -- >>> zero :: Rect Double -- Rect 0.0 0.0 0.0 0.0 -- -- >>> one + one :: Rect Double--- Rect -1.0 1.0 -1.0 1.0+-- Rect (-1.0) 1.0 (-1.0) 1.0 -- -- >>> let a = Rect (-1.0) 1.0 (-2.0) 4.0 -- >>> a--- Rect -1.0 1.0 -2.0 4.0+-- Rect (-1.0) 1.0 (-2.0) 4.0 -- -- >>> a * one--- Rect -1.0 1.0 -2.0 4.0+-- Rect (-1.0) 1.0 (-2.0) 4.0 -- -- >>> let (Ranges x y) = a -- >>> x@@ -69,7 +68,7 @@ -- as a Space instance with Points as Elements -- -- >>> project (Rect 0.0 1.0 (-1.0) 0.0) (Rect 1.0 4.0 10.0 0.0) (Point 0.5 1.0)--- Point 2.5 -10.0+-- Point 2.5 (-10.0) -- >>> gridSpace (Rect 0.0 10.0 0.0 1.0) (Point (2::Int) (2::Int)) -- [Rect 0.0 5.0 0.0 0.5,Rect 0.0 5.0 0.5 1.0,Rect 5.0 10.0 0.0 0.5,Rect 5.0 10.0 0.5 1.0] -- >>> grid MidPos (Rect 0.0 10.0 0.0 1.0) (Point (2::Int) (2::Int))@@ -97,9 +96,11 @@  {-# COMPLETE Ranges #-} -instance (Show a) => Show (Rect a) where+instance (Ord a, Additive a, Show a) => Show (Rect a) where   show (Rect a b c d) =-    "Rect " <> show a <> " " <> show b <> " " <> show c <> " " <> show d+    "Rect " <> wrap a <> " " <> wrap b <> " " <> wrap c <> " " <> wrap d+    where+      wrap x = bool (show x) ("(" <> show x <> ")") (x < zero)  instance Distributive Rect where   collect f x =@@ -179,14 +180,14 @@ -- | create a list of points representing the lower left and upper right corners of a rectangle. -- -- >>> corners one--- [Point -0.5 -0.5,Point 0.5 0.5]+-- [Point (-0.5) (-0.5),Point 0.5 0.5] corners :: (Ord a) => Rect a -> [Point a] corners r = [lower r, upper r]  -- | the 4 corners -- -- >>> corners4 one--- [Point -0.5 -0.5,Point -0.5 0.5,Point 0.5 -0.5,Point 0.5 0.5]+-- [Point (-0.5) (-0.5),Point (-0.5) 0.5,Point 0.5 (-0.5),Point 0.5 0.5] corners4 :: Rect a -> [Point a] corners4 (Rect x z y w) =   [ Point x y,@@ -212,9 +213,9 @@     (Point a' c') = project r0 r1 (Point a c)     (Point b' d') = project r0 r1 (Point b d) --- | Numeric algebra based on interval arithmetioc for addition and unitRect and projection for multiplication+-- | Numeric algebra based on interval arithmetic for addition and unitRect and projection for multiplication -- >>> one + one :: Rect Double--- Rect -1.0 1.0 -1.0 1.0+-- Rect (-1.0) 1.0 (-1.0) 1.0 instance (Additive a) => Additive (Rect a) where   (+) (Rect a b c d) (Rect a' b' c' d') =     Rect (a + a') (b + b') (c + c') (d + d')@@ -241,7 +242,7 @@ -- | convex hull union of Rect's -- -- >>> foldRect [Rect 0 1 0 1, one]--- Just Rect -0.5 1.0 -0.5 1.0+-- Just Rect (-0.5) 1.0 (-0.5) 1.0 foldRect :: (Ord a) => [Rect a] -> Maybe (Rect a) foldRect [] = Nothing foldRect (x : xs) = Just $ sconcat (x :| xs)@@ -249,21 +250,21 @@ -- | convex hull union of Rect's applied to a non-empty structure -- -- >>> foldRectUnsafe [Rect 0 1 0 1, one]--- Rect -0.5 1.0 -0.5 1.0+-- Rect (-0.5) 1.0 (-0.5) 1.0 foldRectUnsafe :: (Foldable f, Ord a) => f (Rect a) -> Rect a foldRectUnsafe = foldr1 (<>)  -- | add a Point to a Rect -- -- >>> addPoint (Point 0 1) one--- Rect -0.5 0.5 0.5 1.5+-- Rect (-0.5) 0.5 0.5 1.5 addPoint :: (Additive a) => Point a -> Rect a -> Rect a addPoint (Point x' y') (Rect x z y w) = Rect (x + x') (z + x') (y + y') (w + y')  -- | rotate the corners of a Rect by x degrees relative to the origin, and fold to a new Rect -- -- >>> rotationBound (pi/4) one--- Rect -0.7071067811865475 0.7071067811865475 -0.7071067811865475 0.7071067811865475+-- Rect (-0.7071067811865475) 0.7071067811865475 (-0.7071067811865475) 0.7071067811865475 rotationBound :: (TrigField a, Ord a) => a -> Rect a -> Rect a rotationBound d = unsafeSpace1 . fmap (rotate d |.) . corners4 @@ -286,14 +287,14 @@ -- | convert a ratio (eg x:1) to a Rect with a height of one. -- -- >>> aspect 2--- Rect -1.0 1.0 -0.5 0.5+-- Rect (-1.0) 1.0 (-0.5) 0.5 aspect :: Double -> Rect Double-aspect a = Rect (a * -0.5) (a * 0.5) -0.5 0.5+aspect a = Rect (a * (-0.5)) (a * 0.5) (-0.5) 0.5  -- | convert a Rect to a ratio -- -- >>> :set -XNegativeLiterals--- >>> ratio (Rect -1 1 -0.5 0.5)+-- >>> ratio (Rect (-1) 1 (-0.5) 0.5) -- 2.0 ratio :: (Field a) => Rect a -> a ratio (Rect x z y w) = (z - x) / (w - y)@@ -301,7 +302,7 @@ -- | project a Rect from one Rect to another, preserving relative position, with guards for singleton Rects. -- -- >>> projectOnR one (Rect 0 1 0 1) (Rect 0 0.5 0 0.5)--- Rect -0.5 0.0 -0.5 0.0+-- Rect (-0.5) 0.0 (-0.5) 0.0 projectOnR :: Rect Double -> Rect Double -> Rect Double -> Rect Double projectOnR new old@(Rect x z y w) ao@(Rect ox oz oy ow)   | x == z && y == w = ao@@ -314,7 +315,7 @@ -- | project a Point from one Rect to another, preserving relative position, with guards for singleton Rects. -- -- >>> projectOnP one (Rect 0 1 0 1) zero--- Point -0.5 -0.5+-- Point (-0.5) (-0.5) projectOnP :: Rect Double -> Rect Double -> Point Double -> Point Double projectOnP new old@(Rect x z y w) po@(Point px py)   | x == z && y == w = po
src/NumHask/Space/Time.hs view
@@ -29,13 +29,11 @@  -- $setup --+-- >>> :set -XRebindableSyntax -- >>> import NumHask.Prelude -- >>> import NumHask.Space--- >>> import NumHask.Space.Time -- >>> import Data.Text (Text, pack) -- >>> import Data.Time------ > :set -XOverloadedStrings  -- | a step in time data TimeGrain
src/NumHask/Space/Types.hs view
@@ -44,6 +44,7 @@ import Prelude qualified as P  -- $setup+-- >>> :set -XRebindableSyntax -- >>> import NumHask.Prelude -- >>> import NumHask.Space -- >>> import System.Random.Stateful@@ -200,6 +201,7 @@ -- > unsafeSpace1 (grid OuterPos s g) == s -- > getUnion (sconcat (Union <$> (gridSpace s g))) == s class (Space s, Field (Element s)) => FieldSpace s where+  -- | the type that divides or quotients the space   type Grid s :: Type    -- | create equally-spaced elements across a space