Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linear #215

Merged
merged 64 commits into from Oct 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0f80bd5
Generalize Angle to Angle v and Angle Double
Mathnerd314 May 24, 2014
825f519
Checkpoint
Mathnerd314 May 28, 2014
bcb48c9
Checkpoint (non-compiling)
Mathnerd314 May 28, 2014
2d7a1a0
Forgot a file
Mathnerd314 May 28, 2014
06f0536
Mostly finished refactoring (still needs language/import cleanups bef…
Mathnerd314 May 31, 2014
f21cf4d
Minor tweaks
Mathnerd314 Jun 19, 2014
660ae2a
Merge branch 'master' into generalize-double
Mathnerd314 Jun 19, 2014
8c35f53
Merge remote-tracking branch 'remotes/origin/master' into generalize-…
Mathnerd314 Jun 19, 2014
f257330
Fix up so it compiles
Mathnerd314 Jun 19, 2014
7c02053
git ls-files | grep '\.hs$' | xargs -n 1 stylish-haskell -c misc/styl…
Mathnerd314 Jun 22, 2014
cf92580
language pragma tweaks
Mathnerd314 Aug 1, 2014
892b6ab
more language tweaks
Mathnerd314 Aug 7, 2014
8bd3e0e
Merge branch 'master' of github.com:diagrams/diagrams-lib into genera…
Mathnerd314 Aug 7, 2014
c49c3d0
Split R2Ish into R2Sym, and remove some useless instances of Point ou…
Mathnerd314 Aug 9, 2014
dff0564
Remove R2Sym in favor of R2D (D for Data) - I have a (bogus) Ord inst…
Mathnerd314 Aug 11, 2014
cd66e8e
Typeable/Show instances for R2Basis
Mathnerd314 Aug 13, 2014
b2fb74b
Add Float and Generic TwoD types and change exports to properly hide …
Mathnerd314 Aug 14, 2014
e1a681d
Fix errors on GHC 7.6
Mathnerd314 Aug 14, 2014
c84cced
Add parameters to GradientStop and TextAlignment, which I missed on m…
Mathnerd314 Aug 16, 2014
2a40713
Some progress.
cchalmers Aug 18, 2014
4b8469a
More progress.
cchalmers Aug 18, 2014
48cbd1d
Bounding box.
cchalmers Aug 18, 2014
fe4892a
Bounding box.
cchalmers Aug 18, 2014
a70c9cf
Merge branch 'generalize-double' of https://github.com/cchalmers/diag…
cchalmers Aug 18, 2014
552c822
Starting on 2D and 3D modules.
cchalmers Aug 21, 2014
a267069
Change VN to Vn.
cchalmers Aug 21, 2014
71d5ada
Almost done.
cchalmers Aug 22, 2014
9961036
Some Bergey sugestions. (and combinators)
cchalmers Aug 23, 2014
3a5ff43
Builds without vector-space.
cchalmers Aug 23, 2014
e1894c6
Update for new lenses.
cchalmers Aug 23, 2014
f237e03
Coordinate instances for linear types.
cchalmers Aug 23, 2014
79c9a2e
Remove unused types.
cchalmers Aug 23, 2014
cf195d0
Use linear's classes for _x, _y, _z.
cchalmers Aug 23, 2014
c989031
Uncomment default pragma.
cchalmers Aug 23, 2014
26582ff
Bring back prelude.
cchalmers Aug 24, 2014
15751d7
lerp has arguments reversed in linear.
cchalmers Aug 24, 2014
507309a
Added (poor) Traced instances for Bounding box.
cchalmers Aug 25, 2014
46a5a9e
General cleanup.
cchalmers Aug 29, 2014
317c7ec
Merge Prelude.ThreeD with Prelude.
cchalmers Aug 29, 2014
d4a5fbd
Added Prelude back.
cchalmers Aug 31, 2014
5d68ad7
Added Polar, Cylindrical and Spherical coordinates.
cchalmers Aug 31, 2014
7e5ca2b
Use stylish-haskell config.
cchalmers Aug 31, 2014
e24baef
Fixed scaling measures.
cchalmers Sep 2, 2014
a11a0f3
Fix bug with showOrigin.
cchalmers Sep 3, 2014
8457055
Postpone new polar coordinate and general cleanup.
cchalmers Sep 7, 2014
0266b2b
Merge branch 'master' into linear
bergey Sep 11, 2014
b53a171
add missing comma in .cabal
bergey Sep 11, 2014
3437160
linear updates for more recent code in master
bergey Sep 11, 2014
fe6f372
Fixes to changes to HasLinearMap and Measure from core.
cchalmers Sep 14, 2014
0e3afee
Some fixes to Angle and BoundingBox.
cchalmers Sep 14, 2014
5a3aace
Remove Data instance for BoundingBox.
cchalmers Sep 14, 2014
df659a4
Remove redundent import.
cchalmers Sep 14, 2014
db94ac4
First attempt at fixes for 7.6.
cchalmers Sep 15, 2014
4dee63c
move `project` to Diagrams.Points
bergey Sep 15, 2014
2b59c1f
Some changes I missed.
cchalmers Sep 15, 2014
c20fb8c
Make Typeable1 instances for Path v and CameraLens l.
cchalmers Sep 15, 2014
ced8456
Remove redundent Data.Typeable from Diagrams.Combinators.
cchalmers Sep 15, 2014
cc232a6
Fix Typeable1 instances.
cchalmers Sep 16, 2014
dde9d02
Call it Path.
cchalmers Sep 16, 2014
63e92b1
add Enum instance for Angle
jeffreyrosenbluth Sep 20, 2014
0268582
document semantics of Lights
bergey Oct 5, 2014
65cfee7
Add Diagrams.ThreeD to prelude.
cchalmers Oct 6, 2014
68ad27a
Merge branch 'linear' of https://github.com/diagrams/diagrams-lib int…
cchalmers Oct 6, 2014
d92afe2
cabal: conservative upper bound on linear
bergey Oct 6, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Setup.hs
@@ -1,2 +1,2 @@
import Distribution.Simple
import Distribution.Simple
main = defaultMain
64 changes: 34 additions & 30 deletions diagrams-lib.cabal
Expand Up @@ -26,57 +26,57 @@ Source-repository head

Library
Exposed-modules: Diagrams.Prelude,
Diagrams.Prelude.ThreeD,
Diagrams.Align,
Diagrams.Angle,
Diagrams.Combinators,
Diagrams.Coordinates,
Diagrams.Attributes,
Diagrams.Attributes.Compile,
Diagrams.Points,
Diagrams.BoundingBox,
Diagrams.Combinators,
Diagrams.Coordinates,
Diagrams.CubicSpline,
Diagrams.CubicSpline.Internal,
Diagrams.Deform
Diagrams.Direction,
Diagrams.Envelope,
Diagrams.Located,
Diagrams.Names,
Diagrams.Parametric,
Diagrams.Parametric.Adjust,
Diagrams.Segment,
Diagrams.Trail,
Diagrams.TrailLike,
Diagrams.Path,
Diagrams.CubicSpline,
Diagrams.CubicSpline.Internal,
Diagrams.Direction,
Diagrams.Points,
Diagrams.Query,
Diagrams.Segment,
Diagrams.Solve,
Diagrams.Tangent,
Diagrams.Transform,
Diagrams.Deform
Diagrams.BoundingBox,
Diagrams.Names,
Diagrams.Envelope,
Diagrams.Trace,
Diagrams.Query,
Diagrams.Trail,
Diagrams.TrailLike,
Diagrams.Transform,
Diagrams.TwoD,
Diagrams.TwoD.Types,
Diagrams.TwoD.Adjust,
Diagrams.TwoD.Align,
Diagrams.TwoD.Arc,
Diagrams.TwoD.Arrow,
Diagrams.TwoD.Arrowheads,
Diagrams.TwoD.Attributes,
Diagrams.TwoD.Combinators,
Diagrams.TwoD.Curvature,
Diagrams.TwoD.Deform,
Diagrams.TwoD.Transform,
Diagrams.TwoD.Transform.ScaleInv,
Diagrams.TwoD.Ellipse,
Diagrams.TwoD.Arc,
Diagrams.TwoD.Segment,
Diagrams.TwoD.Curvature,
Diagrams.TwoD.Image,
Diagrams.TwoD.Model,
Diagrams.TwoD.Offset,
Diagrams.TwoD.Path,
Diagrams.TwoD.Polygons,
Diagrams.TwoD.Segment,
Diagrams.TwoD.Shapes,
Diagrams.TwoD.Vector,
Diagrams.TwoD.Size,
Diagrams.TwoD.Model,
Diagrams.TwoD.Text,
Diagrams.TwoD.Image,
Diagrams.TwoD.Adjust,
Diagrams.TwoD.Transform,
Diagrams.TwoD.Transform.ScaleInv,
Diagrams.TwoD.Types,
Diagrams.TwoD.Vector,
Diagrams.ThreeD,
Diagrams.ThreeD.Align,
Diagrams.ThreeD.Attributes,
Diagrams.ThreeD.Camera,
Expand All @@ -86,7 +86,6 @@ Library
Diagrams.ThreeD.Transform,
Diagrams.ThreeD.Types,
Diagrams.ThreeD.Vector,
Diagrams.ThreeD,
Diagrams.Animation,
Diagrams.Animation.Active,
Diagrams.Util,
Expand All @@ -99,9 +98,6 @@ Library
dual-tree >= 0.2 && < 0.3,
diagrams-core >= 1.2 && < 1.3,
active >= 0.1 && < 0.2,
vector-space >= 0.7.7 && < 0.9,
vector-space-points >= 0.1.2 && < 0.3,
MemoTrie >= 0.6 && < 0.7,
colour >= 2.3.2 && < 2.4,
data-default-class < 0.1,
fingertree >= 0.1 && < 0.2,
Expand All @@ -113,6 +109,9 @@ Library
safe >= 0.2 && < 0.4,
JuicyPixels >= 3.1.5 && < 3.2,
hashable >= 1.1 && < 1.3,
linear >= 1.10 && < 1.11,
adjunctions >= 4.0 && < 5.0,
distributive >=0.2.2 && < 1.0,
process >= 1.1 && < 1.3,
fsnotify >= 0.1 && < 0.2,
directory >= 1.2 && < 1.3,
Expand All @@ -123,3 +122,8 @@ Library
Hs-source-dirs: src
ghc-options: -Wall
default-language: Haskell2010
other-extensions: BangPatterns, CPP, DefaultSignatures, DeriveDataTypeable,
DeriveFunctor, DeriveGeneric, EmptyDataDecls, ExistentialQuantification,
GADTs, GeneralizedNewtypeDeriving, NoMonomorphismRestriction, Rank2Types,
RankNTypes, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell,
TypeOperators, TypeSynonymInstances, UndecidableInstances, ViewPatterns
6 changes: 3 additions & 3 deletions misc/DKSolve.hs
Expand Up @@ -5,8 +5,8 @@
-- See http://en.wikipedia.org/wiki/Durand–Kerner_method


import Data.Complex
import Data.List (inits, tails)
import Data.Complex
import Data.List (inits, tails)

eps :: Double
eps = 1e-14
Expand Down Expand Up @@ -48,4 +48,4 @@ type C = Complex Double
fixedPt :: Double -> ([C] -> [C]) -> [C] -> [C]
fixedPt eps f as | all ((<eps) . realPart . abs) $ zipWith (-) as as' = as
| otherwise = fixedPt eps f as'
where as' = f as
where as' = f as
29 changes: 29 additions & 0 deletions misc/stylish-haskell.yaml
@@ -0,0 +1,29 @@
# stylish-haskell configuration file
# ==================================

steps:
# Import cleanup
- imports:
# global produced the smallest diff
align: global

# Language pragmas
- language_pragmas:
style: vertical
remove_redundant: true

# Align the types in record declarations
- records: {}

# Remove trailing whitespace
- trailing_whitespace: {}

# unused steps - UnicodeSyntax, tabs to spaces

# Wrap to 100 columns, because I feel like it
columns: 100

# No language extensions are enabled by default.
# language_extensions:
# - TemplateHaskell
# - QuasiQuotes
115 changes: 58 additions & 57 deletions src/Diagrams/Align.hs
Expand Up @@ -36,16 +36,18 @@ module Diagrams.Align
) where

import Diagrams.Core
import Diagrams.Util (applyAll)
import Diagrams.Util (applyAll)

import Data.AffineSpace (alerp, (.-.))
import Data.VectorSpace
import Data.Maybe (fromMaybe)
import Data.Ord (comparing)
import Data.Maybe (fromMaybe)
import Data.Ord (comparing)

import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Foldable as F
import qualified Data.Foldable as F
import qualified Data.Map as M
import qualified Data.Set as S

import Linear.Affine
import Linear.Metric
import Linear.Vector

-- | Class of things which can be aligned.
class Alignable a where
Expand All @@ -56,113 +58,112 @@ class Alignable a where
-- edge of the boundary in the direction of the negation of @v@.
-- Other values of @d@ interpolate linearly (so for example, @d =
-- 0@ centers the origin along the direction of @v@).
alignBy' :: ( HasOrigin a, AdditiveGroup (V a), Num (Scalar (V a))
, Fractional (Scalar (V a)))
=> (V a -> a -> Point (V a)) -> V a -> Scalar (V a) -> a -> a
alignBy' :: (V a ~ v, N a ~ n, HasOrigin a, Additive v, Fractional n)
=> (v n -> a -> Point v n) -> v n -> n -> a -> a
alignBy' = alignBy'Default

defaultBoundary :: V a -> a -> Point (V a)
defaultBoundary :: (V a ~ v, N a ~ n) => v n -> a -> Point v n

alignBy :: (HasOrigin a, Num (Scalar (V a)), Fractional (Scalar (V a)))
=> V a -> Scalar (V a) -> a -> a
alignBy :: (V a ~ v, N a ~ n, Additive v, HasOrigin a, Fractional n)
=> v n -> n -> a -> a
alignBy = alignBy' defaultBoundary

-- | Default implementation of 'alignBy' for types with 'HasOrigin'
-- and 'AdditiveGroup' instances.
alignBy'Default :: ( HasOrigin a, AdditiveGroup (V a), Num (Scalar (V a))
, Fractional (Scalar (V a)))
=> (V a -> a -> Point (V a)) -> V a -> Scalar (V a) -> a -> a
alignBy'Default boundary v d a = moveOriginTo (alerp (boundary (negateV v) a)
(boundary v a)
((d + 1) / 2)) a
alignBy'Default :: (V a ~ v, N a ~ n, HasOrigin a, Additive v, Fractional n)
=> (v n -> a -> Point v n) -> v n -> n -> a -> a
alignBy'Default boundary v d a = moveOriginTo (lerp ((d + 1) / 2)
(boundary v a)
(boundary (negated v) a)
) a
{-# ANN alignBy'Default ("HLint: ignore Use camelCase" :: String) #-}


-- | Some standard functions which can be used as the `boundary` argument to
-- `alignBy'`.
envelopeBoundary :: Enveloped a => V a -> a -> Point (V a)
envelopeBoundary :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Point v n
envelopeBoundary = envelopeP

traceBoundary :: Traced a => V a -> a -> Point (V a)
traceBoundary :: (V a ~ v, N a ~ n, Num n, Traced a) => v n -> a -> Point v n
traceBoundary v a = fromMaybe origin (maxTraceP origin v a)

combineBoundaries
:: (F.Foldable f, InnerSpace (V a), Ord (Scalar (V a)))
=> (V a -> a -> Point (V a)) -> (V a -> f a -> Point (V a))
:: (V a ~ v, N a ~ n, F.Foldable f, Metric v, Ord n, Num n)
=> (v n -> a -> Point v n) -> v n -> f a -> Point v n
combineBoundaries b v fa
= b v $ F.maximumBy (comparing (magnitudeSq . (.-. origin) . b v)) fa
= b v $ F.maximumBy (comparing (quadrance . (.-. origin) . b v)) fa

instance (InnerSpace v, OrderedField (Scalar v)) => Alignable (Envelope v) where
instance (Metric v, OrderedField n) => Alignable (Envelope v n) where
defaultBoundary = envelopeBoundary

instance (InnerSpace v, OrderedField (Scalar v)) => Alignable (Trace v) where
instance (Metric v, OrderedField n) => Alignable (Trace v n) where
defaultBoundary = traceBoundary

instance (InnerSpace (V b), Ord (Scalar (V b)), Alignable b)
=> Alignable [b] where
instance (V b ~ v, N b ~ n, Metric v, OrderedField n, Alignable b) => Alignable [b] where
defaultBoundary = combineBoundaries defaultBoundary

instance (InnerSpace (V b), Ord (Scalar (V b)), Alignable b)
=> Alignable (S.Set b) where
instance (V b ~ v, N b ~ n, Metric v, OrderedField n, Alignable b)
=> Alignable (S.Set b) where
defaultBoundary = combineBoundaries defaultBoundary

instance (InnerSpace (V b), Ord (Scalar (V b)), Alignable b)
=> Alignable (M.Map k b) where
instance (V b ~ v, N b ~ n, Metric v, OrderedField n, Alignable b)
=> Alignable (M.Map k b) where
defaultBoundary = combineBoundaries defaultBoundary

instance ( HasLinearMap v, InnerSpace v, OrderedField (Scalar v)
, Monoid' m
) => Alignable (QDiagram b v m) where
instance (HasLinearMap v, Metric v, OrderedField n, Monoid' m)
=> Alignable (QDiagram b v n m) where
defaultBoundary = envelopeBoundary

-- | Although the 'alignBy' method for the @(b -> a)@ instance is
-- sensible, there is no good implementation for
-- 'defaultBoundary'. Instead, we provide a total method, but one that
-- is not sensible. This should not present a serious problem as long
-- as your use of 'Alignable' happens through 'alignBy'.
instance (HasOrigin a, Alignable a) => Alignable (b -> a) where
alignBy v d f b = alignBy v d (f b)
instance (V a ~ v, N a ~ n, Additive v, Num n, HasOrigin a, Alignable a) => Alignable (b -> a) where
alignBy v d f b = alignBy v d (f b)
defaultBoundary _ _ = origin

-- | @align v@ aligns an enveloped object along the edge in the
-- direction of @v@. That is, it moves the local origin in the
-- direction of @v@ until it is on the edge of the envelope. (Note
-- that if the local origin is outside the envelope to begin with,
-- it may have to move \"backwards\".)
align :: ( Alignable a, HasOrigin a, Num (Scalar (V a))
, Fractional (Scalar (V a))) => V a -> a -> a
align :: (V a ~ v, N a ~ n, Additive v, Alignable a, HasOrigin a, Fractional n) => v n -> a -> a
align v = alignBy v 1

-- | Version of @alignBy@ specialized to use @traceBoundary@
snugBy :: (Alignable a, Traced a, HasOrigin a, Num (Scalar (V a)), Fractional (Scalar (V a)))
=> V a -> Scalar (V a) -> a -> a
snugBy :: (V a ~ v, N a ~ n, Alignable a, Traced a, HasOrigin a, Fractional n)
=> v n -> n -> a -> a
snugBy = alignBy' traceBoundary

-- | Like align but uses trace.
snug :: (Fractional (Scalar (V a)), Alignable a, Traced a, HasOrigin a)
=> V a -> a -> a
snug v = snugBy v 1
snug :: (V a ~ v, N a ~ n, Fractional n, Alignable a, Traced a, HasOrigin a)
=> v n -> a -> a
snug v = snugBy v 1

-- | @centerV v@ centers an enveloped object along the direction of
-- @v@.
centerV :: ( Alignable a, HasOrigin a, Num (Scalar (V a))
, Fractional (Scalar (V a))) => V a -> a -> a
centerV :: (V a ~ v, N a ~ n, Additive v, Alignable a, HasOrigin a, Fractional n) => v n -> a -> a
centerV v = alignBy v 0

-- | @center@ centers an enveloped object along all of its basis vectors.
center :: ( HasLinearMap (V a), Alignable a, HasOrigin a, Num (Scalar (V a)),
Fractional (Scalar (V a))) => a -> a
center d = applyAll fs d
center :: (V a ~ v, N a ~ n, HasLinearMap v, Alignable a, HasOrigin a, Fractional n) => a -> a
center = applyAll fs
where
fs = map centerV basis

-- | Like @centerV@ using trace.
snugCenterV
:: (Fractional (Scalar (V a)), Alignable a, Traced a, HasOrigin a)
=> V a -> a -> a
snugCenterV v = (alignBy' traceBoundary) v 0
:: (V a ~ v, N a ~ n, Fractional n, Alignable a, Traced a, HasOrigin a)
=> v n -> a -> a
snugCenterV v = alignBy' traceBoundary v 0

-- | Like @center@ using trace.
snugCenter :: ( HasLinearMap (V a), Alignable a, HasOrigin a, Num (Scalar (V a)),
Fractional (Scalar (V a)), Traced a) => a -> a
snugCenter d = applyAll fs d
snugCenter :: (V a ~ v, N a ~ n, HasLinearMap v, Alignable a, HasOrigin a, Fractional n, Traced a)
=> a -> a
snugCenter = applyAll fs
where
fs = map snugCenterV basis
fs = map snugCenterV basis

{-# ANN module ("HLint: ignore Use camelCase" :: String) #-}