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

Pre 1.3 #241

Merged
merged 35 commits into from
Mar 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
88ffd9d
Nessesary changes from style lenses.
cchalmers Feb 21, 2015
aa321bc
Change view to rectEnvelope.
cchalmers Feb 28, 2015
5510444
Add BoundingBox to prelude.
cchalmers Feb 28, 2015
477c88f
Add (##) operator to Util.
cchalmers Feb 28, 2015
72bf032
Add transformation isomorphisms.
cchalmers Feb 28, 2015
2c06478
Limit Color instances to Double.
cchalmers Feb 28, 2015
bc90da0
Add _AC prism.
cchalmers Feb 28, 2015
b33f96f
Add _loc lens onto location of Located.
cchalmers Feb 28, 2015
0a2eee2
Proper show instance for BoundingBox.
cchalmers Mar 1, 2015
2cad461
Show and read instance for Angles using @@.
cchalmers Mar 2, 2015
9c8b2b7
Nicer Show instance for Segments.
cchalmers Mar 3, 2015
0a1db54
Custom Located Show instance using at.
cchalmers Mar 2, 2015
cc40ac2
SomeColor Show instance.
cchalmers Mar 4, 2015
d4dba22
Add Tangent (FixedSegment v n) instances.
cchalmers Mar 2, 2015
77a411e
Lens instances for Trails.
cchalmers Mar 2, 2015
6edb069
Add Reversing instances.
cchalmers Mar 3, 2015
effddae
Add angleV function.
cchalmers Mar 2, 2015
50d1300
Move from (|>) to (>|).
cchalmers Mar 2, 2015
50359cf
Get rid of unnessesary AttributeA wrappers.
cchalmers Mar 3, 2015
dc19919
Add _Clip and _clip style lenses.
cchalmers Mar 5, 2015
1725545
Add AsEmpty instances.
cchalmers Mar 5, 2015
e2c7dcd
Add Ord instances for line attributes.
cchalmers Mar 5, 2015
471662b
Remove FontWeightA wrapper.
cchalmers Mar 5, 2015
7e72384
Comment for loopFromSegments.
cchalmers Mar 5, 2015
da7d665
More comments about size.
cchalmers Mar 9, 2015
da4e3af
Export lens from Prelude.
cchalmers Feb 28, 2015
17591e8
Merge branch 'master' into pre-1.3
cchalmers Mar 10, 2015
a6bb4b1
Rename (>|) to (.>>).
cchalmers Mar 10, 2015
176276f
Add comments to Reversing instances.
cchalmers Mar 10, 2015
f109b0d
Generalise @@ and bump lens to 4.6.
cchalmers Mar 10, 2015
3f6ed34
various minor Haddock enhancements
byorgey Mar 11, 2015
47fbaac
Add Diagrams module.
cchalmers Mar 11, 2015
f3b535b
Reduce lens exports.
cchalmers Mar 11, 2015
f3da7fe
Export Default from Prelude.
cchalmers Mar 11, 2015
6882057
Bump lens upper bound to 4.9
cchalmers Mar 11, 2015
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
5 changes: 3 additions & 2 deletions diagrams-lib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Source-repository head
location: http://github.com/diagrams/diagrams-lib.git

Library
Exposed-modules: Diagrams.Prelude,
Exposed-modules: Diagrams,
Diagrams.Prelude,
Diagrams.Align,
Diagrams.Angle,
Diagrams.Animation,
Expand Down Expand Up @@ -109,7 +110,7 @@ Library
data-default-class < 0.1,
fingertree >= 0.1 && < 0.2,
intervals >= 0.7 && < 0.8,
lens >= 4.0 && < 4.8,
lens >= 4.6 && < 4.9,
tagged >= 0.7,
optparse-applicative >= 0.11 && < 0.12,
filepath,
Expand Down
150 changes: 150 additions & 0 deletions src/Diagrams.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}
-----------------------------------------------------------------------------
-- |
-- Module : Diagrams
-- Copyright : (c) 2015 diagrams-lib team (see LICENSE)
-- License : BSD-style (see LICENSE)
-- Maintainer : diagrams-discuss@googlegroups.com
--
-- This module only contains exports defined in "diagrams-lib" or
-- "diagrams-core". This module is less likely conflict with any
-- other modules but importing "Diagrams.Prelude" is often more convenient.
--
-----------------------------------------------------------------------------

module Diagrams
(
-- * Core library
-- | The core definitions of transformations, diagrams,
-- backends, and so on.
module Diagrams.Core

-- * Standard library

-- | Attributes (color, line style, etc.) and styles.
, module Diagrams.Attributes

-- | Alignment of diagrams relative to their envelopes.
, module Diagrams.Align

-- | Creating and using bounding boxes.
, module Diagrams.BoundingBox

-- | Combining multiple diagrams into one.
, module Diagrams.Combinators

-- | Giving concrete locations to translation-invariant things.
, module Diagrams.Located

-- | Linear and cubic bezier segments.
, module Diagrams.Segment

-- | Trails.
, module Diagrams.Trail

-- | Parametrization of segments and trails.
, module Diagrams.Parametric

-- | Adjusting the length of parameterized objects.
, module Diagrams.Parametric.Adjust

-- | Computing tangent and normal vectors of segments and
-- trails.
, module Diagrams.Tangent

-- | Trail-like things.
, module Diagrams.TrailLike

-- | Paths.
, module Diagrams.Path

-- | Cubic splines.
, module Diagrams.CubicSpline

-- | Some additional transformation-related functions, like
-- conjugation of transformations.
, module Diagrams.Transform

-- | Projective transformations and other deformations
-- lacking an inverse.
, module Diagrams.Deform

-- | Giving names to subdiagrams and later retrieving
-- subdiagrams by name.
, module Diagrams.Names

-- | Envelopes, aka functional bounding regions.
, module Diagrams.Envelope

-- | Traces, aka embedded raytracers, for finding points on
-- the boundary of a diagram.
, module Diagrams.Trace

-- | A query is a function that maps points in a vector space
-- to values in some monoid; they can be used to annotate
-- the points of a diagram with some values.
, module Diagrams.Query

-- | Utilities for working with points.
, module Diagrams.Points

-- | Utilities for working with size.
, module Diagrams.Size

-- | Angles
, module Diagrams.Angle

-- | Convenience infix operators for working with coordinates.
, module Diagrams.Coordinates

-- | Directions, distinguished from angles or vectors
, module Diagrams.Direction

-- | A wide range of things (shapes, transformations,
-- combinators) specific to creating two-dimensional
-- diagrams.
, module Diagrams.TwoD

-- | Extra things for three-dimensional diagrams.
, module Diagrams.ThreeD

-- | Tools for making animations.
, module Diagrams.Animation

-- | Various utility definitions.
, module Diagrams.Util

) where

import Diagrams.Core

import Diagrams.Align
import Diagrams.Angle
import Diagrams.Animation
import Diagrams.Attributes
import Diagrams.BoundingBox hiding (intersection, union, inside, outside, contains)
import Diagrams.Combinators
import Diagrams.Coordinates
import Diagrams.CubicSpline
import Diagrams.Deform
import Diagrams.Direction hiding (dir)
import Diagrams.Envelope
import Diagrams.Located
import Diagrams.Names
import Diagrams.Parametric
import Diagrams.Parametric.Adjust
import Diagrams.Path
import Diagrams.Points
import Diagrams.Query
import Diagrams.Segment
import Diagrams.Size
import Diagrams.Tangent
import Diagrams.ThreeD
import Diagrams.Trace
import Diagrams.Trail hiding (linePoints, loopPoints,
trailPoints)
import Diagrams.TrailLike
import Diagrams.Transform
import Diagrams.TwoD
import Diagrams.Util

64 changes: 47 additions & 17 deletions src/Diagrams/Angle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ module Diagrams.Angle
) where

import Control.Applicative
import Control.Lens (Iso', Lens', iso, over, review, (^.))
import Control.Lens (AReview, Iso', Lens', iso, over, review, (^.))
import Data.Fixed
import Data.Monoid hiding ((<>))
import Data.Semigroup
import Text.Read
import Prelude

import Diagrams.Core (OrderedField)
Expand All @@ -52,7 +53,18 @@ import Linear.Vector
-- | Angles can be expressed in a variety of units. Internally,
-- they are represented in radians.
newtype Angle n = Radians n
deriving (Read, Show, Eq, Ord, Enum, Functor)
deriving (Eq, Ord, Enum, Functor)

instance Show n => Show (Angle n) where
showsPrec d (Radians a) = showParen (d > 5) $
showsPrec 6 a . showString " @@ rad"

instance Read n => Read (Angle n) where
readPrec = parens . prec 5 $ do
x <- readPrec
Symbol "@@" <- lexP
Ident "rad" <- lexP
pure (Radians x)

type instance N (Angle n) = n

Expand All @@ -74,21 +86,22 @@ instance Num n => Monoid (Angle n) where
mappend = (<>)
mempty = Radians 0

-- | The radian measure of an @Angle@ @a@ can be accessed as @a
-- ^. rad@. A new @Angle@ can be defined in radians as @pi \@\@ rad@.
-- | The radian measure of an 'Angle' @a@ can be accessed as @a '^.'
-- rad@. A new 'Angle' can be defined in radians as @pi \@\@
-- rad@.
rad :: Iso' (Angle n) n
rad = iso (\(Radians r) -> r) Radians
{-# INLINE rad #-}

-- | The measure of an @Angle@ @a@ in full circles can be accessed as
-- @a ^. turn@. A new @Angle@ of one-half circle can be defined in as
-- | The measure of an 'Angle' @a@ in full circles can be accessed as
-- @a '^.' turn@. A new 'Angle' of one-half circle can be defined in as
-- @1/2 \@\@ turn@.
turn :: Floating n => Iso' (Angle n) n
turn = iso (\(Radians r) -> r / (2*pi)) (Radians . (*(2*pi)))
{-# INLINE turn #-}

-- | The degree measure of an @Angle@ @a@ can be accessed as @a
-- ^. deg@. A new @Angle@ can be defined in degrees as @180 \@\@
-- | The degree measure of an 'Angle' @a@ can be accessed as @a
-- '^.' deg@. A new 'Angle' can be defined in degrees as @180 \@\@
-- deg@.
deg :: Floating n => Iso' (Angle n) n
deg = iso (\(Radians r) -> r / (2*pi/360)) (Radians . ( * (2*pi/360)))
Expand Down Expand Up @@ -141,7 +154,7 @@ atan2A y x = Radians $ atan2 y x

-- | Similar to 'atan2A' but without the 'RealFloat' constraint. This means it
-- doesn't handle negative zero cases. However, for most geometric purposes,
-- outcome will be the same.
-- the outcome will be the same.
atan2A' :: OrderedField n => n -> n -> Angle n
atan2A' y x = atan2' y x @@ rad

Expand All @@ -156,13 +169,30 @@ atan2' y x
| x==0 && y==0 = y -- must be after the other double zero tests
| otherwise = x + y -- x or y is a NaN, return a NaN (via +)

-- | @30 \@\@ deg@ is an @Angle@ of the given measure and units.
-- | @30 \@\@ deg@ is an 'Angle' of the given measure and units.
--
-- >>> pi @@ rad
-- 3.141592653589793 @@ rad
--
-- >>> 1 @@ turn
-- 6.283185307179586 @@ rad
--
-- >>> 30 @@ deg
-- 0.5235987755982988 @@ rad
--
-- For 'Iso''s, ('@@') reverses the 'Iso'' on its right, and applies
-- the 'Iso'' to the value on the left. 'Angle's are the motivating
-- example where this order improves readability.
--
-- This is the same as a flipped 'review'.
--
-- More generally, @\@\@@ reverses the @Iso\'@ on its right, and
-- applies the @Iso\'@ to the value on the left. @Angle@s are the
-- motivating example where this order improves readability.
(@@) :: b -> Iso' a b -> a
-- The signature above is slightly specialized, in favor of readability
-- @
-- ('@@') :: a -> 'Iso'' s a -> s
-- ('@@') :: a -> 'Prism'' s a -> s
-- ('@@') :: a -> 'Review' s a -> s
-- ('@@') :: a -> 'Equality'' s a -> s
-- @
(@@) :: b -> AReview a b -> a
a @@ i = review i a

infixl 5 @@
Expand All @@ -180,12 +210,12 @@ normalizeAngle = over rad (`mod'` (2 * pi))
------------------------------------------------------------
-- Polar Coordinates

-- | The class of types with at least one angle coordinate, called _theta.
-- | The class of types with at least one angle coordinate, called '_theta'.
class HasTheta t where
_theta :: RealFloat n => Lens' (t n) (Angle n)

-- | The class of types with at least two angle coordinates, the second called
-- _phi. _phi is the positive angle measured from the z axis.
-- '_phi'. '_phi' is the positive angle measured from the z axis.
class HasTheta t => HasPhi t where
_phi :: RealFloat n => Lens' (t n) (Angle n)

Expand Down
Loading