elm-geometry icon indicating copy to clipboard operation
elm-geometry copied to clipboard

Switch from Maybe to Result where it makes sense

Open ianmackenzie opened this issue 5 years ago • 0 comments

Currently there are several constructor/factory functions such as Arc2d.withRadius that return Maybe values if construction fails (invalid arguments given, no solution found, etc.). Ideally many of these should be switched to return Result values instead with a custom error type that indicates the failure reason; for example, @folkertdev's proposal for EllipticalArc2d.fromEndpoints:

type ArcError
    = IdenticalStartAndEndpoint -- omit this segment
    | RadiusIsZero -- (i.e. endpoint == center) draw straight line segment 
    | NoSolution -- maybe point to docs on how svg deals with this

One possible modification: change the NoSolution case to actually include the 'best approximation' elliptical arc with X and Y radius scaled to make arc construction possible. This way attempting to construct an ellipse with invalid/impossible radii is an Err, but the user can explicitly choose to fall back to the scaled ellipse if they want (which is what browser SVG engines do, since that's what's mandated by the SVG spec).

ianmackenzie avatar Sep 16 '18 19:09 ianmackenzie