{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Path.Parser
(
parsePath,
pathParser,
command,
svgToPathData,
pathDataToSvg,
PathCommand (..),
Origin (..),
PathCursor (..),
toPathDatas,
)
where
import Chart.Data
import Chart.Parse
import Control.Applicative hiding (many, optional, some, (<|>))
import Control.Monad.State.Lazy
import Data.ByteString (ByteString)
import Data.ByteString.Char8 qualified as C8
import Data.Char hiding (isDigit)
import Data.Data
import Data.FormatN
import Data.Path (ArcInfo (ArcInfo), PathData (..))
import Data.Text.Encoding (encodeUtf8)
import GHC.Generics
import GHC.OverloadedLabels ()
import NumHask.Prelude hiding (many, optional, some, (<|>))
import Optics.Core hiding ((<|))
runParserMaybe :: Parser e a -> ByteString -> Maybe a
runParserMaybe :: forall e a. Parser e a -> ByteString -> Maybe a
runParserMaybe Parser e a
p ByteString
b = case Parser e a -> ByteString -> Result e a
forall e a. Parser e a -> ByteString -> Result e a
runParser Parser e a
p ByteString
b of
OK a
r ByteString
_ -> a -> Maybe a
forall a. a -> Maybe a
Just a
r
Result e a
Fail -> Maybe a
forall a. Maybe a
Nothing
Err e
_ -> Maybe a
forall a. Maybe a
Nothing
comma_ :: Parser e ()
comma_ :: forall e. Parser e ()
comma_ = Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
','
ws_ :: Parser e ()
ws_ :: forall e. Parser e ()
ws_ = Parser e ()
forall e. Parser e ()
go
where
go :: Parser e ()
go = ((Char -> Bool) -> Parser e Char
forall e. (Char -> Bool) -> Parser e Char
satisfy Char -> Bool
isWhitespace Parser e Char -> Parser e () -> Parser e ()
forall a b. Parser e a -> Parser e b -> Parser e b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser e ()
go) Parser e () -> Parser e () -> Parser e ()
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> () -> Parser e ()
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
isWhitespace :: Char -> Bool
isWhitespace Char
c = Char
c Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
' ', Char
'\n', Char
'\t', Char
'\r', Char
'\f']
parsePath :: ByteString -> Maybe [PathCommand]
parsePath :: ByteString -> Maybe [PathCommand]
parsePath = Parser (ZonkAny 0) [PathCommand]
-> ByteString -> Maybe [PathCommand]
forall e a. Parser e a -> ByteString -> Maybe a
runParserMaybe Parser (ZonkAny 0) [PathCommand]
forall e. Parser e [PathCommand]
pathParser
commaWsp :: Parser e (Maybe ())
commaWsp :: forall e. Parser e (Maybe ())
commaWsp = Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e (Maybe ()) -> Parser e (Maybe ())
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e () -> Parser e (Maybe ())
forall e a. Parser e a -> Parser e (Maybe a)
optional Parser e ()
forall e. Parser e ()
comma_ Parser e (Maybe ()) -> Parser e () -> Parser e (Maybe ())
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e ()
forall e. Parser e ()
ws_
minus :: Parser e ()
minus :: forall e. Parser e ()
minus = Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'-' Parser e () -> Parser e () -> Parser e ()
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ByteString -> Parser e ()
forall e. ByteString -> Parser e ()
byteString ByteString
"¯"
digit :: Parser e Int
digit :: forall e. Parser e Int
digit = (\Char
c -> Char -> Int
ord Char
c Int -> Int -> Int
forall a. Subtractive a => a -> a -> a
- Char -> Int
ord Char
'0') (Char -> Int) -> Parser e Char -> Parser e Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> Bool) -> Parser e Char
forall e. (Char -> Bool) -> Parser e Char
satisfyAscii Char -> Bool
isDigit
digits :: Parser e (Int, Int)
digits :: forall e. Parser e (Int, Int)
digits = do
(place, n) <- (Int -> (Int, Int) -> (Int, Int))
-> Parser e Int -> Parser e (Int, Int) -> Parser e (Int, Int)
forall a b e.
(a -> b -> b) -> Parser e a -> Parser e b -> Parser e b
chainr (\Int
n (Int
place, Int
acc) -> (Int
place Int -> Int -> Int
forall a. Multiplicative a => a -> a -> a
* Int
10, Int
acc Int -> Int -> Int
forall a. Additive a => a -> a -> a
+ Int
place Int -> Int -> Int
forall a. Multiplicative a => a -> a -> a
* Int
n)) Parser e Int
forall e. Parser e Int
digit ((Int, Int) -> Parser e (Int, Int)
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
1, Int
0))
case place of
Int
1 -> Parser e (Int, Int)
forall a. Parser e a
forall (f :: * -> *) a. Alternative f => f a
empty
Int
_ -> (Int, Int) -> Parser e (Int, Int)
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
place, Int
n)
double :: Parser e Double
double :: forall e. Parser e Double
double = do
(placel, nl) <- Parser e (Int, Int)
forall e. Parser e (Int, Int)
digits
withOption
(char '.' *> digits)
( \(Int
placer, Int
nr) ->
case Int
placel of
Int
1 -> Parser e Double
forall a. Parser e a
forall (f :: * -> *) a. Alternative f => f a
empty
Int
_ -> Double -> Parser e Double
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Double -> Parser e Double) -> Double -> Parser e Double
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. FromIntegral a b => b -> a
fromIntegral Int
nl Double -> Double -> Double
forall a. Additive a => a -> a -> a
+ Int -> Double
forall a b. FromIntegral a b => b -> a
fromIntegral Int
nr Double -> Double -> Double
forall a. Divisive a => a -> a -> a
/ Int -> Double
forall a b. FromIntegral a b => b -> a
fromIntegral Int
placer
)
( case placel of
Int
1 -> Parser e Double
forall a. Parser e a
forall (f :: * -> *) a. Alternative f => f a
empty
Int
_ -> Double -> Parser e Double
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Double -> Parser e Double) -> Double -> Parser e Double
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. FromIntegral a b => b -> a
fromIntegral Int
nl
)
signed :: (Subtractive b) => Parser e b -> Parser e b
signed :: forall b e. Subtractive b => Parser e b -> Parser e b
signed Parser e b
p = do
m <- Parser e () -> Parser e (Maybe ())
forall e a. Parser e a -> Parser e (Maybe a)
optional Parser e ()
forall e. Parser e ()
minus
case m of
Maybe ()
Nothing -> Parser e b
p
Just () -> b -> b
forall a. Subtractive a => a -> a
negate (b -> b) -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e b
p
num :: Parser e Double
num :: forall e. Parser e Double
num = Parser e Double -> Parser e Double
forall b e. Subtractive b => Parser e b -> Parser e b
signed Parser e Double
forall e. Parser e Double
double
point :: Parser e (Point Double)
point :: forall e. Parser e (Point Double)
point = Double -> Double -> Point Double
forall a. a -> a -> Point a
Point (Double -> Double -> Point Double)
-> Parser e Double -> Parser e (Double -> Point Double)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e Double
forall e. Parser e Double
num Parser e (Double -> Point Double)
-> Parser e (Maybe ()) -> Parser e (Double -> Point Double)
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp Parser e (Double -> Point Double)
-> Parser e Double -> Parser e (Point Double)
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e Double
forall e. Parser e Double
num
numComma :: Parser e Double
numComma :: forall e. Parser e Double
numComma = Parser e Double
forall e. Parser e Double
num Parser e Double -> Parser e (Maybe ()) -> Parser e Double
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp
points :: Parser e [Point Double]
points :: forall e. Parser e [Point Double]
points = (:) (Point Double -> [Point Double] -> [Point Double])
-> Parser e (Point Double)
-> Parser e ([Point Double] -> [Point Double])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e (Point Double)
forall e. Parser e (Point Double)
point Parser e ([Point Double] -> [Point Double])
-> Parser e [Point Double] -> Parser e [Point Double]
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e (Point Double) -> Parser e [Point Double]
forall e a. Parser e a -> Parser e [a]
many (Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp Parser e (Maybe ())
-> Parser e (Point Double) -> Parser e (Point Double)
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e (Point Double)
forall e. Parser e (Point Double)
point) Parser e [Point Double]
-> Parser e [Point Double] -> Parser e [Point Double]
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Point Double] -> Parser e [Point Double]
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
pointPair :: Parser e (Point Double, Point Double)
pointPair :: forall e. Parser e (Point Double, Point Double)
pointPair = (,) (Point Double -> Point Double -> (Point Double, Point Double))
-> Parser e (Point Double)
-> Parser e (Point Double -> (Point Double, Point Double))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e (Point Double)
forall e. Parser e (Point Double)
point Parser e (Point Double -> (Point Double, Point Double))
-> Parser e (Maybe ())
-> Parser e (Point Double -> (Point Double, Point Double))
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp Parser e (Point Double -> (Point Double, Point Double))
-> Parser e (Point Double) -> Parser e (Point Double, Point Double)
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e (Point Double)
forall e. Parser e (Point Double)
point
pointPairs :: Parser e [(Point Double, Point Double)]
pointPairs :: forall e. Parser e [(Point Double, Point Double)]
pointPairs = (:) ((Point Double, Point Double)
-> [(Point Double, Point Double)]
-> [(Point Double, Point Double)])
-> Parser e (Point Double, Point Double)
-> Parser
e
([(Point Double, Point Double)] -> [(Point Double, Point Double)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e (Point Double, Point Double)
forall e. Parser e (Point Double, Point Double)
pointPair Parser
e
([(Point Double, Point Double)] -> [(Point Double, Point Double)])
-> Parser e [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e (Point Double, Point Double)
-> Parser e [(Point Double, Point Double)]
forall e a. Parser e a -> Parser e [a]
many (Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp Parser e (Maybe ())
-> Parser e (Point Double, Point Double)
-> Parser e (Point Double, Point Double)
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e (Point Double, Point Double)
forall e. Parser e (Point Double, Point Double)
pointPair) Parser e [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
nums :: Parser e [Double]
nums :: forall e. Parser e [Double]
nums = (:) (Double -> [Double] -> [Double])
-> Parser e Double -> Parser e ([Double] -> [Double])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e Double
forall e. Parser e Double
num Parser e ([Double] -> [Double])
-> Parser e [Double] -> Parser e [Double]
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e Double -> Parser e [Double]
forall e a. Parser e a -> Parser e [a]
many (Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp Parser e (Maybe ()) -> Parser e Double -> Parser e Double
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e Double
forall e. Parser e Double
num) Parser e [Double] -> Parser e [Double] -> Parser e [Double]
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Double] -> Parser e [Double]
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
flag :: Parser e Bool
flag :: forall e. Parser e Bool
flag = (Int -> Bool) -> Parser e Int -> Parser e Bool
forall a b. (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0) Parser e Int
forall e. Parser e Int
digit
manyComma :: Parser e a -> Parser e [a]
manyComma :: forall e a. Parser e a -> Parser e [a]
manyComma Parser e a
a = (:) (a -> [a] -> [a]) -> Parser e a -> Parser e ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e a
a Parser e ([a] -> [a]) -> Parser e [a] -> Parser e [a]
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e a -> Parser e [a]
forall e a. Parser e a -> Parser e [a]
many (Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp Parser e (Maybe ()) -> Parser e a -> Parser e a
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e a
a) Parser e [a] -> Parser e [a] -> Parser e [a]
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [a] -> Parser e [a]
forall a. a -> Parser e a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
flagComma :: Parser e Bool
flagComma :: forall e. Parser e Bool
flagComma = Parser e Bool
forall e. Parser e Bool
flag Parser e Bool -> Parser e (Maybe ()) -> Parser e Bool
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp
curveToArgs ::
Parser
e
(Point Double, Point Double, Point Double)
curveToArgs :: forall e. Parser e (Point Double, Point Double, Point Double)
curveToArgs =
(,,)
(Point Double
-> Point Double
-> Point Double
-> (Point Double, Point Double, Point Double))
-> Parser e (Point Double)
-> Parser
e
(Point Double
-> Point Double -> (Point Double, Point Double, Point Double))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser e (Point Double)
forall e. Parser e (Point Double)
point Parser e (Point Double)
-> Parser e (Maybe ()) -> Parser e (Point Double)
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp)
Parser
e
(Point Double
-> Point Double -> (Point Double, Point Double, Point Double))
-> Parser e (Point Double)
-> Parser
e (Point Double -> (Point Double, Point Double, Point Double))
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e (Point Double)
forall e. Parser e (Point Double)
point Parser e (Point Double)
-> Parser e (Maybe ()) -> Parser e (Point Double)
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp)
Parser
e (Point Double -> (Point Double, Point Double, Point Double))
-> Parser e (Point Double)
-> Parser e (Point Double, Point Double, Point Double)
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e (Point Double)
forall e. Parser e (Point Double)
point
ellipticalArgs ::
Parser
e
(Double, Double, Double, Bool, Bool, Point Double)
ellipticalArgs :: forall e.
Parser e (Double, Double, Double, Bool, Bool, Point Double)
ellipticalArgs =
(,,,,,)
(Double
-> Double
-> Double
-> Bool
-> Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
-> Parser e Double
-> Parser
e
(Double
-> Double
-> Bool
-> Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser e Double
forall e. Parser e Double
numComma
Parser
e
(Double
-> Double
-> Bool
-> Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
-> Parser e Double
-> Parser
e
(Double
-> Bool
-> Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e Double
forall e. Parser e Double
numComma
Parser
e
(Double
-> Bool
-> Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
-> Parser e Double
-> Parser
e
(Bool
-> Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e Double
forall e. Parser e Double
numComma
Parser
e
(Bool
-> Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
-> Parser e Bool
-> Parser
e
(Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e Bool
forall e. Parser e Bool
flagComma
Parser
e
(Bool
-> Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
-> Parser e Bool
-> Parser
e
(Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e Bool
forall e. Parser e Bool
flagComma
Parser
e
(Point Double
-> (Double, Double, Double, Bool, Bool, Point Double))
-> Parser e (Point Double)
-> Parser e (Double, Double, Double, Bool, Bool, Point Double)
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser e (Point Double)
forall e. Parser e (Point Double)
point
pathParser :: Parser e [PathCommand]
pathParser :: forall e. Parser e [PathCommand]
pathParser = Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [PathCommand] -> Parser e [PathCommand]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e PathCommand -> Parser e [PathCommand]
forall e a. Parser e a -> Parser e [a]
manyComma Parser e PathCommand
forall e. Parser e PathCommand
command
command :: Parser e PathCommand
command :: forall e. Parser e PathCommand
command =
(Origin -> [Point Double] -> PathCommand
MoveTo Origin
OriginAbsolute ([Point Double] -> PathCommand)
-> Parser e () -> Parser e ([Point Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'M' Parser e ([Point Double] -> PathCommand)
-> Parser e [Point Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Point Double] -> Parser e [Point Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Point Double]
forall e. Parser e [Point Double]
points))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Point Double] -> PathCommand
MoveTo Origin
OriginRelative ([Point Double] -> PathCommand)
-> Parser e () -> Parser e ([Point Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'm' Parser e ([Point Double] -> PathCommand)
-> Parser e [Point Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Point Double] -> Parser e [Point Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Point Double]
forall e. Parser e [Point Double]
points))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Point Double] -> PathCommand
LineTo Origin
OriginAbsolute ([Point Double] -> PathCommand)
-> Parser e () -> Parser e ([Point Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'L' Parser e ([Point Double] -> PathCommand)
-> Parser e [Point Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Point Double] -> Parser e [Point Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Point Double]
forall e. Parser e [Point Double]
points))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Point Double] -> PathCommand
LineTo Origin
OriginRelative ([Point Double] -> PathCommand)
-> Parser e () -> Parser e ([Point Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'l' Parser e ([Point Double] -> PathCommand)
-> Parser e [Point Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Point Double] -> Parser e [Point Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Point Double]
forall e. Parser e [Point Double]
points))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Double] -> PathCommand
HorizontalTo Origin
OriginAbsolute ([Double] -> PathCommand)
-> Parser e () -> Parser e ([Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'H' Parser e ([Double] -> PathCommand)
-> Parser e [Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Double] -> Parser e [Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Double]
forall e. Parser e [Double]
nums))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Double] -> PathCommand
HorizontalTo Origin
OriginRelative ([Double] -> PathCommand)
-> Parser e () -> Parser e ([Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'h' Parser e ([Double] -> PathCommand)
-> Parser e [Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Double] -> Parser e [Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Double]
forall e. Parser e [Double]
nums))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Double] -> PathCommand
VerticalTo Origin
OriginAbsolute ([Double] -> PathCommand)
-> Parser e () -> Parser e ([Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'V' Parser e ([Double] -> PathCommand)
-> Parser e [Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Double] -> Parser e [Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Double]
forall e. Parser e [Double]
nums))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Double] -> PathCommand
VerticalTo Origin
OriginRelative ([Double] -> PathCommand)
-> Parser e () -> Parser e ([Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'v' Parser e ([Double] -> PathCommand)
-> Parser e [Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Double] -> Parser e [Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Double]
forall e. Parser e [Double]
nums))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin
-> [(Point Double, Point Double, Point Double)] -> PathCommand
CurveTo Origin
OriginAbsolute ([(Point Double, Point Double, Point Double)] -> PathCommand)
-> Parser e ()
-> Parser
e ([(Point Double, Point Double, Point Double)] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'C' Parser
e ([(Point Double, Point Double, Point Double)] -> PathCommand)
-> Parser e [(Point Double, Point Double, Point Double)]
-> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Point Double, Point Double, Point Double)]
-> Parser e [(Point Double, Point Double, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e (Point Double, Point Double, Point Double)
-> Parser e [(Point Double, Point Double, Point Double)]
forall e a. Parser e a -> Parser e [a]
manyComma Parser e (Point Double, Point Double, Point Double)
forall e. Parser e (Point Double, Point Double, Point Double)
curveToArgs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin
-> [(Point Double, Point Double, Point Double)] -> PathCommand
CurveTo Origin
OriginRelative ([(Point Double, Point Double, Point Double)] -> PathCommand)
-> Parser e ()
-> Parser
e ([(Point Double, Point Double, Point Double)] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'c' Parser
e ([(Point Double, Point Double, Point Double)] -> PathCommand)
-> Parser e [(Point Double, Point Double, Point Double)]
-> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Point Double, Point Double, Point Double)]
-> Parser e [(Point Double, Point Double, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e (Point Double, Point Double, Point Double)
-> Parser e [(Point Double, Point Double, Point Double)]
forall e a. Parser e a -> Parser e [a]
manyComma Parser e (Point Double, Point Double, Point Double)
forall e. Parser e (Point Double, Point Double, Point Double)
curveToArgs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [(Point Double, Point Double)] -> PathCommand
SmoothCurveTo Origin
OriginAbsolute ([(Point Double, Point Double)] -> PathCommand)
-> Parser e ()
-> Parser e ([(Point Double, Point Double)] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'S' Parser e ([(Point Double, Point Double)] -> PathCommand)
-> Parser e [(Point Double, Point Double)] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [(Point Double, Point Double)]
forall e. Parser e [(Point Double, Point Double)]
pointPairs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [(Point Double, Point Double)] -> PathCommand
SmoothCurveTo Origin
OriginRelative ([(Point Double, Point Double)] -> PathCommand)
-> Parser e ()
-> Parser e ([(Point Double, Point Double)] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
's' Parser e ([(Point Double, Point Double)] -> PathCommand)
-> Parser e [(Point Double, Point Double)] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [(Point Double, Point Double)]
forall e. Parser e [(Point Double, Point Double)]
pointPairs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [(Point Double, Point Double)] -> PathCommand
QuadraticBezier Origin
OriginAbsolute ([(Point Double, Point Double)] -> PathCommand)
-> Parser e ()
-> Parser e ([(Point Double, Point Double)] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'Q' Parser e ([(Point Double, Point Double)] -> PathCommand)
-> Parser e [(Point Double, Point Double)] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [(Point Double, Point Double)]
forall e. Parser e [(Point Double, Point Double)]
pointPairs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [(Point Double, Point Double)] -> PathCommand
QuadraticBezier Origin
OriginRelative ([(Point Double, Point Double)] -> PathCommand)
-> Parser e ()
-> Parser e ([(Point Double, Point Double)] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'q' Parser e ([(Point Double, Point Double)] -> PathCommand)
-> Parser e [(Point Double, Point Double)] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Point Double, Point Double)]
-> Parser e [(Point Double, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [(Point Double, Point Double)]
forall e. Parser e [(Point Double, Point Double)]
pointPairs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Point Double] -> PathCommand
SmoothQuadraticBezierCurveTo Origin
OriginAbsolute ([Point Double] -> PathCommand)
-> Parser e () -> Parser e ([Point Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'T' Parser e ([Point Double] -> PathCommand)
-> Parser e [Point Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Point Double] -> Parser e [Point Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Point Double]
forall e. Parser e [Point Double]
points))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin -> [Point Double] -> PathCommand
SmoothQuadraticBezierCurveTo Origin
OriginRelative ([Point Double] -> PathCommand)
-> Parser e () -> Parser e ([Point Double] -> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
't' Parser e ([Point Double] -> PathCommand)
-> Parser e [Point Double] -> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e () -> Parser e [Point Double] -> Parser e [Point Double]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e [Point Double]
forall e. Parser e [Point Double]
points))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin
-> [(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand
EllipticalArc Origin
OriginAbsolute ([(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand)
-> Parser e ()
-> Parser
e
([(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'A' Parser
e
([(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand)
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
-> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e (Double, Double, Double, Bool, Bool, Point Double)
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
forall e a. Parser e a -> Parser e [a]
manyComma Parser e (Double, Double, Double, Bool, Bool, Point Double)
forall e.
Parser e (Double, Double, Double, Bool, Bool, Point Double)
ellipticalArgs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Origin
-> [(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand
EllipticalArc Origin
OriginRelative ([(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand)
-> Parser e ()
-> Parser
e
([(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand)
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'a' Parser
e
([(Double, Double, Double, Bool, Bool, Point Double)]
-> PathCommand)
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
-> Parser e PathCommand
forall a b. Parser e (a -> b) -> Parser e a -> Parser e b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser e ()
forall e. Parser e ()
ws_ Parser e ()
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
forall a b. Parser e a -> Parser e b -> Parser e b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser e (Double, Double, Double, Bool, Bool, Point Double)
-> Parser e [(Double, Double, Double, Bool, Bool, Point Double)]
forall e a. Parser e a -> Parser e [a]
manyComma Parser e (Double, Double, Double, Bool, Bool, Point Double)
forall e.
Parser e (Double, Double, Double, Bool, Bool, Point Double)
ellipticalArgs))
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (PathCommand
EndPath PathCommand -> Parser e () -> Parser e PathCommand
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'Z' Parser e PathCommand -> Parser e (Maybe ()) -> Parser e PathCommand
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp)
Parser e PathCommand
-> Parser e PathCommand -> Parser e PathCommand
forall a. Parser e a -> Parser e a -> Parser e a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (PathCommand
EndPath PathCommand -> Parser e () -> Parser e PathCommand
forall a b. a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser e ()
forall e. Char -> Parser e ()
char Char
'z' Parser e PathCommand -> Parser e (Maybe ()) -> Parser e PathCommand
forall a b. Parser e a -> Parser e b -> Parser e a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser e (Maybe ())
forall e. Parser e (Maybe ())
commaWsp)
data PathCommand
=
MoveTo !Origin ![Point Double]
|
LineTo !Origin ![Point Double]
|
HorizontalTo !Origin ![Double]
|
VerticalTo !Origin ![Double]
|
CurveTo !Origin ![(Point Double, Point Double, Point Double)]
|
SmoothCurveTo !Origin ![(Point Double, Point Double)]
|
QuadraticBezier !Origin ![(Point Double, Point Double)]
|
SmoothQuadraticBezierCurveTo !Origin ![Point Double]
|
EllipticalArc !Origin ![(Double, Double, Double, Bool, Bool, Point Double)]
|
EndPath
deriving (PathCommand -> PathCommand -> Bool
(PathCommand -> PathCommand -> Bool)
-> (PathCommand -> PathCommand -> Bool) -> Eq PathCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PathCommand -> PathCommand -> Bool
== :: PathCommand -> PathCommand -> Bool
$c/= :: PathCommand -> PathCommand -> Bool
/= :: PathCommand -> PathCommand -> Bool
Eq, Int -> PathCommand -> ShowS
[PathCommand] -> ShowS
PathCommand -> [Char]
(Int -> PathCommand -> ShowS)
-> (PathCommand -> [Char])
-> ([PathCommand] -> ShowS)
-> Show PathCommand
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PathCommand -> ShowS
showsPrec :: Int -> PathCommand -> ShowS
$cshow :: PathCommand -> [Char]
show :: PathCommand -> [Char]
$cshowList :: [PathCommand] -> ShowS
showList :: [PathCommand] -> ShowS
Show, ReadPrec [PathCommand]
ReadPrec PathCommand
Int -> ReadS PathCommand
ReadS [PathCommand]
(Int -> ReadS PathCommand)
-> ReadS [PathCommand]
-> ReadPrec PathCommand
-> ReadPrec [PathCommand]
-> Read PathCommand
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PathCommand
readsPrec :: Int -> ReadS PathCommand
$creadList :: ReadS [PathCommand]
readList :: ReadS [PathCommand]
$creadPrec :: ReadPrec PathCommand
readPrec :: ReadPrec PathCommand
$creadListPrec :: ReadPrec [PathCommand]
readListPrec :: ReadPrec [PathCommand]
Read, (forall x. PathCommand -> Rep PathCommand x)
-> (forall x. Rep PathCommand x -> PathCommand)
-> Generic PathCommand
forall x. Rep PathCommand x -> PathCommand
forall x. PathCommand -> Rep PathCommand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PathCommand -> Rep PathCommand x
from :: forall x. PathCommand -> Rep PathCommand x
$cto :: forall x. Rep PathCommand x -> PathCommand
to :: forall x. Rep PathCommand x -> PathCommand
Generic, Typeable PathCommand
Typeable PathCommand =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCommand -> c PathCommand)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCommand)
-> (PathCommand -> Constr)
-> (PathCommand -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCommand))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PathCommand))
-> ((forall b. Data b => b -> b) -> PathCommand -> PathCommand)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r)
-> (forall u. (forall d. Data d => d -> u) -> PathCommand -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> PathCommand -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand)
-> Data PathCommand
PathCommand -> Constr
PathCommand -> DataType
(forall b. Data b => b -> b) -> PathCommand -> PathCommand
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PathCommand -> u
forall u. (forall d. Data d => d -> u) -> PathCommand -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCommand
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCommand -> c PathCommand
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCommand)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PathCommand)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCommand -> c PathCommand
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCommand -> c PathCommand
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCommand
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCommand
$ctoConstr :: PathCommand -> Constr
toConstr :: PathCommand -> Constr
$cdataTypeOf :: PathCommand -> DataType
dataTypeOf :: PathCommand -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCommand)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCommand)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PathCommand)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PathCommand)
$cgmapT :: (forall b. Data b => b -> b) -> PathCommand -> PathCommand
gmapT :: (forall b. Data b => b -> b) -> PathCommand -> PathCommand
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCommand -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PathCommand -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PathCommand -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PathCommand -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PathCommand -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCommand -> m PathCommand
Data)
data Origin
=
OriginAbsolute
|
OriginRelative
deriving (Origin -> Origin -> Bool
(Origin -> Origin -> Bool)
-> (Origin -> Origin -> Bool) -> Eq Origin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Origin -> Origin -> Bool
== :: Origin -> Origin -> Bool
$c/= :: Origin -> Origin -> Bool
/= :: Origin -> Origin -> Bool
Eq, Int -> Origin -> ShowS
[Origin] -> ShowS
Origin -> [Char]
(Int -> Origin -> ShowS)
-> (Origin -> [Char]) -> ([Origin] -> ShowS) -> Show Origin
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Origin -> ShowS
showsPrec :: Int -> Origin -> ShowS
$cshow :: Origin -> [Char]
show :: Origin -> [Char]
$cshowList :: [Origin] -> ShowS
showList :: [Origin] -> ShowS
Show, ReadPrec [Origin]
ReadPrec Origin
Int -> ReadS Origin
ReadS [Origin]
(Int -> ReadS Origin)
-> ReadS [Origin]
-> ReadPrec Origin
-> ReadPrec [Origin]
-> Read Origin
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Origin
readsPrec :: Int -> ReadS Origin
$creadList :: ReadS [Origin]
readList :: ReadS [Origin]
$creadPrec :: ReadPrec Origin
readPrec :: ReadPrec Origin
$creadListPrec :: ReadPrec [Origin]
readListPrec :: ReadPrec [Origin]
Read, (forall x. Origin -> Rep Origin x)
-> (forall x. Rep Origin x -> Origin) -> Generic Origin
forall x. Rep Origin x -> Origin
forall x. Origin -> Rep Origin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Origin -> Rep Origin x
from :: forall x. Origin -> Rep Origin x
$cto :: forall x. Rep Origin x -> Origin
to :: forall x. Rep Origin x -> Origin
Generic, Typeable Origin
Typeable Origin =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Origin -> c Origin)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Origin)
-> (Origin -> Constr)
-> (Origin -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Origin))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Origin))
-> ((forall b. Data b => b -> b) -> Origin -> Origin)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Origin -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Origin -> r)
-> (forall u. (forall d. Data d => d -> u) -> Origin -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Origin -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin)
-> Data Origin
Origin -> Constr
Origin -> DataType
(forall b. Data b => b -> b) -> Origin -> Origin
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Origin -> u
forall u. (forall d. Data d => d -> u) -> Origin -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Origin -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Origin -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Origin
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Origin -> c Origin
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Origin)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Origin)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Origin -> c Origin
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Origin -> c Origin
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Origin
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Origin
$ctoConstr :: Origin -> Constr
toConstr :: Origin -> Constr
$cdataTypeOf :: Origin -> DataType
dataTypeOf :: Origin -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Origin)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Origin)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Origin)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Origin)
$cgmapT :: (forall b. Data b => b -> b) -> Origin -> Origin
gmapT :: (forall b. Data b => b -> b) -> Origin -> Origin
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Origin -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Origin -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Origin -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Origin -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Origin -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Origin -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Origin -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Origin -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Origin -> m Origin
Data)
pointToSvgCoords :: Point Double -> Point Double
pointToSvgCoords :: Point Double -> Point Double
pointToSvgCoords (Point Double
x Double
y) = Double -> Double -> Point Double
forall a. a -> a -> Point a
Point Double
x (-Double
y)
svgCoords :: PathData Double -> PathData Double
svgCoords :: PathData Double -> PathData Double
svgCoords (CubicP Point Double
a Point Double
b Point Double
p) = Point Double -> Point Double -> Point Double -> PathData Double
forall a. Point a -> Point a -> Point a -> PathData a
CubicP (Point Double -> Point Double
pointToSvgCoords Point Double
a) (Point Double -> Point Double
pointToSvgCoords Point Double
b) (Point Double -> Point Double
pointToSvgCoords Point Double
p)
svgCoords (QuadP Point Double
a Point Double
p) = Point Double -> Point Double -> PathData Double
forall a. Point a -> Point a -> PathData a
QuadP (Point Double -> Point Double
pointToSvgCoords Point Double
a) (Point Double -> Point Double
pointToSvgCoords Point Double
p)
svgCoords (StartP Point Double
p) = Point Double -> PathData Double
forall a. Point a -> PathData a
StartP (Point Double -> Point Double
pointToSvgCoords Point Double
p)
svgCoords (LineP Point Double
p) = Point Double -> PathData Double
forall a. Point a -> PathData a
LineP (Point Double -> Point Double
pointToSvgCoords Point Double
p)
svgCoords (ArcP ArcInfo Double
i Point Double
p) = ArcInfo Double -> Point Double -> PathData Double
forall a. ArcInfo a -> Point a -> PathData a
ArcP ArcInfo Double
i (Point Double -> Point Double
pointToSvgCoords Point Double
p)
toPathAbsolute ::
PathData Double ->
ByteString
toPathAbsolute :: PathData Double -> ByteString
toPathAbsolute (StartP Point Double
p) = ByteString
"M " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
p
toPathAbsolute (LineP Point Double
p) = ByteString
"L " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
p
toPathAbsolute (CubicP Point Double
c1 Point Double
c2 Point Double
p) =
ByteString
"C "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
c1
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
c2
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
p
toPathAbsolute (QuadP Point Double
control Point Double
p) =
ByteString
"Q "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
control
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
p
toPathAbsolute (ArcP (ArcInfo (Point Double
x Double
y) Double
phi' Bool
l Bool
sw) Point Double
x2) =
ByteString
"A "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Double -> ByteString
pv' Double
x
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Double -> ByteString
pv' Double
y
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Double -> ByteString
pv' (-(Double
phi' Double -> Double -> Double
forall a. Multiplicative a => a -> a -> a
* Double
180 Double -> Double -> Double
forall a. Divisive a => a -> a -> a
/ Double
forall a. TrigField a => a
pi))
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString -> ByteString -> Bool -> ByteString
forall a. a -> a -> Bool -> a
bool ByteString
"0" ByteString
"1" Bool
l
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString -> ByteString -> Bool -> ByteString
forall a. a -> a -> Bool -> a
bool ByteString
"0" ByteString
"1" Bool
sw
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" "
ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Point Double -> ByteString
pp' Point Double
x2
pv' :: Double -> ByteString
pv' :: Double -> ByteString
pv' Double
x =
Text -> ByteString
encodeUtf8 (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$
FormatStyle -> Maybe Int -> Double -> Text
formatOrShow (Int -> FormatStyle
FixedStyle Int
4) Maybe Int
forall a. Maybe a
Nothing Double
x
pp' :: Point Double -> ByteString
pp' :: Point Double -> ByteString
pp' (Point Double
x Double
y) =
Text -> ByteString
encodeUtf8 (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$
FormatStyle -> Maybe Int -> Double -> Text
formatOrShow (Int -> FormatStyle
FixedStyle Int
4) Maybe Int
forall a. Maybe a
Nothing Double
x
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
","
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FormatStyle -> Maybe Int -> Double -> Text
formatOrShow (Int -> FormatStyle
FixedStyle Int
4) Maybe Int
forall a. Maybe a
Nothing (Double -> Double -> Bool -> Double
forall a. a -> a -> Bool -> a
bool (-Double
y) Double
y (Double
y Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
forall a. Additive a => a
zero))
data PathCursor = PathCursor
{
PathCursor -> Point Double
curPrevious :: Point Double,
PathCursor -> Point Double
curStart :: Point Double,
PathCursor -> Maybe (Point Double)
curControl :: Maybe (Point Double)
}
deriving (PathCursor -> PathCursor -> Bool
(PathCursor -> PathCursor -> Bool)
-> (PathCursor -> PathCursor -> Bool) -> Eq PathCursor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PathCursor -> PathCursor -> Bool
== :: PathCursor -> PathCursor -> Bool
$c/= :: PathCursor -> PathCursor -> Bool
/= :: PathCursor -> PathCursor -> Bool
Eq, Int -> PathCursor -> ShowS
[PathCursor] -> ShowS
PathCursor -> [Char]
(Int -> PathCursor -> ShowS)
-> (PathCursor -> [Char])
-> ([PathCursor] -> ShowS)
-> Show PathCursor
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PathCursor -> ShowS
showsPrec :: Int -> PathCursor -> ShowS
$cshow :: PathCursor -> [Char]
show :: PathCursor -> [Char]
$cshowList :: [PathCursor] -> ShowS
showList :: [PathCursor] -> ShowS
Show, ReadPrec [PathCursor]
ReadPrec PathCursor
Int -> ReadS PathCursor
ReadS [PathCursor]
(Int -> ReadS PathCursor)
-> ReadS [PathCursor]
-> ReadPrec PathCursor
-> ReadPrec [PathCursor]
-> Read PathCursor
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PathCursor
readsPrec :: Int -> ReadS PathCursor
$creadList :: ReadS [PathCursor]
readList :: ReadS [PathCursor]
$creadPrec :: ReadPrec PathCursor
readPrec :: ReadPrec PathCursor
$creadListPrec :: ReadPrec [PathCursor]
readListPrec :: ReadPrec [PathCursor]
Read, (forall x. PathCursor -> Rep PathCursor x)
-> (forall x. Rep PathCursor x -> PathCursor) -> Generic PathCursor
forall x. Rep PathCursor x -> PathCursor
forall x. PathCursor -> Rep PathCursor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PathCursor -> Rep PathCursor x
from :: forall x. PathCursor -> Rep PathCursor x
$cto :: forall x. Rep PathCursor x -> PathCursor
to :: forall x. Rep PathCursor x -> PathCursor
Generic, Typeable PathCursor
Typeable PathCursor =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCursor -> c PathCursor)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCursor)
-> (PathCursor -> Constr)
-> (PathCursor -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCursor))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PathCursor))
-> ((forall b. Data b => b -> b) -> PathCursor -> PathCursor)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r)
-> (forall u. (forall d. Data d => d -> u) -> PathCursor -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> PathCursor -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor)
-> Data PathCursor
PathCursor -> Constr
PathCursor -> DataType
(forall b. Data b => b -> b) -> PathCursor -> PathCursor
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PathCursor -> u
forall u. (forall d. Data d => d -> u) -> PathCursor -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCursor
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCursor -> c PathCursor
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCursor)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PathCursor)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCursor -> c PathCursor
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PathCursor -> c PathCursor
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCursor
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PathCursor
$ctoConstr :: PathCursor -> Constr
toConstr :: PathCursor -> Constr
$cdataTypeOf :: PathCursor -> DataType
dataTypeOf :: PathCursor -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCursor)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PathCursor)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PathCursor)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PathCursor)
$cgmapT :: (forall b. Data b => b -> b) -> PathCursor -> PathCursor
gmapT :: (forall b. Data b => b -> b) -> PathCursor -> PathCursor
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PathCursor -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PathCursor -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PathCursor -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PathCursor -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PathCursor -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PathCursor -> m PathCursor
Data)
stateCur0 :: PathCursor
stateCur0 :: PathCursor
stateCur0 = Point Double -> Point Double -> Maybe (Point Double) -> PathCursor
PathCursor Point Double
forall a. Additive a => a
zero Point Double
forall a. Additive a => a
zero Maybe (Point Double)
forall a. Maybe a
Nothing
svgToPathData :: ByteString -> [PathData Double]
svgToPathData :: ByteString -> [PathData Double]
svgToPathData = ([PathCommand] -> [PathData Double])
-> Maybe [PathCommand] -> [PathData Double]
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap [PathCommand] -> [PathData Double]
toPathDatas (Maybe [PathCommand] -> [PathData Double])
-> (ByteString -> Maybe [PathCommand])
-> ByteString
-> [PathData Double]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> Maybe [PathCommand]
parsePath
pathDataToSvg :: [PathData Double] -> ByteString
pathDataToSvg :: [PathData Double] -> ByteString
pathDataToSvg [PathData Double]
xs = [ByteString] -> ByteString
C8.unwords ([ByteString] -> ByteString) -> [ByteString] -> ByteString
forall a b. (a -> b) -> a -> b
$ (PathData Double -> ByteString)
-> [PathData Double] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PathData Double -> ByteString
toPathAbsolute [PathData Double]
xs
toPathDatas :: [PathCommand] -> [PathData Double]
toPathDatas :: [PathCommand] -> [PathData Double]
toPathDatas [PathCommand]
xs = (PathData Double -> PathData Double)
-> [PathData Double] -> [PathData Double]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PathData Double -> PathData Double
svgCoords ([PathData Double] -> [PathData Double])
-> [PathData Double] -> [PathData Double]
forall a b. (a -> b) -> a -> b
$ [[PathData Double]] -> [PathData Double]
forall a. Monoid a => [a] -> a
mconcat ([[PathData Double]] -> [PathData Double])
-> [[PathData Double]] -> [PathData Double]
forall a b. (a -> b) -> a -> b
$ (State PathCursor [[PathData Double]]
-> PathCursor -> [[PathData Double]])
-> PathCursor
-> State PathCursor [[PathData Double]]
-> [[PathData Double]]
forall a b c. (a -> b -> c) -> b -> a -> c
flip State PathCursor [[PathData Double]]
-> PathCursor -> [[PathData Double]]
forall s a. State s a -> s -> a
evalState PathCursor
stateCur0 (State PathCursor [[PathData Double]] -> [[PathData Double]])
-> State PathCursor [[PathData Double]] -> [[PathData Double]]
forall a b. (a -> b) -> a -> b
$ (PathCommand -> StateT PathCursor Identity [PathData Double])
-> [PathCommand] -> State PathCursor [[PathData Double]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM PathCommand -> StateT PathCursor Identity [PathData Double]
toPathData [PathCommand]
xs
relToAbs :: (Additive a) => a -> [a] -> [a]
relToAbs :: forall a. Additive a => a -> [a] -> [a]
relToAbs a
p [a]
xs = [a] -> [a]
forall a (f :: * -> *). (Additive a, Traversable f) => f a -> f a
accsum (a
p a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs)
moveTo :: [Point Double] -> State PathCursor [PathData Double]
moveTo :: [Point Double] -> StateT PathCursor Identity [PathData Double]
moveTo [] = [PathData Double] -> StateT PathCursor Identity [PathData Double]
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
moveTo (Point Double
x : [Point Double]
xs) = do
PathCursor -> StateT PathCursor Identity ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (Point Double -> Point Double -> Maybe (Point Double) -> PathCursor
PathCursor (Point Double -> Maybe (Point Double) -> Point Double
forall a. a -> Maybe a -> a
fromMaybe Point Double
x (Maybe (Point Double) -> Point Double)
-> Maybe (Point Double) -> Point Double
forall a b. (a -> b) -> a -> b
$ [Point Double] -> Maybe (Point Double)
forall a. [a] -> Maybe a
listToMaybe ([Point Double] -> Maybe (Point Double))
-> [Point Double] -> Maybe (Point Double)
forall a b. (a -> b) -> a -> b
$ [Point Double] -> [Point Double]
forall a. [a] -> [a]
reverse [Point Double]
xs) Point Double
x Maybe (Point Double)
forall a. Maybe a
Nothing)
[PathData Double] -> StateT PathCursor Identity [PathData Double]
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Point Double -> PathData Double
forall a. Point a -> PathData a
StartP Point Double
x PathData Double -> [PathData Double] -> [PathData Double]
forall a. a -> [a] -> [a]
: (Point Double -> PathData Double
forall a. Point a -> PathData a
LineP (Point Double -> PathData Double)
-> [Point Double] -> [PathData Double]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Point Double]
xs))
lineTo :: [Point Double] -> State PathCursor [PathData Double]
lineTo :: [Point Double] -> StateT PathCursor Identity [PathData Double]
lineTo [Point Double]
xs = do
(PathCursor -> PathCursor) -> StateT PathCursor Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
-> Point Double -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
#curPrevious ([Point Double] -> Point Double
forall a. HasCallStack => [a] -> a
last [Point Double]
xs) (PathCursor -> PathCursor)
-> (PathCursor -> PathCursor) -> PathCursor -> PathCursor
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
-> Maybe (Point Double) -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
#curControl Maybe (Point Double)
forall a. Maybe a
Nothing)
[PathData Double] -> StateT PathCursor Identity [PathData Double]
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([PathData Double] -> StateT PathCursor Identity [PathData Double])
-> [PathData Double]
-> StateT PathCursor Identity [PathData Double]
forall a b. (a -> b) -> a -> b
$ Point Double -> PathData Double
forall a. Point a -> PathData a
LineP (Point Double -> PathData Double)
-> [Point Double] -> [PathData Double]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Point Double]
xs
horTo :: [Double] -> State PathCursor [PathData Double]
horTo :: [Double] -> StateT PathCursor Identity [PathData Double]
horTo [Double]
xs = do
(PathCursor (Point _ y) _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
lineTo (fmap (`Point` y) xs)
verTo :: [Double] -> State PathCursor [PathData Double]
verTo :: [Double] -> StateT PathCursor Identity [PathData Double]
verTo [Double]
ys = do
(PathCursor (Point x _) _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
lineTo (fmap (Point x) ys)
curveTo :: [(Point Double, Point Double, Point Double)] -> State PathCursor [PathData Double]
curveTo :: [(Point Double, Point Double, Point Double)]
-> StateT PathCursor Identity [PathData Double]
curveTo [(Point Double, Point Double, Point Double)]
xs = do
(PathCursor -> PathCursor) -> StateT PathCursor Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify
( Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
-> Point Double -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
#curPrevious ((\(Point Double
_, Point Double
_, Point Double
p) -> Point Double
p) ([(Point Double, Point Double, Point Double)]
-> (Point Double, Point Double, Point Double)
forall a. HasCallStack => [a] -> a
last [(Point Double, Point Double, Point Double)]
xs))
(PathCursor -> PathCursor)
-> (PathCursor -> PathCursor) -> PathCursor -> PathCursor
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
#curControl Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
-> Point Double -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a (Maybe b) -> b -> s -> t
?~ (\(Point Double
_, Point Double
c2, Point Double
_) -> Point Double
c2) ([(Point Double, Point Double, Point Double)]
-> (Point Double, Point Double, Point Double)
forall a. HasCallStack => [a] -> a
last [(Point Double, Point Double, Point Double)]
xs))
)
[PathData Double] -> StateT PathCursor Identity [PathData Double]
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([PathData Double] -> StateT PathCursor Identity [PathData Double])
-> [PathData Double]
-> StateT PathCursor Identity [PathData Double]
forall a b. (a -> b) -> a -> b
$ (\(Point Double
c1, Point Double
c2, Point Double
x2) -> Point Double -> Point Double -> Point Double -> PathData Double
forall a. Point a -> Point a -> Point a -> PathData a
CubicP Point Double
c1 Point Double
c2 Point Double
x2) ((Point Double, Point Double, Point Double) -> PathData Double)
-> [(Point Double, Point Double, Point Double)]
-> [PathData Double]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Point Double, Point Double, Point Double)]
xs
relToAbs3 :: (Additive a) => a -> [(a, a, a)] -> [(a, a, a)]
relToAbs3 :: forall a. Additive a => a -> [(a, a, a)] -> [(a, a, a)]
relToAbs3 a
p [(a, a, a)]
xs = [(a, a, a)]
xs'
where
x1 :: [a]
x1 = (\(a
x, a
_, a
_) -> a
x) ((a, a, a) -> a) -> [(a, a, a)] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, a, a)]
xs
x2 :: [a]
x2 = (\(a
_, a
x, a
_) -> a
x) ((a, a, a) -> a) -> [(a, a, a)] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, a, a)]
xs
x3 :: [a]
x3 = (\(a
_, a
_, a
x) -> a
x) ((a, a, a) -> a) -> [(a, a, a)] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, a, a)]
xs
x1' :: [a]
x1' = (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
p a -> a -> a
forall a. Additive a => a -> a -> a
+) ([a] -> [a]
forall a (f :: * -> *). (Additive a, Traversable f) => f a -> f a
accsum [a]
x1)
x2' :: [a]
x2' = (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
p a -> a -> a
forall a. Additive a => a -> a -> a
+) ([a] -> [a]
forall a (f :: * -> *). (Additive a, Traversable f) => f a -> f a
accsum [a]
x2)
x3' :: [a]
x3' = (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
p a -> a -> a
forall a. Additive a => a -> a -> a
+) ([a] -> [a]
forall a (f :: * -> *). (Additive a, Traversable f) => f a -> f a
accsum [a]
x3)
xs' :: [(a, a, a)]
xs' = [a] -> [a] -> [a] -> [(a, a, a)]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 [a]
x1' [a]
x2' [a]
x3'
reflControlPoint :: State PathCursor (Point Double)
reflControlPoint :: State PathCursor (Point Double)
reflControlPoint = do
(PathCursor p _ c) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
case c of
Maybe (Point Double)
Nothing -> Point Double -> State PathCursor (Point Double)
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Point Double
p
Just Point Double
c' -> Point Double -> State PathCursor (Point Double)
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Point Double
p Point Double -> Point Double -> Point Double
forall a. Subtractive a => a -> a -> a
- (Point Double
c' Point Double -> Point Double -> Point Double
forall a. Subtractive a => a -> a -> a
- Point Double
p))
smoothCurveToStep :: (Point Double, Point Double) -> State PathCursor (PathData Double)
smoothCurveToStep :: (Point Double, Point Double) -> State PathCursor (PathData Double)
smoothCurveToStep (Point Double
c2, Point Double
x2) = do
c1 <- State PathCursor (Point Double)
reflControlPoint
modify ((#curControl ?~ c2) . set #curPrevious x2)
pure (CubicP c1 c2 x2)
smoothCurveTo :: [(Point Double, Point Double)] -> State PathCursor [PathData Double]
smoothCurveTo :: [(Point Double, Point Double)]
-> StateT PathCursor Identity [PathData Double]
smoothCurveTo = ((Point Double, Point Double)
-> State PathCursor (PathData Double))
-> [(Point Double, Point Double)]
-> StateT PathCursor Identity [PathData Double]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Point Double, Point Double) -> State PathCursor (PathData Double)
smoothCurveToStep
relToAbs2 :: (Additive a) => a -> [(a, a)] -> [(a, a)]
relToAbs2 :: forall a. Additive a => a -> [(a, a)] -> [(a, a)]
relToAbs2 a
p [(a, a)]
xs = [(a, a)]
xs'
where
x1 :: [a]
x1 = (a, a) -> a
forall a b. (a, b) -> a
fst ((a, a) -> a) -> [(a, a)] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, a)]
xs
x2 :: [a]
x2 = (a, a) -> a
forall a b. (a, b) -> b
snd ((a, a) -> a) -> [(a, a)] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, a)]
xs
x1' :: [a]
x1' = (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
p a -> a -> a
forall a. Additive a => a -> a -> a
+) ([a] -> [a]
forall a (f :: * -> *). (Additive a, Traversable f) => f a -> f a
accsum [a]
x1)
x2' :: [a]
x2' = (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
p a -> a -> a
forall a. Additive a => a -> a -> a
+) ([a] -> [a]
forall a (f :: * -> *). (Additive a, Traversable f) => f a -> f a
accsum [a]
x2)
xs' :: [(a, a)]
xs' = [a] -> [a] -> [(a, a)]
forall a b. [a] -> [b] -> [(a, b)]
zip [a]
x1' [a]
x2'
quad :: [(Point Double, Point Double)] -> State PathCursor [PathData Double]
quad :: [(Point Double, Point Double)]
-> StateT PathCursor Identity [PathData Double]
quad [(Point Double, Point Double)]
xs = do
(PathCursor -> PathCursor) -> StateT PathCursor Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify
( Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
-> Point Double -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
#curPrevious ((Point Double, Point Double) -> Point Double
forall a b. (a, b) -> b
snd ([(Point Double, Point Double)] -> (Point Double, Point Double)
forall a. HasCallStack => [a] -> a
last [(Point Double, Point Double)]
xs))
(PathCursor -> PathCursor)
-> (PathCursor -> PathCursor) -> PathCursor -> PathCursor
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
-> Maybe (Point Double) -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
#curControl (Point Double -> Maybe (Point Double)
forall a. a -> Maybe a
Just ((Point Double, Point Double) -> Point Double
forall a b. (a, b) -> a
fst ([(Point Double, Point Double)] -> (Point Double, Point Double)
forall a. HasCallStack => [a] -> a
last [(Point Double, Point Double)]
xs)))
)
[PathData Double] -> StateT PathCursor Identity [PathData Double]
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([PathData Double] -> StateT PathCursor Identity [PathData Double])
-> [PathData Double]
-> StateT PathCursor Identity [PathData Double]
forall a b. (a -> b) -> a -> b
$ (Point Double -> Point Double -> PathData Double)
-> (Point Double, Point Double) -> PathData Double
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Point Double -> Point Double -> PathData Double
forall a. Point a -> Point a -> PathData a
QuadP ((Point Double, Point Double) -> PathData Double)
-> [(Point Double, Point Double)] -> [PathData Double]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Point Double, Point Double)]
xs
smoothQuadStep :: Point Double -> State PathCursor (PathData Double)
smoothQuadStep :: Point Double -> State PathCursor (PathData Double)
smoothQuadStep Point Double
x2 = do
c1 <- State PathCursor (Point Double)
reflControlPoint
modify (set #curControl (Just c1) . set #curPrevious x2)
pure (QuadP c1 x2)
smoothQuad :: [Point Double] -> State PathCursor [PathData Double]
smoothQuad :: [Point Double] -> StateT PathCursor Identity [PathData Double]
smoothQuad = (Point Double -> State PathCursor (PathData Double))
-> [Point Double] -> StateT PathCursor Identity [PathData Double]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Point Double -> State PathCursor (PathData Double)
smoothQuadStep
arcTo :: [(Double, Double, Double, Bool, Bool, Point Double)] -> State PathCursor [PathData Double]
arcTo :: [(Double, Double, Double, Bool, Bool, Point Double)]
-> StateT PathCursor Identity [PathData Double]
arcTo [(Double, Double, Double, Bool, Bool, Point Double)]
xs = do
(PathCursor -> PathCursor) -> StateT PathCursor Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
-> Point Double -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic
A_Lens NoIx PathCursor PathCursor (Point Double) (Point Double)
#curPrevious ((\(Double
_, Double
_, Double
_, Bool
_, Bool
_, Point Double
p) -> Point Double
p) ([(Double, Double, Double, Bool, Bool, Point Double)]
-> (Double, Double, Double, Bool, Bool, Point Double)
forall a. HasCallStack => [a] -> a
last [(Double, Double, Double, Bool, Bool, Point Double)]
xs)) (PathCursor -> PathCursor)
-> (PathCursor -> PathCursor) -> PathCursor -> PathCursor
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
-> Maybe (Point Double) -> PathCursor -> PathCursor
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic
A_Lens
NoIx
PathCursor
PathCursor
(Maybe (Point Double))
(Maybe (Point Double))
#curControl Maybe (Point Double)
forall a. Maybe a
Nothing)
[PathData Double] -> StateT PathCursor Identity [PathData Double]
forall a. a -> StateT PathCursor Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([PathData Double] -> StateT PathCursor Identity [PathData Double])
-> [PathData Double]
-> StateT PathCursor Identity [PathData Double]
forall a b. (a -> b) -> a -> b
$ (Double, Double, Double, Bool, Bool, Point Double)
-> PathData Double
forall a. (a, a, a, Bool, Bool, Point a) -> PathData a
fromPathEllipticalArc ((Double, Double, Double, Bool, Bool, Point Double)
-> PathData Double)
-> [(Double, Double, Double, Bool, Bool, Point Double)]
-> [PathData Double]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Double, Double, Double, Bool, Bool, Point Double)]
xs
fromPathEllipticalArc :: (a, a, a, Bool, Bool, Point a) -> PathData a
fromPathEllipticalArc :: forall a. (a, a, a, Bool, Bool, Point a) -> PathData a
fromPathEllipticalArc (a
x, a
y, a
r, Bool
l, Bool
s, Point a
p) = ArcInfo a -> Point a -> PathData a
forall a. ArcInfo a -> Point a -> PathData a
ArcP (Point a -> a -> Bool -> Bool -> ArcInfo a
forall a. Point a -> a -> Bool -> Bool -> ArcInfo a
ArcInfo (a -> a -> Point a
forall a. a -> a -> Point a
Point a
x a
y) a
r Bool
l Bool
s) Point a
p
relToAbsArc :: (Additive a) => Point a -> [(a, a, a, Bool, Bool, Point a)] -> [(a, a, a, Bool, Bool, Point a)]
relToAbsArc :: forall a.
Additive a =>
Point a
-> [(a, a, a, Bool, Bool, Point a)]
-> [(a, a, a, Bool, Bool, Point a)]
relToAbsArc Point a
p [(a, a, a, Bool, Bool, Point a)]
xs = [(a, a, a, Bool, Bool, Point a)]
xs'
where
ps :: [Point a]
ps = (\(a
_, a
_, a
_, Bool
_, Bool
_, Point a
pt) -> Point a
pt) ((a, a, a, Bool, Bool, Point a) -> Point a)
-> [(a, a, a, Bool, Bool, Point a)] -> [Point a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, a, a, Bool, Bool, Point a)]
xs
ps' :: [Point a]
ps' = (Point a -> Point a) -> [Point a] -> [Point a]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Point a
p Point a -> Point a -> Point a
forall a. Additive a => a -> a -> a
+) ([Point a] -> [Point a]
forall a (f :: * -> *). (Additive a, Traversable f) => f a -> f a
accsum [Point a]
ps)
xs' :: [(a, a, a, Bool, Bool, Point a)]
xs' = ((a, a, a, Bool, Bool, Point a)
-> Point a -> (a, a, a, Bool, Bool, Point a))
-> [(a, a, a, Bool, Bool, Point a)]
-> [Point a]
-> [(a, a, a, Bool, Bool, Point a)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\(a
x0, a
x1, a
x2, Bool
x3, Bool
x4, Point a
_) Point a
pt -> (a
x0, a
x1, a
x2, Bool
x3, Bool
x4, Point a
pt)) [(a, a, a, Bool, Bool, Point a)]
xs [Point a]
ps'
toPathData :: PathCommand -> State PathCursor [PathData Double]
toPathData :: PathCommand -> StateT PathCursor Identity [PathData Double]
toPathData (MoveTo Origin
OriginAbsolute [Point Double]
xs) = [Point Double] -> StateT PathCursor Identity [PathData Double]
moveTo [Point Double]
xs
toPathData (MoveTo Origin
OriginRelative [Point Double]
xs) = do
(PathCursor p _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
moveTo (relToAbs p xs)
toPathData PathCommand
EndPath = do
(PathCursor _ s _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
pure [LineP s]
toPathData (LineTo Origin
OriginAbsolute [Point Double]
xs) = [Point Double] -> StateT PathCursor Identity [PathData Double]
lineTo [Point Double]
xs
toPathData (LineTo Origin
OriginRelative [Point Double]
xs) = do
(PathCursor p _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
lineTo (relToAbs p xs)
toPathData (HorizontalTo Origin
OriginAbsolute [Double]
xs) = [Double] -> StateT PathCursor Identity [PathData Double]
horTo [Double]
xs
toPathData (HorizontalTo Origin
OriginRelative [Double]
xs) = do
(PathCursor (Point x _) _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
horTo (relToAbs x xs)
toPathData (VerticalTo Origin
OriginAbsolute [Double]
xs) = [Double] -> StateT PathCursor Identity [PathData Double]
verTo [Double]
xs
toPathData (VerticalTo Origin
OriginRelative [Double]
ys) = do
(PathCursor (Point _ y) _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
verTo (relToAbs y ys)
toPathData (CurveTo Origin
OriginAbsolute [(Point Double, Point Double, Point Double)]
xs) = [(Point Double, Point Double, Point Double)]
-> StateT PathCursor Identity [PathData Double]
curveTo [(Point Double, Point Double, Point Double)]
xs
toPathData (CurveTo Origin
OriginRelative [(Point Double, Point Double, Point Double)]
xs) = do
(PathCursor p _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
curveTo (relToAbs3 p xs)
toPathData (SmoothCurveTo Origin
OriginAbsolute [(Point Double, Point Double)]
xs) = [(Point Double, Point Double)]
-> StateT PathCursor Identity [PathData Double]
smoothCurveTo [(Point Double, Point Double)]
xs
toPathData (SmoothCurveTo Origin
OriginRelative [(Point Double, Point Double)]
xs) = do
(PathCursor p _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
smoothCurveTo (relToAbs2 p xs)
toPathData (QuadraticBezier Origin
OriginAbsolute [(Point Double, Point Double)]
xs) = [(Point Double, Point Double)]
-> StateT PathCursor Identity [PathData Double]
quad [(Point Double, Point Double)]
xs
toPathData (QuadraticBezier Origin
OriginRelative [(Point Double, Point Double)]
xs) = do
(PathCursor p _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
quad (relToAbs2 p xs)
toPathData (SmoothQuadraticBezierCurveTo Origin
OriginAbsolute [Point Double]
xs) = [Point Double] -> StateT PathCursor Identity [PathData Double]
smoothQuad [Point Double]
xs
toPathData (SmoothQuadraticBezierCurveTo Origin
OriginRelative [Point Double]
xs) = do
(PathCursor p _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
smoothQuad (relToAbs p xs)
toPathData (EllipticalArc Origin
OriginAbsolute [(Double, Double, Double, Bool, Bool, Point Double)]
xs) = [(Double, Double, Double, Bool, Bool, Point Double)]
-> StateT PathCursor Identity [PathData Double]
arcTo [(Double, Double, Double, Bool, Bool, Point Double)]
xs
toPathData (EllipticalArc Origin
OriginRelative [(Double, Double, Double, Bool, Bool, Point Double)]
xs) = do
(PathCursor p _ _) <- StateT PathCursor Identity PathCursor
forall s (m :: * -> *). MonadState s m => m s
get
arcTo (relToAbsArc p xs)