Skip to content

Commit ddc7d45

Browse files
authored
Merge pull request #219 from noinia/rename->hgeom
Rename new modules not on hackage to HGeometry.<name of module>
2 parents 137ef77 + f39e63b commit ddc7d45

File tree

39 files changed

+186
-168
lines changed

39 files changed

+186
-168
lines changed

hgeometry-combinatorial/changelog.org

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
core-only value of type ~c~ and an ~Ext~.
99
- Added an ~AsExt~ class that to capture types that can be decomposed
1010
(and recomposed) into an ~Ext~.
11-
- Added ~Data.Ratio.Generalized~ that implements Ratio but supports
11+
- Added ~HGeometry.Number.Ratio.Generalized~ that implements Ratio but supports
1212
types that are not ~Integral~.
13-
- A ~Data.RealNumber.Symbolic~ type that represents numbers with a
13+
- A ~HGeometry.Number.Real.Symbolic~ type that represents numbers with a
1414
symbolic pertubation. Useful for Simulation of Simplicity.
1515
- Dropped the ~CanAquire~ module.
1616
- Explicit export list for ~Data.Permutation~.
17-
- Added the ~Data.Sign~ and ~Data.Indexed~ modules.
17+
- Added the ~HGeometry.Sign~ and ~HGeometry.Indexed~ modules.
1818
- Support mtl 2.3
19-
- Added ~Data.Radical~ for types that support computing square roots.
20-
- Added ~Data.Foldable.Sort~ which has a faster sort implementation
19+
- Added ~HGeometry.Number.Radical~ for types that support computing square roots.
20+
- Added ~HGeometry.Foldable.Sort~ which has a faster sort implementation
2121
(that will take any Foldable and return an Vector.)
22-
- Added ~Data.Cyclic~ and ~Data.Vector.NonEmpty~ modules.
22+
- Added ~HGeometry.Cyclic~ and ~HGeometry.Vector.NonEmpty~ modules.
2323
- Added Uniform and UniformRange instances for ~Ext~.
2424
- Removed ~Data.PlanarGraph.Mutable~, ~Data.PlanarGraph.Persistent~,
2525
and ~Data.PlanarGraph.Immutable~, since they were note used anyway.

hgeometry-combinatorial/doctests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ modules =
7171
, "Data.Double.Approximate"
7272
, "Data.Double.Shaman"
7373

74-
, "Data.RealNumber.Symbolic"
74+
, "HGeometry.Number.Real.Symbolic"
7575
]

hgeometry-combinatorial/hgeometry-combinatorial.cabal

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,16 @@ library
130130

131131
-- * Numeric Data Types
132132
Data.RealNumber.Rational
133-
Data.RealNumber.Symbolic
133+
134+
135+
HGeometry.Number.Real.Rational
136+
HGeometry.Number.Real.Symbolic
137+
134138
Data.Double.Approximate
135139
Data.Double.Shaman
136-
Data.Ratio.Generalized
137-
Data.Radical
140+
141+
HGeometry.Number.Ratio.Generalized
142+
HGeometry.Number.Radical
138143

139144
-- * Measurements
140145
Data.Measured
@@ -146,8 +151,10 @@ library
146151
Data.Intersection
147152
Data.Range
148153
Data.Ext
149-
Data.Sign
150-
Data.Indexed
154+
155+
156+
HGeometry.Sign
157+
HGeometry.Indexed
151158

152159
-- Data.Ext.Multi
153160

@@ -193,12 +200,12 @@ library
193200

194201
Data.Yaml.Util
195202

196-
Data.Foldable.Sort
197-
Data.Foldable.Util
203+
HGeometry.Foldable.Sort
204+
HGeometry.Foldable.Util
198205

199-
Data.Vector.NonEmpty.Util
206+
HGeometry.Vector.NonEmpty.Util
200207

201-
Data.Cyclic
208+
HGeometry.Cyclic
202209

203210
other-modules: Data.PlanarGraph.Internal
204211
Data.PlanarGraph.Core

hgeometry-combinatorial/src/Data/RealNumber/Rational.hs

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -6,96 +6,6 @@
66
-- License : see the LICENSE file
77
-- Maintainer : Frank Staals
88
--------------------------------------------------------------------------------
9-
module Data.RealNumber.Rational(RealNumber(..)
9+
module Data.RealNumber.Rational(module HGeometry.Number.Real.Rational) where
1010

11-
-- * Converting to and from RealNumber's
12-
, AsFixed(..), asFixed
13-
, toFixed, fromFixed
14-
, Nat
15-
) where
16-
17-
import Data.Aeson
18-
import Data.Data
19-
import Data.Fixed
20-
import Data.Hashable
21-
import Data.List (dropWhileEnd)
22-
import GHC.Generics (Generic (..))
23-
import GHC.TypeLits
24-
import Test.QuickCheck (Arbitrary (..))
25-
import Control.Monad.Random
26-
import Data.Ratio
27-
import Control.DeepSeq
28-
29-
--------------------------------------------------------------------------------
30-
31-
-- | Real Numbers represented using Rational numbers. The number type
32-
-- itself is exact in the sense that we can represent any rational
33-
-- number.
34-
--
35-
-- The parameter, a natural number, represents the precision (in
36-
-- number of decimals behind the period) with which we display the
37-
-- numbers when printing them (using Show).
38-
--
39-
-- If the number cannot be displayed exactly a '~' is printed after
40-
-- the number.
41-
newtype RealNumber (p :: Nat) = RealNumber Rational
42-
deriving (Eq,Ord,Data,Num,Fractional,Real,RealFrac,Generic,Hashable,ToJSON,FromJSON,NFData)
43-
44-
data NatPrec (p :: Nat) = NatPrec
45-
46-
instance KnownNat p => HasResolution (NatPrec p) where
47-
resolution _ = 10 ^ (natVal (NatPrec @p))
48-
49-
50-
instance KnownNat p => Show (RealNumber p) where
51-
showsPrec d r = showParen (d > app_prec && r < 0) $
52-
case asFixed r of
53-
Exact p -> showString (dropWhileEnd (== '.') . dropWhileEnd (== '0') . show $ p)
54-
Lossy p -> shows p . showChar '~'
55-
where
56-
app_prec = 10
57-
58-
instance KnownNat p => Read (RealNumber p) where
59-
readsPrec i = map wrap . readsPrec @(Fixed (NatPrec p)) i
60-
where
61-
wrap (RealNumber . realToFrac -> x,s') = case s' of
62-
'~':s'' -> (x,s'')
63-
_ -> (x,s')
64-
65-
instance KnownNat p => Arbitrary (RealNumber p) where
66-
arbitrary = fromFixed <$> arbitrary
67-
68-
69-
instance Random (RealNumber p) where
70-
-- Generate a random number between a and b with 'maxBound `div` 2 :: Int' discrete increments.
71-
randomR (a,b) = runRand $ do
72-
v <- getRandom
73-
pure $ (b-a)*abs v + a
74-
-- Generate a random number between -1 and +1 with 'maxBound::Int' discrete increments.
75-
random = runRand $ do
76-
v <- getRandom
77-
let fromInt :: Int -> Integer; fromInt = fromIntegral
78-
pure $ RealNumber $ fromInt v % fromInt maxBound
79-
80-
--------------------------------------------------------------------------------
81-
82-
83-
84-
-- | Fixed-precision representation of a 'RealNumber'. If there's insufficient
85-
-- precision to accurately represent the 'RealNumber' then the 'Lossy' constructor
86-
-- will be used.
87-
data AsFixed p = Exact !(Fixed p) | Lossy !(Fixed p) deriving (Show,Eq)
88-
89-
-- | Cast 'RealNumber' to a fixed-precision number. Data is silently lost if there's
90-
-- insufficient precision.
91-
toFixed :: KnownNat p => RealNumber p -> Fixed (NatPrec p)
92-
toFixed = realToFrac
93-
94-
-- | Cast a fixed-precision number to a 'RealNumber'.
95-
fromFixed :: KnownNat p => Fixed (NatPrec p) -> RealNumber p
96-
fromFixed = realToFrac
97-
98-
-- | Cast 'RealNumber' to a fixed-precision number. Data-loss caused by insufficient
99-
-- precision will be marked by the 'Lossy' constructor.
100-
asFixed :: KnownNat p => RealNumber p -> AsFixed (NatPrec p)
101-
asFixed r = let p = toFixed r in if r == fromFixed p then Exact p else Lossy p
11+
import HGeometry.Number.Real.Rational

hgeometry-combinatorial/src/Data/Cyclic.hs renamed to hgeometry-combinatorial/src/HGeometry/Cyclic.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE UndecidableInstances #-}
22
{-# LANGUAGE BangPatterns #-}
33
{-# LANGUAGE QuantifiedConstraints #-}
4-
module Data.Cyclic
4+
module HGeometry.Cyclic
55
( Cyclic(..)
66
, toCircularVector
77
) where
@@ -11,11 +11,11 @@ module Data.Cyclic
1111
import Control.DeepSeq (NFData)
1212
import Control.Lens
1313
import qualified Data.Foldable as F
14-
import Data.Foldable.Util
1514
import Data.Semigroup.Foldable
1615
import Data.Vector.Circular (CircularVector(..))
1716
import Data.Vector.NonEmpty (NonEmptyVector)
1817
import GHC.Generics (Generic)
18+
import HGeometry.Foldable.Util
1919
--------------------------------------------------------------------------------
2020

2121
-- | A cyclic sequence type

hgeometry-combinatorial/src/Data/Foldable/Sort.hs renamed to hgeometry-combinatorial/src/HGeometry/Foldable/Sort.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Data.Foldable.Sort
1+
module HGeometry.Foldable.Sort
22
( sortBy
33
, sort
44
, sortOnCheap

hgeometry-combinatorial/src/Data/Foldable/Util.hs renamed to hgeometry-combinatorial/src/HGeometry/Foldable/Util.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Data.Foldable.Util
1+
module HGeometry.Foldable.Util
22
( HasFromFoldable(..)
33
, HasFromFoldable1(..)
44
) where

hgeometry-combinatorial/src/Data/Indexed.hs renamed to hgeometry-combinatorial/src/HGeometry/Indexed.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{-# LANGUAGE ScopedTypeVariables #-}
22
--------------------------------------------------------------------------------
33
-- |
4-
-- Module : Data.Indexed
4+
-- Module : HGeometry.Indexed
55
-- Copyright : (C) Frank Staals
66
-- License : see the LICENSE file
77
-- Maintainer : Frank Staals
88
--
99
-- Things that have an index.
1010
--
1111
--------------------------------------------------------------------------------
12-
module Data.Indexed
12+
module HGeometry.Indexed
1313
( HasIndex(..)
1414
, Index
1515
, WithIndex(..), theValue

hgeometry-combinatorial/src/Data/Radical.hs renamed to hgeometry-combinatorial/src/HGeometry/Number/Radical.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{-# LANGUAGE DefaultSignatures #-}
22
--------------------------------------------------------------------------------
33
-- |
4-
-- Module : Data.Radical
4+
-- Module : HGeometry.Number.Radical
55
-- Copyright : (C) Frank Staals
66
-- License : see the LICENSE file
77
-- Maintainer : Frank Staals
88
--
99
-- Types that support computing Square roots
1010
--------------------------------------------------------------------------------
11-
module Data.Radical
11+
module HGeometry.Number.Radical
1212
( Radical(..)
1313
) where
1414

hgeometry-combinatorial/src/Data/Ratio/Generalized.hs renamed to hgeometry-combinatorial/src/HGeometry/Number/Ratio/Generalized.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
--------------------------------------------------------------------------------
22
-- |
3-
-- Module : Data.Ratio.Generalized
3+
-- Module : HGeometry.Number.Ratio.Generalized
44
-- Copyright : (C) Frank Staals
55
-- License : see the LICENSE file
66
-- Maintainer : Frank Staals
77
--
88
-- Generalized Ratio type that accepts arbitrary 'Num a' types rather
99
-- than just Integral ones as in Data.Ratio
1010
--------------------------------------------------------------------------------
11-
module Data.Ratio.Generalized
11+
module HGeometry.Number.Ratio.Generalized
1212
( GRatio
1313
, (%)
1414
, numerator, denominator
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{-# LANGUAGE DeriveDataTypeable #-}
2+
--------------------------------------------------------------------------------
3+
-- |
4+
-- Module : HGeometry.Number.Real.Rational
5+
-- Copyright : (C) Frank Staals
6+
-- License : see the LICENSE file
7+
-- Maintainer : Frank Staals
8+
--------------------------------------------------------------------------------
9+
module HGeometry.Number.Real.Rational(
10+
RealNumber(..)
11+
12+
-- * Converting to and from RealNumber's
13+
, AsFixed(..), asFixed
14+
, toFixed, fromFixed
15+
, Nat
16+
) where
17+
18+
import Control.DeepSeq
19+
import Control.Monad.Random
20+
import Data.Aeson
21+
import Data.Data
22+
import Data.Fixed
23+
import Data.Hashable
24+
import Data.List (dropWhileEnd)
25+
import Data.Ratio
26+
import GHC.Generics (Generic (..))
27+
import GHC.TypeLits
28+
import Test.QuickCheck (Arbitrary (..))
29+
30+
--------------------------------------------------------------------------------
31+
32+
-- | Real Numbers represented using Rational numbers. The number type
33+
-- itself is exact in the sense that we can represent any rational
34+
-- number.
35+
--
36+
-- The parameter, a natural number, represents the precision (in
37+
-- number of decimals behind the period) with which we display the
38+
-- numbers when printing them (using Show).
39+
--
40+
-- If the number cannot be displayed exactly a '~' is printed after
41+
-- the number.
42+
newtype RealNumber (p :: Nat) = RealNumber Rational
43+
deriving (Eq,Ord,Data,Num,Fractional,Real,RealFrac,Generic,Hashable,ToJSON,FromJSON,NFData)
44+
45+
data NatPrec (p :: Nat) = NatPrec
46+
47+
instance KnownNat p => HasResolution (NatPrec p) where
48+
resolution _ = 10 ^ (natVal (NatPrec @p))
49+
50+
51+
instance KnownNat p => Show (RealNumber p) where
52+
showsPrec d r = showParen (d > app_prec && r < 0) $
53+
case asFixed r of
54+
Exact p -> showString (dropWhileEnd (== '.') . dropWhileEnd (== '0') . show $ p)
55+
Lossy p -> shows p . showChar '~'
56+
where
57+
app_prec = 10
58+
59+
instance KnownNat p => Read (RealNumber p) where
60+
readsPrec i = map wrap . readsPrec @(Fixed (NatPrec p)) i
61+
where
62+
wrap (RealNumber . realToFrac -> x,s') = case s' of
63+
'~':s'' -> (x,s'')
64+
_ -> (x,s')
65+
66+
instance KnownNat p => Arbitrary (RealNumber p) where
67+
arbitrary = fromFixed <$> arbitrary
68+
69+
70+
instance Random (RealNumber p) where
71+
-- Generate a random number between a and b with 'maxBound `div` 2 :: Int' discrete increments.
72+
randomR (a,b) = runRand $ do
73+
v <- getRandom
74+
pure $ (b-a)*abs v + a
75+
-- Generate a random number between -1 and +1 with 'maxBound::Int' discrete increments.
76+
random = runRand $ do
77+
v <- getRandom
78+
let fromInt :: Int -> Integer; fromInt = fromIntegral
79+
pure $ RealNumber $ fromInt v % fromInt maxBound
80+
81+
--------------------------------------------------------------------------------
82+
83+
84+
85+
-- | Fixed-precision representation of a 'RealNumber'. If there's insufficient
86+
-- precision to accurately represent the 'RealNumber' then the 'Lossy' constructor
87+
-- will be used.
88+
data AsFixed p = Exact !(Fixed p) | Lossy !(Fixed p) deriving (Show,Eq)
89+
90+
-- | Cast 'RealNumber' to a fixed-precision number. Data is silently lost if there's
91+
-- insufficient precision.
92+
toFixed :: KnownNat p => RealNumber p -> Fixed (NatPrec p)
93+
toFixed = realToFrac
94+
95+
-- | Cast a fixed-precision number to a 'RealNumber'.
96+
fromFixed :: KnownNat p => Fixed (NatPrec p) -> RealNumber p
97+
fromFixed = realToFrac
98+
99+
-- | Cast 'RealNumber' to a fixed-precision number. Data-loss caused by insufficient
100+
-- precision will be marked by the 'Lossy' constructor.
101+
asFixed :: KnownNat p => RealNumber p -> AsFixed (NatPrec p)
102+
asFixed r = let p = toFixed r in if r == fromFixed p then Exact p else Lossy p

hgeometry-combinatorial/src/Data/RealNumber/Symbolic.hs renamed to hgeometry-combinatorial/src/HGeometry/Number/Real/Symbolic.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE UndecidableInstances #-}
22
--------------------------------------------------------------------------------
33
-- |
4-
-- Module : Data.RealNumber.Symbolic
4+
-- Module : HGeometry.Number.Real.Symbolic
55
-- Copyright : (C) Frank Staals
66
-- License : see the LICENSE file
77
-- Maintainer : Frank Staals
@@ -19,7 +19,7 @@
1919
--
2020
--
2121
--------------------------------------------------------------------------------
22-
module Data.RealNumber.Symbolic(
22+
module HGeometry.Number.Real.Symbolic(
2323
EpsFold
2424
, eps, mkEpsFold
2525
, evalEps
@@ -46,8 +46,8 @@ import qualified Data.List as List
4646
import qualified Data.Map.Merge.Strict as Map
4747
import qualified Data.Map.Strict as Map
4848
import Data.Maybe (isNothing)
49-
import Data.Ratio.Generalized (GRatio, (%))
50-
import Data.Sign (Sign(..))
49+
import HGeometry.Number.Ratio.Generalized (GRatio, (%))
50+
import HGeometry.Sign (Sign(..))
5151
import Test.QuickCheck (Arbitrary(..), listOf)
5252
import Test.QuickCheck.Instances ()
5353

0 commit comments

Comments
 (0)