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

Rework of units #169

Merged
merged 84 commits into from
Mar 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
2b21445
start work on pushing fill attributes down to subtrees with only loops
byorgey Feb 10, 2014
6028236
implement splitFills for case of style node
byorgey Feb 11, 2014
7c95e39
finish implementing splitFills: RPrim case
byorgey Feb 11, 2014
0412269
D.Attributes: fix warnings
byorgey Feb 11, 2014
79d1556
D.Attributes: clarify comments on splitFills
byorgey Feb 13, 2014
f5410a2
Exclude joins in offsets on close segments (Fixes #160).
Feb 15, 2014
bf51700
finish implementing splitFills (with tests).
byorgey Feb 19, 2014
ecc1a80
CHANGES for 1.1
byorgey Feb 20, 2014
a6feb30
require diagrams-core-1.1
byorgey Feb 20, 2014
eb0fcb5
Added `frame` section
jeffreyrosenbluth Feb 21, 2014
38bc25d
edit `frame` description
jeffreyrosenbluth Feb 22, 2014
c9e63fc
update tested-with field
byorgey Mar 1, 2014
1e0a1a0
update copyright years
byorgey Mar 1, 2014
e3a270c
fix doc for === and |||
denys-duchier Mar 2, 2014
56fb4b6
Merge pull request #164 from denys-duchier/doc-fix
byorgey Mar 2, 2014
49b1705
add Denys to contributors list
byorgey Mar 2, 2014
02da78c
add GHC 7.8.1 to tested-with field
byorgey Mar 2, 2014
0d4e019
Merge pull request #161 from diagrams/split-fills
bergey Mar 3, 2014
f78be72
Wall: remove extra imports
bergey Mar 3, 2014
0cf4726
initial commit
Mar 3, 2014
8ce0b10
change defaults
Mar 4, 2014
4007bdd
handle zero case, add documentation
Mar 4, 2014
16813be
travis: build with 7.8.1 instead of GHC HEAD
bergey Mar 5, 2014
63fe0ad
CHANGES: note new splitFills function
Mar 5, 2014
b54f948
travis: require ghc-7.8.1 to succeed, re-add HEAD
bergey Mar 5, 2014
4b9d919
travis: fix capitalization of GHC head
bergey Mar 6, 2014
ee18b88
CHANGES: 1.1 release date
byorgey Mar 9, 2014
37e4033
headWidth, tailWidth, widths
jeffreyrosenbluth Mar 9, 2014
2594195
3D colors, material reflectance
bergey Feb 14, 2014
d1806e4
simpler angleBetween
bergey Feb 24, 2014
26807c2
Add trig functions using Angle
bergey Feb 14, 2014
44bdbad
lenses for polar coordinates
bergey Feb 24, 2014
1fea5fa
allow vector-space-points-0.2
byorgey Mar 9, 2014
57b746e
Bump version to 1.1.0.1
byorgey Mar 9, 2014
7614b82
Release notes for 1.1.0.1
byorgey Mar 9, 2014
7ff0263
make R3 strict data like R2
bergey Feb 24, 2014
216317f
Make Direction a type, not a type class
bergey Feb 24, 2014
03833af
Add Box
bergey Feb 24, 2014
2e03dec
Add Frustum
bergey Feb 24, 2014
1229c55
Wall: remove extra imports
bergey Mar 9, 2014
ec8f0a9
explicit instances for HasPhi, HasR, HasTheta to avoid overlap
bergey Mar 9, 2014
9148c6a
make HasR _r lens be the vector magnitude
bergey Mar 9, 2014
c76595e
move avgScale to core
Mar 10, 2014
debf974
clean up R3 instances
bergey Mar 11, 2014
78c0522
Wall: remove unneeded import
bergey Mar 11, 2014
a52e8e5
generalize angleBetween for arbitrary InnerSpace
bergey Mar 11, 2014
e4312f0
move Angle definition to separate module
bergey Mar 11, 2014
3ebb80d
move angleBetween to Diagrams.Angle
bergey Mar 11, 2014
daca572
export more Angle functions from TwoD.hs
bergey Mar 11, 2014
d7a09ea
import Data.Proxy iff GHC < 7.7
bergey Mar 11, 2014
7b356a7
Better Haddock comments for 3D attributes, _r Lens
bergey Mar 11, 2014
e1897ca
Use _relative from Diagrams.Core
bergey Mar 11, 2014
49d298f
Wall: remove AffineSpace import
bergey Mar 11, 2014
f86249c
Segment: clean up ghc-7.8 warnings
Mar 11, 2014
b9a3a2d
Merge pull request #167 from diagrams/avg-scale
byorgey Mar 12, 2014
77480c0
Export Angle module from Prelude instead of TwoD
bergey Mar 12, 2014
cc73190
Merge pull request #166 from diagrams/3d-color
byorgey Mar 12, 2014
0193b0e
Merge pull request #165 from diagrams/tail
byorgey Mar 12, 2014
b65dccb
Wall: remove redundant import
byorgey Mar 12, 2014
a325a06
Revert "Manually written Transformable instance for SegTree"
Mar 12, 2014
b742281
Merge branch 'master' into roles
Mar 12, 2014
792bb5e
Remove extraneous comments
jeffreyrosenbluth Mar 13, 2014
2b1e1b8
Add `gaps` as synonym for `gap`
jeffreyrosenbluth Mar 13, 2014
aafd919
Added gaps
jeffreyrosenbluth Mar 13, 2014
bf635ff
allow optparse-applicative-0.8
byorgey Mar 19, 2014
a5d2c62
Release notes for 1.1.0.2
byorgey Mar 19, 2014
91aa809
allow lens-4.1
bergey Mar 19, 2014
4e6d125
give connectOutside a reasonable behavior even when one or both endpo…
byorgey Mar 19, 2014
0297bb3
CHANGES for 1.1.0.3
bergey Mar 19, 2014
0acad55
trailLocSegments, pathLocSegments
jeffreyrosenbluth Mar 20, 2014
efdfe0c
fixed comment
jeffreyrosenbluth Mar 20, 2014
0cae89a
export pathLocSegments
jeffreyrosenbluth Mar 20, 2014
7bcf0a5
Arrowtest: update to use Angle type
bergey Mar 21, 2014
2f98b13
Merge branch 'master' into units2
byorgey Mar 24, 2014
bd4b3a3
progress on units
byorgey Mar 25, 2014
9ea002f
-Wall: remove redundant import
byorgey Mar 25, 2014
1e2e468
-Wall: remove another redundant import
byorgey Mar 25, 2014
c9407f8
get rid of setLineWidth, which is no longer used and seems dodgy anyway
byorgey Mar 25, 2014
3092b71
headSize and tailSize use applyGTAttr
jeffreyrosenbluth Mar 25, 2014
e625a48
convert dashing to Measure, Local not scaling
jeffreyrosenbluth Mar 25, 2014
2578d59
fix Dashing transform
jeffreyrosenbluth Mar 25, 2014
abe0b97
better
jeffreyrosenbluth Mar 25, 2014
40a02f4
remove redundant imports from arrows
jeffreyrosenbluth Mar 25, 2014
d00b132
Transformable instance for (Measure Double), convenience functions fo…
jeffreyrosenbluth Mar 25, 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
- HPVER=2013.2.0.0
- GHCVER=7.4.2
- GHCVER=7.6.3
- GHCVER=7.8.1
- GHCVER=head
global:
- CABALVER=1.18
Expand Down
84 changes: 84 additions & 0 deletions CHANGES.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
1.1.0.3 (19 March 2014)
----------------------

- Allow `lens-4.1`

1.1.0.2 (18 March 2014)
-----------------------

- Allow `optparse-applicative-0.8`

1.1.0.1 (9 March 2014)
----------------------

- Allow `vector-space-points-0.2`

1.1 (8 March 2014)
------------------

* **New features**

- Support for `Deformation`s, arbitrary (non-affine)
transformations on objects such as points, paths, and located
trails (though not on diagrams).

- New functions `clipTo`, which clips a diagram's envelope and
trace along with its visual representation, and `clipped`, which
clips the diagram's visual representation but replaces its
envelope and trace with those of the clipping path.

- New `arrowV` function, for creating an arrow with the direction
and magnitude of a given vector.

- `gap` traversal, for setting the head and tail gaps of an arrow
simultaneously.

- Generalized types for `centerXY` and `snugXY`, based on new
`basis` function from `diagrams-core

- New 3D `Transform`s, alignment, and 3D-specific `Prelude`.

- New `frame` function similar to `pad`, but increases the envelope
of a diagram by an amount specified in local units in every direction
irrespective of the local origin.

- New `splitFills` function for pushing fill attributes down to
subtrees containing only loops (mostly of relevance only to
backend implementors).

* **New instances**

- `Typeable` instances for all data types that are used as diagram
primitives.
- `Sectionable` instance for `FixedSegment`.

* **API changes**

- `Angle` is now a type, rather than a class. It uses a single
internal representation for angles, and lenses `turn`, `rad,`
and `deg` are supplied for constructing (using `@@`) and viewing
(using `^.`) `Angle`s in various units. In addition, the `Num`
instance for `Angle` has been removed, eliminating a class of
errors where a bare number is interpreted in units other than
what you expect.

- Removed `Num` instance for angles.

* **Dependency/version changes**

- Require `lens >= 4.0`.
- Allow `array-0.5`.
- Allow `hashable-1.1`.
- Remove `NumInstances` dependency.

* **Bug fixes**

- Exclude joins in offsets on close segments (#160).
- Exclude extra segment when joining loops in offset (#155).

* **Performance improvements**

- `colorToSRGBA` function now avoids expensive matrix operations,
offering dramatic speedups in rendering diagrams with many color
attributes.

1.0.1 (26 January 2014)
-----------------------

Expand Down
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Copyright (c) 2011-2013 diagrams-lib team:
Copyright (c) 2011-2014 diagrams-lib team:

Jan Bracker <jan.bracker@googlemail.com>
Daniel Bergey <bergey@alum.mit.edu>
Denys Duchier <denys.duchier@univ-orleans.fr>
Daniil Frumin <difrumin@gmail.com>
Niklas Haas <nand@lavabit.com>
Peter Hall <peter.hall@memorphic.com>
Expand Down
16 changes: 9 additions & 7 deletions diagrams-lib.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: diagrams-lib
Version: 1.1
Version: 1.1.0.1
Synopsis: Embedded domain-specific language for declarative graphics
Description: Diagrams is a flexible, extensible EDSL for creating
graphics of many types. Graphics can be created
Expand All @@ -19,7 +19,7 @@ Build-type: Simple
Cabal-version: >=1.10
Extra-source-files: CHANGES.markdown, README.markdown, diagrams/*.svg
Extra-doc-files: diagrams/*.svg
Tested-with: GHC == 7.4.2, GHC == 7.6.1
Tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.1
Source-repository head
type: git
location: http://github.com/diagrams/diagrams-lib.git
Expand All @@ -28,9 +28,11 @@ Library
Exposed-modules: Diagrams.Prelude,
Diagrams.Prelude.ThreeD,
Diagrams.Align,
Diagrams.Angle,
Diagrams.Combinators,
Diagrams.Coordinates,
Diagrams.Attributes,
Diagrams.Attributes.Compile,
Diagrams.Points,
Diagrams.Located,
Diagrams.Parametric,
Expand Down Expand Up @@ -63,7 +65,6 @@ Library
Diagrams.TwoD.Ellipse,
Diagrams.TwoD.Arc,
Diagrams.TwoD.Segment,
Diagrams.TwoD.Compile,
Diagrams.TwoD.Curvature,
Diagrams.TwoD.Offset,
Diagrams.TwoD.Path,
Expand All @@ -76,6 +77,7 @@ Library
Diagrams.TwoD.Image,
Diagrams.TwoD.Adjust,
Diagrams.ThreeD.Align,
Diagrams.ThreeD.Attributes,
Diagrams.ThreeD.Camera,
Diagrams.ThreeD.Deform,
Diagrams.ThreeD.Light,
Expand All @@ -94,19 +96,19 @@ Library
array >= 0.3 && < 0.6,
semigroups >= 0.3.4 && < 0.13,
monoid-extras >= 0.3 && < 0.4,
diagrams-core >= 1.0 && < 1.1,
diagrams-core >= 1.1 && < 1.2,
active >= 0.1 && < 0.2,
vector-space >= 0.7.7 && < 0.9,
vector-space-points >= 0.1.2 && < 0.2,
vector-space-points >= 0.1.2 && < 0.3,
MemoTrie >= 0.6 && < 0.7,
colour >= 2.3.2 && < 2.4,
data-default-class < 0.1,
pretty >= 1.0.1.2 && < 1.2,
fingertree >= 0.1 && < 0.2,
intervals >= 0.3 && < 0.5,
lens >= 4.0 && < 4.1,
lens >= 4.0 && < 4.2,
tagged >= 0.7,
optparse-applicative >= 0.7 && < 0.8,
optparse-applicative >= 0.7 && < 0.9,
filepath,
safe >= 0.2 && < 0.4,
hashable >= 1.1 && < 1.3
Expand Down
113 changes: 113 additions & 0 deletions src/Diagrams/Angle.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
-----------------------------------------------------------------------------
-- |
-- Module : Diagrams.Angle
-- Copyright : (c) 2013 diagrams-lib team (see LICENSE)
-- License : BSD-style (see LICENSE)
-- Maintainer : diagrams-discuss@googlegroups.com
--
-- Type for representing angles, independent of vector-space
--
-----------------------------------------------------------------------------

module Diagrams.Angle
(
Angle
, rad, turn, deg
, fullTurn, fullCircle, angleRatio
, sinA, cosA, tanA, asinA, acosA, atanA
, (@@)
, angleBetween
, HasTheta(..)
) where

import Control.Lens (Iso', Lens', iso, review, (^.))
-- , review , (^.), _1, _2, Lens', lens)

import Data.VectorSpace

-- | Angles can be expressed in a variety of units. Internally,
-- they are represented in radians.
newtype Angle = Radians Double
deriving (Read, Show, Eq, Ord, Enum, AdditiveGroup)

instance VectorSpace Angle where
type Scalar Angle = Double
s *^ Radians t = Radians (s*t)

-- | 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 Double
rad = iso (\(Radians r) -> r) Radians

-- | 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 :: Iso' Angle Double
turn = iso (\(Radians r) -> r/2/pi) (Radians . (*(2*pi)))

-- | 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 :: Iso' Angle Double
deg = iso (\(Radians r) -> r/2/pi*360) (Radians . (*(2*pi/360)))

-- | An angle representing one full turn.
fullTurn :: Angle
fullTurn = 1 @@ turn

-- | Deprecated synonym for 'fullTurn', retained for backwards compatibility.
fullCircle :: Angle
fullCircle = fullTurn

-- | Calculate ratio between two angles.
angleRatio :: Angle -> Angle -> Double
angleRatio a b = (a^.rad) / (b^.rad)

-- | The sine of the given @Angle@.
sinA :: Angle -> Double
sinA (Radians r) = sin r

-- | The cosine of the given @Angle@.
cosA :: Angle -> Double
cosA (Radians r) = cos r

-- | The tangent function of the given @Angle@.
tanA :: Angle -> Double
tanA (Radians r) = tan r

-- | The @Angle@ with the given sine.
asinA :: Double -> Angle
asinA = Radians . asin

-- | The @Angle@ with the given cosine.
acosA :: Double -> Angle
acosA = Radians . acos

-- | The @Angle@ with the given tangent.
atanA :: Double -> Angle
atanA = Radians . atan

-- | @30 \@\@ deg@ is an @Angle@ of the given measure and units.
--
-- 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 @@ i = review i a

infixl 5 @@

-- | compute the positive angle between the two vectors in their common plane
angleBetween :: (InnerSpace v, Scalar v ~ Double) => v -> v -> Angle
angleBetween v1 v2 = acos (normalized v1 <.> normalized v2) @@ rad

------------------------------------------------------------
-- Polar Coordinates

-- | The class of types with at least one angle coordinate, called _theta.
class HasTheta t where
_theta :: Lens' t Angle
57 changes: 30 additions & 27 deletions src/Diagrams/Attributes.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
-----------------------------------------------------------------------------
-- |
-- Module : Diagrams.Attributes
Expand Down Expand Up @@ -49,24 +51,28 @@ module Diagrams.Attributes (
-- ** Miter limit
, LineMiterLimit(..), getLineMiterLimit, lineMiterLimit, lineMiterLimitA

-- ** Dashing
, Dashing(..), DashingA, getDashing, dashing

-- * Compilation utilities
, splitFills

) where

import Control.Lens (Setter, sets)
import Control.Lens (Setter, sets)
import Data.Colour
import Data.Colour.RGBSpace (RGB(..))
import Data.Colour.SRGB (toSRGB)
import Data.Colour.RGBSpace (RGB (..))
import Data.Colour.SRGB (toSRGB)
import Data.Default.Class
import Data.Maybe (fromMaybe)
import Data.Maybe (fromMaybe)
import Data.Monoid.Recommend
import Data.Semigroup
import Data.Typeable

import Diagrams.Attributes.Compile
import Diagrams.Core
import Diagrams.Core.Style (setAttr)
import Diagrams.Core.Style (setAttr)
import Diagrams.Core.Types (RTree)
import Diagrams.Located (unLoc)
import Diagrams.Path (Path, pathTrails)
import Diagrams.Trail (isLoop)

------------------------------------------------------------
-- Color -------------------------------------------------
Expand Down Expand Up @@ -333,24 +339,21 @@ lineMiterLimit = applyAttr . LineMiterLimit . Last
-- | Apply a 'LineMiterLimit' attribute.
lineMiterLimitA :: HasStyle a => LineMiterLimit -> a -> a
lineMiterLimitA = applyAttr
------------------------------------------------------------

-- | Create lines that are dashing... er, dashed.
data Dashing = Dashing [Double] Double
deriving (Typeable, Eq)
data FillLoops v = FillLoops

newtype DashingA = DashingA (Last Dashing)
deriving (Typeable, Semigroup, Eq)
instance AttributeClass DashingA

getDashing :: DashingA -> Dashing
getDashing (DashingA (Last d)) = d

-- | Set the line dashing style.
dashing :: HasStyle a =>
[Double] -- ^ A list specifying alternate lengths of on
-- and off portions of the stroke. The empty
-- list indicates no dashing.
-> Double -- ^ An offset into the dash pattern at which the
-- stroke should start.
-> a -> a
dashing ds offs = applyAttr (DashingA (Last (Dashing ds offs)))
instance Typeable v => SplitAttribute (FillLoops v) where
type AttrType (FillLoops v) = FillColor
type PrimType (FillLoops v) = Path v

primOK _ = all (isLoop . unLoc) . pathTrails

-- | Push fill attributes down until they are at the root of subtrees
-- containing only loops. This makes life much easier for backends,
-- which typically have a semantics where fill attributes are
-- applied to lines/non-closed paths as well as loops/closed paths,
-- whereas in the semantics of diagrams, fill attributes only apply
-- to loops.
splitFills :: forall b v a. Typeable v => RTree b v a -> RTree b v a
splitFills = splitAttr (FillLoops :: FillLoops v)
Loading