Skip to content

Commit

Permalink
print path variables to 4 decimal places
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Jul 9, 2015
1 parent 5a8645f commit 5b77cb6
Show file tree
Hide file tree
Showing 8 changed files with 1,114 additions and 37 deletions.
10 changes: 8 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.5.0.0 (9 Jul 2015)
---------------------

- Functions in the `Path` module output numbers to 4 decimal places
using `Data.Text.Lazy.Builder.RealFloat (formatRealFloat)` instead of `show`.

0.4.0.4 (9 Mar 2015)
---------------------

Expand Down Expand Up @@ -28,7 +34,7 @@

- Change names of attribute functions to more closely match SVG spec.
For example: SVG's cap-height is lucid-svg `cap_height`_.

0.2.1 (27 Jan 2015)
---------------------

Expand All @@ -53,4 +59,4 @@
0.1 (17 Jan 2015)
-----------------

- Initial release.
- Initial release.
2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

3 changes: 3 additions & 0 deletions examples/path.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/simple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lucid-svg.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: lucid-svg
version: 0.4.0.4
version: 0.5.0.0
synopsis: DSL for SVG using lucid for HTML
homepage: http://github.com/jeffreyrosenbluth/lucid-svg.git
license: BSD3
Expand Down
4 changes: 2 additions & 2 deletions src/Lucid/Svg/Attributes.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

-------------------------------------------------------------------------------
-- |
-- Module : Lucid.Svg.Attributes
Expand All @@ -11,7 +11,7 @@
--
-------------------------------------------------------------------------------

module Lucid.Svg.Attributes where
module Lucid.Svg.Attributes where

import Lucid.Base
import Data.Text (Text)
Expand Down
63 changes: 33 additions & 30 deletions src/Lucid/Svg/Path.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,93 +15,96 @@

module Lucid.Svg.Path where

import Data.Text (Text, pack)
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Lazy (toStrict)
import Data.Text.Lazy.Builder (toLazyText)
import Data.Text.Lazy.Builder.RealFloat

-- | Convert a showable object to Text.
toText :: Show a => a -> Text
toText = pack . show
-- | Convert a number to Text.
toText :: RealFloat a => a -> Text
toText = toStrict . toLazyText . formatRealFloat Fixed (Just 4)

-- | moveto (absolute)
mA :: Show a => a -> a -> Text
mA :: RealFloat a => a -> a -> Text
mA x y = T.concat ["M " ,toText x, ",", toText y, " "]

-- | moveto (relative)
mR :: Show a => a -> a -> Text
mR :: RealFloat a => a -> a -> Text
mR dx dy = T.concat ["m ", toText dx, ",", toText dy, " "]

-- | lineto (absolute)
lA :: Show a => a -> a -> Text
lA :: RealFloat a => a -> a -> Text
lA x y = T.concat ["L ", toText x, ",", toText y, " "]

-- | lineto (relative)
lR :: Show a => a -> a -> Text
lR :: RealFloat a => a -> a -> Text
lR dx dy = T.concat ["l ", toText dx, ",", toText dy, " "]

-- | horizontal lineto (absolute)
hA :: Show a => a -> Text
hA :: RealFloat a => a -> Text
hA x = T.concat ["H ", toText x, " "]

-- | horizontal lineto (relative)
hR :: Show a => a -> Text
hR :: RealFloat a => a -> Text
hR dx = T.concat ["h ", toText dx, " "]

-- | vertical lineto (absolute)
vA :: Show a => a -> Text
vA :: RealFloat a => a -> Text
vA y = T.concat ["V ", toText y, " "]

-- | vertical lineto (relative)
vR :: Show a => a -> Text
vR :: RealFloat a => a -> Text
vR dy = T.concat ["v ", toText dy, " "]

-- | Cubic Bezier curve (absolute)
cA :: Show a => a -> a -> a -> a -> a -> a -> Text
cA :: RealFloat a => a -> a -> a -> a -> a -> a -> Text
cA c1x c1y c2x c2y x y = T.concat
[ "C ", toText c1x, ",", toText c1y, " ", toText c2x, ","
, toText c2y, " ", toText x, " ", toText y]

-- | Cubic Bezier curve (relative)
cR :: Show a => a -> a -> a -> a -> a -> a -> Text
cR :: RealFloat a => a -> a -> a -> a -> a -> a -> Text
cR dc1x dc1y dc2x dc2y dx dy = T.concat
[ "c ", toText dc1x, ",", toText dc1y, " ", toText dc2x
, ",", toText dc2y, " ", toText dx, " ", toText dy]

-- | Smooth Cubic Bezier curve (absolute)
sA :: Show a => a -> a -> a -> a -> Text
sA :: RealFloat a => a -> a -> a -> a -> Text
sA c2x c2y x y = T.concat
["S ", toText c2x, ",", toText c2y, " ", toText x, ",", toText y, " "]

-- | Smooth Cubic Bezier curve (relative)
sR :: Show a => a -> a -> a -> a -> Text
sR :: RealFloat a => a -> a -> a -> a -> Text
sR dc2x dc2y dx dy = T.concat
["s ", toText dc2x, ",", toText dc2y, " ", toText dx, ",", toText dy, " "]

-- | Quadratic Bezier curve (absolute)
qA :: Show a => a -> a -> a -> a -> Text
qA :: RealFloat a => a -> a -> a -> a -> Text
qA cx cy x y = T.concat
["Q ", toText cx, ",", toText cy, " ", toText x, ",", toText y, " "]

-- | Quadratic Bezier curve (relative)
qR :: Show a => a -> a -> a -> a -> Text
qR :: RealFloat a => a -> a -> a -> a -> Text
qR dcx dcy dx dy = T.concat
["q ", toText dcx, ",", toText dcy, " ", toText dx, ",", toText dy, " " ]

-- | Smooth Quadratic Bezier curve (absolute)
tA :: Show a => a -> a -> Text
tA :: RealFloat a => a -> a -> Text
tA x y = T.concat ["T ", " ", toText x, ",", toText y, " "]

-- | Smooth Quadratic Bezier curve (relative)
tR :: Show a => a -> a -> Text
tR :: RealFloat a => a -> a -> Text
tR x y = T.concat [ "t ", toText x, ",", toText y, " "]

-- | Arc (absolute)
aA :: Show a => a -> a -> a -> a -> a -> a -> a -> Text
aA :: RealFloat a => a -> a -> a -> a -> a -> a -> a -> Text
aA rx ry xrot largeFlag sweepFlag x y = T.concat
[ "A ", toText rx, ",", toText ry, " ", toText xrot, " ", toText largeFlag
, " ", toText sweepFlag, " ", toText x, " ", toText y, " "]

-- | Arc (relative)
aR :: Show a => a -> a -> a -> a -> a -> a -> a -> Text
aR :: RealFloat a => a -> a -> a -> a -> a -> a -> a -> Text
aR rx ry xrot largeFlag sweepFlag x y = T.concat
[ "a ", toText rx, ",", toText ry, " ", toText xrot, " ", toText largeFlag
, " ", toText sweepFlag, " ", toText x, " ", toText y, " "]
Expand All @@ -112,32 +115,32 @@ z = "Z"

-- | SVG Transform components
-- | Specifies a translation by @x@ and @y@
translate :: Show a => a -> a -> Text
translate :: RealFloat a => a -> a -> Text
translate x y = T.concat ["translate(", toText x, " ", toText y, ")"]

-- | Specifies a scale operation by @x@ and @y@
scale :: Show a => a -> a -> Text
scale :: RealFloat a => a -> a -> Text
scale x y = T.concat ["scale(", toText x, " ", toText y, ")"]

-- | Specifies a rotation by @rotate-angle@ degrees
rotate :: Show a => a -> Text
rotate :: RealFloat a => a -> Text
rotate angle = T.concat ["rotate(", toText angle, ")"]

-- | Specifies a rotation by @rotate-angle@ degrees about the given time @rx,ry@
rotateAround :: Show a => a -> a -> a -> Text
rotateAround :: RealFloat a => a -> a -> a -> Text
rotateAround angle rx ry = T.concat
["rotate(", toText angle, ",", toText rx, ",", toText ry, ")"]

-- | Skew tansformation along x-axis
skewX :: Show a => a -> Text
skewX :: RealFloat a => a -> Text
skewX angle = T.concat ["skewX(", toText angle, ")"]

-- | Skew tansformation along y-axis
skewY :: Show a => a -> Text
skewY :: RealFloat a => a -> Text
skewY angle = T.concat ["skewY(", toText angle, ")"]

-- | Specifies a transform in the form of a transformation matrix
matrix :: Show a => a -> a -> a -> a -> a -> a -> Text
matrix :: RealFloat a => a -> a -> a -> a -> a -> a -> Text
matrix a b c d e f = T.concat
[ "matrix(", toText a, ",", toText b, ",", toText c
, ",", toText d, ",", toText e, ",", toText f, ")"]
Loading

0 comments on commit 5b77cb6

Please sign in to comment.