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
Changes from 1 commit
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mostly finished refactoring (still needs language/import cleanups bef…
…ore merge, plus review)
  • Loading branch information
Mathnerd314 committed May 31, 2014
commit 06f05367666dd8cbdad3b7c34853f4f0297cc86c
3 changes: 3 additions & 0 deletions diagrams-lib.cabal
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ Library
Diagrams.Query,
Diagrams.TwoD,
Diagrams.TwoD.Types,
Diagrams.TwoD.Types.Double,
Diagrams.TwoD.Align,
Diagrams.TwoD.Arrow,
Diagrams.TwoD.Arrowheads,
@@ -85,6 +86,7 @@ Library
Diagrams.ThreeD.Shapes,
Diagrams.ThreeD.Transform,
Diagrams.ThreeD.Types,
Diagrams.ThreeD.Types.Double,
Diagrams.ThreeD.Vector,
Diagrams.ThreeD,
Diagrams.Animation,
@@ -116,6 +118,7 @@ Library
if impl(ghc < 7.6)
Build-depends: ghc-prim
Hs-source-dirs: src
ghc-options: -Wall -Werror
default-language: Haskell2010
-- default-extensions: FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, TypeFamilies
other-extensions: BangPatterns, CPP, DefaultSignatures, DeriveDataTypeable, DeriveFunctor, DeriveGeneric, EmptyDataDecls, ExistentialQuantification, GADTs,
10 changes: 9 additions & 1 deletion src/Diagrams/Angle.hs
Original file line number Diff line number Diff line change
@@ -26,13 +26,14 @@ module Diagrams.Angle
, HasPhi(..)
) where

import Control.Lens (Iso', Lens', iso, review, (^.))
import Control.Lens (Iso', Lens', iso, review)

import Data.Monoid hiding ((<>))
import Data.Semigroup
import Data.VectorSpace

import Diagrams.Core.V
import Diagrams.Points

-- | Angles can be expressed in a variety of units. Internally,
-- they are represented in radians.
@@ -136,3 +137,10 @@ class HasTheta t where
class HasPhi t where
_phi :: Lens' t (Angle (Scalar (V t)))

-- Point instances
instance (HasTheta v, v ~ V v) => HasTheta (Point v) where
_theta = _pIso . _theta

instance (HasPhi v, v ~ V v) => HasPhi (Point v) where
_phi = _pIso . _phi

9 changes: 5 additions & 4 deletions src/Diagrams/Animation.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds, TypeFamilies, FlexibleContexts #-}
-----------------------------------------------------------------------------
-- |
-- Module : Diagrams.Animation
@@ -109,18 +110,18 @@ animEnvelope' r a = withEnvelope (simulate r a) <$> a
--
-- Uses 30 samples per time unit by default; to adjust this number
-- see 'animRect''.
animRect :: (TrailLike t, Enveloped t, Transformable t, Monoid t, V t ~ R2
animRect :: (TrailLike t, Enveloped t, Transformable t, Monoid t, V t ~ v, R2Ish v
, Monoid' m)
=> QAnimation b R2 m -> t
=> QAnimation b v m -> t
animRect = animRect' 30

-- | Like 'animRect', but with an adjustible sample rate. The first
-- parameter is the number of samples per time unit to use. Lower
-- rates will be faster but less accurate; higher rates are more
-- accurate but slower.
animRect' :: (TrailLike t, Enveloped t, Transformable t, Monoid t, V t ~ R2
animRect' :: (TrailLike t, Enveloped t, Transformable t, Monoid t, V t ~ v, R2Ish v
, Monoid' m)
=> Rational -> QAnimation b R2 m -> t
=> Rational -> QAnimation b v m -> t
animRect' r anim
| null results = rect 1 1
| otherwise = boxFit (foldMap boundingBox results) (rect 1 1)
42 changes: 32 additions & 10 deletions src/Diagrams/Coordinates.hs
Original file line number Diff line number Diff line change
@@ -23,17 +23,10 @@ module Diagrams.Coordinates
import Control.Lens (Lens')
import Data.VectorSpace

import Diagrams.Core.Points
import Diagrams.Points
import Data.AffineSpace.Point
import Diagrams.Core.V

-- | A pair of values, with a convenient infix (left-associative)
-- data constructor.
data a :& b = a :& b
deriving (Eq, Ord, Show)

infixl 7 :&


-- | Types which are instances of the @Coordinates@ class can be
-- constructed using '^&' (for example, a three-dimensional vector
-- could be constructed by @1 ^& 6 ^& 3@), and deconstructed using
@@ -78,14 +71,30 @@ class Coordinates c where

infixl 7 ^&

-- | A pair of values, with a convenient infix (left-associative)
-- data constructor.
data a :& b = a :& b
deriving (Eq, Ord, Show)

infixl 7 :&

-- Instance for :& (the buck stops here)
instance Coordinates (a :& b) where
type FinalCoord (a :& b) = b
type PrevDim (a :& b) = a
type Decomposition (a :& b) = a :& b
x ^& y = x :& y
coords (x :& y) = x :& y


-- Some standard instances for plain old tuples

instance Coordinates (a,b) where
type FinalCoord (a,b) = b
type PrevDim (a,b) = a
type Decomposition (a,b) = a :& b

x ^& y = (x,y)
x ^& y = (x,y)
coords (x,y) = x :& y

instance Coordinates (a,b,c) where
@@ -128,3 +137,16 @@ class HasZ t where
-- magnitude of a vector, or the distance from the origin of a point.
class HasR t where
_r :: Lens' t (Scalar (V t))

instance (HasX v, v ~ V v) => HasX (Point v) where
_x = _pIso . _x

instance (HasY v, v ~ V v) => HasY (Point v) where
_y = _pIso . _y

instance (HasZ v, v ~ V v) => HasZ (Point v) where
_z = _pIso . _z

instance (HasR v, v ~ V v) => HasR (Point v) where
_r = _pIso . _r

7 changes: 6 additions & 1 deletion src/Diagrams/Points.hs
Original file line number Diff line number Diff line change
@@ -20,17 +20,22 @@ module Diagrams.Points
-- * Point-related utilities
, centroid
, pointDiagram

, _pIso
) where

import Diagrams.Core (pointDiagram)
import Diagrams.Core.Points

import Control.Arrow ((&&&))
import Control.Lens (Iso', iso)

import Data.AffineSpace.Point
import Data.VectorSpace

-- Point v <-> v
_pIso :: Iso' (Point v) v
_pIso = iso unPoint P

-- | The centroid of a set of /n/ points is their sum divided by /n/.
centroid :: (VectorSpace v, Fractional (Scalar v)) => [Point v] -> Point v
centroid = P . uncurry (^/) . (sumV &&& (fromIntegral . length)) . map unPoint
14 changes: 6 additions & 8 deletions src/Diagrams/Tangent.hs
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ module Diagrams.Tangent
, normalAtStart
, normalAtEnd
, Tangent(..)
, MoreLikeR2
)
where

@@ -35,7 +34,8 @@ import Diagrams.Located
import Diagrams.Parametric
import Diagrams.Segment
import Diagrams.Trail
import Diagrams.TwoD.Vector (perp, LikeR2)
import Diagrams.TwoD.Vector (perp)
import Diagrams.TwoD.Types (R2Ish)

------------------------------------------------------------
-- Tangent
@@ -157,8 +157,6 @@ instance ( InnerSpace v
-- Normal
------------------------------------------------------------

type MoreLikeR2 v = (LikeR2 v, InnerSpace v, Floating (Scalar v))

-- | Compute the (unit) normal vector to a segment or trail at a
-- particular parameter.
--
@@ -172,22 +170,22 @@ type MoreLikeR2 v = (LikeR2 v, InnerSpace v, Floating (Scalar v))
--
-- See the instances listed for the 'Tangent' newtype for more.
normalAtParam
:: (MoreLikeR2 (Codomain (Tangent t)), Parametric (Tangent t))
:: (R2Ish (Codomain (Tangent t)), Parametric (Tangent t))
=> t -> Scalar (V t) -> Codomain (Tangent t)
normalAtParam t p = normize (t `tangentAtParam` p)

-- | Compute the normal vector at the start of a segment or trail.
normalAtStart
:: (MoreLikeR2 (Codomain (Tangent t)), EndValues (Tangent t))
:: (R2Ish (Codomain (Tangent t)), EndValues (Tangent t))
=> t -> Codomain (Tangent t)
normalAtStart = normize . tangentAtStart

-- | Compute the normal vector at the end of a segment or trail.
normalAtEnd
:: (MoreLikeR2 (Codomain (Tangent t)), EndValues (Tangent t))
:: (R2Ish (Codomain (Tangent t)), EndValues (Tangent t))
=> t -> Codomain (Tangent t)
normalAtEnd = normize . tangentAtEnd

-- | Construct a normal vector from a tangent.
normize :: (MoreLikeR2 v) => v -> v
normize :: (R2Ish v) => v -> v
normize = negateV . perp . normalized
Loading