diff --git a/README.md b/README.md index 782042d..b77015d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # One True Path -A general-purpose library for working with paths. +A general-purpose library for working with curves and paths. -The primary aim at the moment is SVG paths, but the types and functions in this package can also be +The primary aim is SVG paths, but the types and functions in this package can also be used for animations or other graphics backends (webgl, canvas). +Additionally, this package is meant to serve as an interchange format between packages. + ## Core Concepts * **Path:** A list of subpaths @@ -105,8 +107,7 @@ Path.parse pathAsString The `Segment` module breaks down a line into four basic segment types, and exposes some mathematical functions (and the constructors, if you want to define your own fancy stuff). -The `LowLevel` module has that name for a reason. Unless you are making your own primitives, there is probably a better way. -If there isn't but you think there should be, please open an issue. +The `LowLevel.Command` module contains individual instructions. These should only be used for building other primitives! Making and combining curves should happen on the SubPath level. ## What about styling diff --git a/src/LowLevel/Command.elm b/src/LowLevel/Command.elm index 5e2fce9..10beeae 100644 --- a/src/LowLevel/Command.elm +++ b/src/LowLevel/Command.elm @@ -29,9 +29,11 @@ module LowLevel.Command , merge ) -{-| Low-level access to absolute svg drawing commands. +{-| Low-level access to drawing instructions. -As the name implies, this is a low-level module that you probably shouldn't deal with. +This is a low-level module that you probably shouldn't deal with. +These instructions are meant to build up primitives (like in the `Curve` module); building of +curves should happen at the `SubPath` level. ## Threading State @@ -121,10 +123,12 @@ type DrawTo { start = ( 0, 42 ) , end = ( 42, 0 ) , radii = ( 1, 1 ) - , xAxisRotate = 0 + , xAxisRotate = 90 , arcFlag = largestArc , direction = clockwise } + +The xAxisRotate parameter is in degrees (note that in the `Segment` module, it is in radians). -} type alias EllipticalArcArgument = { radii : ( Float, Float ) @@ -351,15 +355,15 @@ fromLowLevelDrawTo drawto ({ start, cursor } as state) = LowLevel.SmoothCurveTo mode coordinates -> -- (If there is no previous command or if the previous command was not an C, c, S or s, -- assume the first control point is coincident with the current point.) - coordinates - |> coordinatesToAbsolute mode (Vec2.map (Vec2.add cursor)) - |> Maybe.map (makeControlPointExplicitVec2 state << Tuple.second) - |> Maybe.map - (\( finalState, finalPoints ) -> - ( CurveTo finalPoints - , finalState - ) + let + updateState ( finalState, finalPoints ) = + ( CurveTo finalPoints + , finalState ) + in + coordinates + |> coordinatesToAbsolute mode (Vec2.map (Vec2.add cursor)) + |> Maybe.map (updateState << makeControlPointExplicitVec2 state << Tuple.second) LowLevel.QuadraticBezierCurveTo mode coordinates -> let @@ -373,15 +377,15 @@ fromLowLevelDrawTo drawto ({ start, cursor } as state) = |> Maybe.map updateState LowLevel.SmoothQuadraticBezierCurveTo mode coordinates -> - coordinates - |> coordinatesToAbsolute mode (Vec2.add cursor) - |> Maybe.map (makeControlPointExplicitVec1 state << Tuple.second) - |> Maybe.map - (\( finalState, finalPoints ) -> - ( QuadraticBezierCurveTo finalPoints - , finalState - ) + let + updateState ( finalState, finalPoints ) = + ( QuadraticBezierCurveTo finalPoints + , finalState ) + in + coordinates + |> coordinatesToAbsolute mode (Vec2.add cursor) + |> Maybe.map (updateState << makeControlPointExplicitVec1 state << Tuple.second) LowLevel.EllipticalArc mode arguments -> let