Skip to content

Namespace package #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The code for drawing the letter H looks like this:

```elm
import SubPath exposing SubPath
import Curve
import Svg.Curve as Curve
import Svg exposing (Svg)
import Svg.Attributes exposing
(width, height, viewBox, fill, stroke)
Expand Down Expand Up @@ -71,8 +71,8 @@ A `SubPath` can be `ArcLengthParameterized`, to sample the curve, animate along
Finally, a piece of svg path syntax can be parsed into a list of `SubPath`s

```elm
import Path
import SubPath
import SvgPath
import Svg.SubPath as SubPath

pathAsString =
"""
Expand All @@ -87,7 +87,7 @@ pathAsString =
"""

path =
Path.parse pathAsString
SvgPath.parse pathAsString
|> Result.toMaybe
|> Maybe.andThen List.head
```
Expand All @@ -103,7 +103,7 @@ access the `OpenSolid` values and use that package to modify your geometry.

## Others

The `Path` module is a convenience for when you have a list of `SubPath`s and want to render them into one `path` element.
The `SvgPath` module is a convenience for when you have a list of `SubPath`s and want to render them into one `path` element.

The `LowLevel.Command` module is meant for package authors. It allows more control over the generated svg instructions, but
is pretty cumbersome to work with. Try to stay away from it.
Expand Down
4 changes: 2 additions & 2 deletions examples/CurveImages.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ and then used in the documentations
-}

import Color
import Curve
import Svg.Curve as Curve
import Html
import Html.Attributes
import Path
import SvgPath
import SubPath exposing (SubPath, with)
import Svg exposing (Attribute, Svg)
import Svg.Attributes exposing (..)
Expand Down
8 changes: 4 additions & 4 deletions examples/EvenlySpaced.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import Html.Attributes as Attributes
import Html.Events as Events
import Svg.Attributes exposing (width, height, fill, stroke)
import Html.Attributes
import CurveImages exposing (gridRect, svgGrid, nodes)
import Curve
import SubPath
import Path
import Svg.Curve as CurveImages exposing (gridRect, svgGrid, nodes)
import Svg.Curve as Curve
import Svg.SubPath as SubPath
import SvgPath
import Geometry.Ellipse exposing (signedAngle)
import AnimationFrame
import Time exposing (Time)
Expand Down
4 changes: 2 additions & 2 deletions examples/InterpolationDocumentation.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Html exposing (..)
import Html.Attributes
import LowLevel.Command exposing (moveTo, lineTo, closePath)
import SubPath exposing (subpath)
import Path
import Curve exposing (..)
import SvgPath
import Svg.Curve as Curve exposing (..)
import Color
import Color.Interpolate as Color exposing (Space(LAB))
import Color.Convert as Color
Expand Down
2 changes: 1 addition & 1 deletion examples/LabelPositions.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Main exposing (main)

import Curve
import Svg.Curve as Curve
import Html.Attributes exposing (attribute)
import LowLevel.Command exposing (..)
import OpenSolid.Direction2d as Direction2d
Expand Down
58 changes: 29 additions & 29 deletions src/Curve.elm → src/Svg/Curve.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Curve exposing
module Svg.Curve exposing
( linear, linearClosed
, cubicBezier, smoothCubicBezier, quadraticBezier, smoothQuadraticBezier
, step, stepBefore, stepAfter
Expand Down Expand Up @@ -98,7 +98,7 @@ import List.Extra as List
import LowLevel.Command as Command exposing (..)
import Path.LowLevel as LowLevel exposing (Mode(..))
import Quantity exposing (Unitless)
import SubPath exposing (SubPath(..), close, connect, empty)
import Svg.SubPath exposing (SubPath(..), close, connect, empty)
import Vector2d exposing (Vector2d)


Expand Down Expand Up @@ -149,7 +149,7 @@ linear points =
empty

x :: xs ->
SubPath.with (moveTo x) [ lineTo xs ]
Svg.SubPath.with (moveTo x) [ lineTo xs ]


{-| Draw a straigt line between the data points, connecting the ends.
Expand All @@ -164,7 +164,7 @@ linearClosed points =
empty

x :: xs ->
SubPath.with (moveTo x) [ lineTo xs, closePath ]
Svg.SubPath.with (moveTo x) [ lineTo xs, closePath ]


{-| Shorthand to draw a sequence of cubic bezier segments
Expand All @@ -176,7 +176,7 @@ cubicBezier start points =
empty

x :: xs ->
SubPath.with (moveTo start) [ cubicCurveTo points ]
Svg.SubPath.with (moveTo start) [ cubicCurveTo points ]


{-| Shorthand to draw a sequence of smooth cubic bezier segments
Expand All @@ -193,7 +193,7 @@ smoothCubicBezier start first points =
lowLevelSubPath =
{ moveto = LowLevel.MoveTo Absolute start, drawtos = lowLevelDrawTos }
in
SubPath.fromLowLevel lowLevelSubPath
Svg.SubPath.fromLowLevel lowLevelSubPath


{-| Shorthand to draw a sequence of quadratic bezier segments
Expand All @@ -205,7 +205,7 @@ quadraticBezier start points =
empty

x :: xs ->
SubPath.with (moveTo start) [ quadraticCurveTo points ]
Svg.SubPath.with (moveTo start) [ quadraticCurveTo points ]


{-| Shorthand to draw a sequence of smooth quadratic bezier segments
Expand All @@ -222,7 +222,7 @@ smoothQuadraticBezier start first points =
lowLevelSubPath =
{ moveto = LowLevel.MoveTo Absolute start, drawtos = lowLevelDrawTos }
in
SubPath.fromLowLevel lowLevelSubPath
Svg.SubPath.fromLowLevel lowLevelSubPath


{-| Convert `(angle, radius)` pairs to `(x, y)` coordinates, relative to the given vector.
Expand Down Expand Up @@ -309,10 +309,10 @@ basis points =
in
case points of
p0 :: p1 :: _ :: _ ->
SubPath.with (moveTo p0) (lineTo [ toFirst (Vector2d.fromTuple Quantity.float p0) (Vector2d.fromTuple Quantity.float p1) ] :: commonCase [] points)
Svg.SubPath.with (moveTo p0) (lineTo [ toFirst (Vector2d.fromTuple Quantity.float p0) (Vector2d.fromTuple Quantity.float p1) ] :: commonCase [] points)

[ p0, p1 ] ->
SubPath.with (moveTo p0) [ lineTo [ p1 ] ]
Svg.SubPath.with (moveTo p0) [ lineTo [ p1 ] ]

_ ->
empty
Expand Down Expand Up @@ -358,7 +358,7 @@ basisClosed points =
|> Vector2d.scaleBy (1 / 6)
|> Vector2d.toTuple Quantity.toFloat
in
SubPath.with (moveTo start)
Svg.SubPath.with (moveTo start)
[ cubicCurveTo (commonCase [] closing (p3 :: p4 :: rest)) ]

[ p0_, p1_ ] ->
Expand All @@ -377,7 +377,7 @@ basisClosed points =
Vector2d.scaleBy (1 / 3) (Vector2d.plus p1 (Vector2d.scaleBy 2 p0))
|> Vector2d.toTuple Quantity.toFloat
in
SubPath.with (moveTo start) [ lineTo [ end ], closePath ]
Svg.SubPath.with (moveTo start) [ lineTo [ end ], closePath ]

_ ->
empty
Expand Down Expand Up @@ -407,7 +407,7 @@ basisOpen points =
|> Vector2d.scaleBy (1 / 6)
|> Vector2d.toTuple Quantity.toFloat
in
SubPath.with (moveTo start) [ cubicCurveTo (helper [] (p1 :: p :: pp :: rest)) ]
Svg.SubPath.with (moveTo start) [ cubicCurveTo (helper [] (p1 :: p :: pp :: rest)) ]

_ ->
empty
Expand Down Expand Up @@ -505,10 +505,10 @@ cardinal tension points =
in
case points of
[ p0, p1 ] ->
SubPath.with (moveTo p0) [ lineTo [ p1 ] ]
Svg.SubPath.with (moveTo p0) [ lineTo [ p1 ] ]

p0 :: p1 :: p2 :: rest ->
SubPath.with (moveTo p0) [ cubicCurveTo (cardinalPoint k p1 p0 p1 p2 :: helper [] points) ]
Svg.SubPath.with (moveTo p0) [ cubicCurveTo (cardinalPoint k p1 p0 p1 p2 :: helper [] points) ]

_ ->
empty
Expand All @@ -527,7 +527,7 @@ cardinalOpen tension points =
List.map4 (cardinalPoint k) (p0 :: p1 :: p2 :: p3 :: rest) (p1 :: p2 :: p3 :: rest) (p2 :: p3 :: rest) (p3 :: rest)
|> cubicCurveTo
|> List.singleton
|> SubPath.with (moveTo p1)
|> Svg.SubPath.with (moveTo p1)

_ ->
empty
Expand Down Expand Up @@ -560,7 +560,7 @@ cardinalClosed tension points =
empty

[ p0, p1 ] ->
SubPath.with (moveTo p1) [ lineTo [ p0 ], closePath ]
Svg.SubPath.with (moveTo p1) [ lineTo [ p0 ], closePath ]

p3 :: p4 :: p5 :: rest ->
let
Expand All @@ -570,7 +570,7 @@ cardinalClosed tension points =
, cardinalPoint k p2 p3 p4 p5
]
in
SubPath.with (moveTo p4) [ cubicCurveTo (helper [] end points) ]
Svg.SubPath.with (moveTo p4) [ cubicCurveTo (helper [] end points) ]


catmullRomDistance : Float -> Vector2d Unitless coordinates -> Vector2d Unitless coordinates -> ( Float, Float )
Expand All @@ -595,14 +595,14 @@ catmullRom alpha points =
else
case points of
[ p1, p2 ] ->
SubPath.with (moveTo p1) [ lineTo [ p2 ] ]
Svg.SubPath.with (moveTo p1) [ lineTo [ p2 ] ]

p0 :: p1 :: p2 :: rest ->
let
ending q0 q1 q2 =
[ catmullRomPoint alpha q0 q1 q2 q2 ]
in
SubPath.with (moveTo p0) [ cubicCurveTo (catmullRomHelper alpha ending (p0 :: points) []) ]
Svg.SubPath.with (moveTo p0) [ cubicCurveTo (catmullRomHelper alpha ending (p0 :: points) []) ]

_ ->
empty
Expand Down Expand Up @@ -636,14 +636,14 @@ catmullRomOpen alpha points =
else
case points of
[ p0, p1, p2 ] ->
SubPath.with (moveTo p1) [ closePath ]
Svg.SubPath.with (moveTo p1) [ closePath ]

p0 :: p1 :: p2 :: p :: rest ->
let
ending _ _ _ =
[]
in
SubPath.with (moveTo p1) [ cubicCurveTo (catmullRomHelper alpha ending points []) ]
Svg.SubPath.with (moveTo p1) [ cubicCurveTo (catmullRomHelper alpha ending points []) ]

_ ->
empty
Expand All @@ -665,7 +665,7 @@ catmullRomClosed alpha points =
empty

[ p1, p2 ] ->
SubPath.with (moveTo p2) [ lineTo [ p1 ], closePath ]
Svg.SubPath.with (moveTo p2) [ lineTo [ p1 ], closePath ]

p3 :: p4 :: p5 :: rest ->
let
Expand All @@ -675,7 +675,7 @@ catmullRomClosed alpha points =
, catmullRomPoint alpha p2 p3 p4 p5
]
in
SubPath.with (moveTo p4) [ cubicCurveTo (catmullRomHelper alpha ending points []) ]
Svg.SubPath.with (moveTo p4) [ cubicCurveTo (catmullRomHelper alpha ending points []) ]


catmullRomPoint : Float -> ( Float, Float ) -> ( Float, Float ) -> ( Float, Float ) -> ( Float, Float ) -> Triplet ( Float, Float )
Expand Down Expand Up @@ -838,10 +838,10 @@ monotoneX points =
otherInstructions =
monotoneXHelper [] t1 (p1 :: p :: rest)
in
SubPath.with (moveTo p0) [ cubicCurveTo (initialInstruction :: otherInstructions) ]
Svg.SubPath.with (moveTo p0) [ cubicCurveTo (initialInstruction :: otherInstructions) ]

[ p0, p1 ] ->
SubPath.with (moveTo p0) [ lineTo [ p1 ] ]
Svg.SubPath.with (moveTo p0) [ lineTo [ p1 ] ]

_ ->
empty
Expand Down Expand Up @@ -883,7 +883,7 @@ monotoneY points =
points
|> List.map (\( x, y ) -> ( y, x ))
|> monotoneX
|> SubPath.mapCoordinate (\( x, y ) -> ( y, x ))
|> Svg.SubPath.mapCoordinate (\( x, y ) -> ( y, x ))


toH : Float -> Float -> Float
Expand Down Expand Up @@ -911,7 +911,7 @@ natural points =
empty

[ p1, p2 ] ->
SubPath.with (moveTo p1) [ lineTo [ p2 ] ]
Svg.SubPath.with (moveTo p1) [ lineTo [ p2 ] ]

p :: _ :: _ ->
let
Expand All @@ -921,7 +921,7 @@ natural points =
|> naturalControlPoints
|> List.map (mapTriplet (Vector2d.toTuple Quantity.toFloat))
in
SubPath.with (moveTo p) [ cubicCurveTo cubicTriplets ]
Svg.SubPath.with (moveTo p) [ cubicCurveTo cubicTriplets ]


{-| ![step](https://rawgit.com/folkertdev/one-true-path-experiment/master/docs/step.svg)
Expand Down
Loading