juicy-gcode 0.1.0.5 → 0.1.0.5.1
raw patch · 3 files changed
+17/−10 lines, 3 filesdep ~lensdep ~svg-tree
Dependency ranges changed: lens, svg-tree
Files
- ChangeLog.md +2/−2
- juicy-gcode.cabal +3/−3
- src/Render.hs +12/−5
ChangeLog.md view
@@ -1,8 +1,8 @@ # Revision history for juicy-gcode -## 0.1.0.5 -- 2018-03-16 +## 0.1.0.5 -- 2018-08-08 -* Update README +* Simplify special bezier curves to lines ## 0.1.0.4 -- 2017-12-30
juicy-gcode.cabal view
@@ -1,5 +1,5 @@ name: juicy-gcode -version: 0.1.0.5 +version: 0.1.0.5.1 license: BSD3 license-file: LICENSE author: dlacko @@ -23,13 +23,13 @@ build-depends: base >=4.8 && <5, - lens >=4.15.4 && <4.16, + lens >=4.15.4 && <4.18, linear >=1.20 && <1.21, optparse-applicative >=0.13 && <0.14, configurator >=0.3 && <0.4, text >=1.2.2 && <1.3, matrix >=0.3.5 && <0.4, - svg-tree >=0.5 && <0.6 + svg-tree >=0.6 && <0.7 GHC-Options: -Wall default-language: Haskell2010
src/Render.hs view
@@ -43,10 +43,17 @@ -- convert a quadratic bezier to a cubic one bezierQ2C :: Point -> Point -> Point -> DrawOp bezierQ2C (qp0x, qp0y) (qp1x, qp1y) (qp2x, qp2y) - = DBezierTo (qp0x + 2.0 / 3.0 * (qp1x - qp0x), qp0y + 2.0 / 3.0 * (qp1y - qp0y)) - (qp2x + 2.0 / 3.0 * (qp1x - qp2x), qp2y + 2.0 / 3.0 * (qp1y - qp2y)) - (qp2x, qp2y) + = createBezier (qp0x + 2.0 / 3.0 * (qp1x - qp0x), qp0y + 2.0 / 3.0 * (qp1y - qp0y)) + (qp2x + 2.0 / 3.0 * (qp1x - qp2x), qp2y + 2.0 / 3.0 * (qp1y - qp2y)) + (qp2x, qp2y) +-- create a cubic bezier dta constructor from two control and one endpoints +-- tries to simplify as well. it happens that the points actually describe a line, converting it to arcs would fail later on +createBezier :: Point -> Point -> Point -> DrawOp +createBezier c1 c2 e + | (c1 == c2) && (c2 == e) = DMoveTo e + | otherwise = DBezierTo c1 c2 e + toAbsolute :: (Double, Double) -> SVG.Origin -> (Double, Double) -> (Double, Double) toAbsolute _ SVG.OriginAbsolute p = p toAbsolute (cx,cy) SVG.OriginRelative (dx,dy) = (cx+dx, cy+dy) @@ -117,7 +124,7 @@ cont dys' = SVG.VerticalTo SVG.OriginRelative dys' : ds renderPathCommands firstp currentp _ (SVG.CurveTo origin ((c1,c2,p):ps):ds) - = DBezierTo ac1 ac2 ap : renderPathCommands firstp ap (Just ac2) (cont ps) + = createBezier ac1 ac2 ap : renderPathCommands firstp ap (Just ac2) (cont ps) where ap = toAbsolute currentp origin (fromRPoint p) ac1 = toAbsolute currentp origin (fromRPoint c1) @@ -127,7 +134,7 @@ cont ps' = SVG.CurveTo origin ps' : ds renderPathCommands firstp currentp mbControlp (SVG.SmoothCurveTo origin ((c2,p):ps):ds) - = DBezierTo ac1 ac2 ap : renderPathCommands firstp ap (Just ac2) (cont ps) + = createBezier ac1 ac2 ap : renderPathCommands firstp ap (Just ac2) (cont ps) where ap = toAbsolute currentp origin (fromRPoint p) ac1 = maybe ac2 (mirrorControlPoint currentp) mbControlp