Skip to content

Instantly share code, notes, and snippets.

@mdgriffith
Last active December 26, 2018 21:52
Show Gist options
  • Save mdgriffith/a5203ce5a1e020ed018544c32e80dcac to your computer and use it in GitHub Desktop.
Save mdgriffith/a5203ce5a1e020ed018544c32e80dcac to your computer and use it in GitHub Desktop.
----------------------
--Curve.Path.elm
--------------------------------
-- This module is meant to be a complete interface
-- constructors would be exposed as functions.
type Path
= Path (List Curve)
| Closed (List Curve)
{-| Render a path into an svg 'd' property: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d -}
pathString : Path -> String
{-| Maybe return a result if there are interesting errors?
Again reads SVG d strings.
-}
read : String -> Maybe Path
{-| Adjusts curves so that that each curve starts where the previous one left off.
I think this is a cool way to handle "relative" coords if it's desired.
Everything else in the lib will be absolute like we talked about.
-}
continuous : List Curve -> Path
append : Path -> Path -> Path
{-| Append path1 to path2, but path2's coordinates are relative to the last point given in path1.
-}
continue : Path -> Path -> Path
{-
Hey Ian!
So, I thought probably the best way to collaborate on this would be to first settle on an API.
Once we have that sketched out, next would be internal types, and finally writing the code!
You definitely understand the constraints of handling this kind of data better than I do,
so, if you're so inclined :), let me know if part of this API doesn't work conceptually or is totally wrong.
This API doesn't address interconverting between curves yet, though adding that would be awesome.
Also, my first stab at this library is here: https://github.com/mdgriffith/elm-curve
Though after we talked I figured it's probably easiest to write it from the ground up.
-}
-- Construction
line : Point -> Point -> Curve
{-|
-}
polyline : List Point -> Curve
bezier : List Point -> Curve
-- I know we want some idea of boundary conditions, starting with 'Clamped' and 'Free'.
-- Do boundary conditions only make sense for catmullRom type stuff
--
-- Maybe curve is an implicitly "free" catmull rom?
curve : List Point -> Curve
-- For clamped, we have to have a vector at each end, right?
-- Feels a little weird that this would essentially be `clamped start end middle`
-- but I'm not sure `clamped start middle end` would be better in usage.
clamped : Vector -> Vector -> List Point -> Curve
{-| Probably need to review this. I know it doesn't match 1:1 with svg as it is.-}
arc :
{ clockwise : Bool
, origin : Point
, startAngle : Angle
, endAngle : Angle
}
-> Curve
-- From Functions
fromEasing : (Float -> Float) -> Curve
-- fn -> NumOfSamples -> starting bound -> ending bound
fromFunction : (Float -> Float) -> Int -> Float -> Float -> Curve
-- Reading Out
pointAt : Curve -> Float -> Point
tangentAt : Curve -> Float -> Angle
{-| I suppose this isn't really a vector because it doesn't have a scalar value? -}
vectorAt : Curve -> Float -> (Point, Angle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment