juicy-gcode 0.1.0.2 → 0.1.0.3
raw patch · 4 files changed
+66/−62 lines, 4 files
Files
- ChangeLog.md +4/−0
- CubiCBezier.hs +0/−60
- CubicBezier.hs +60/−0
- juicy-gcode.cabal +2/−2
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for juicy-gcode +## 0.1.0.3 -- 2017-03-19 + +* Fix typo in cabal file + ## 0.1.0.2 -- 2017-03-18 * Fix generating arcs with negative I or J
− CubiCBezier.hs
@@ -1,60 +0,0 @@-module CubicBezier ( CubicBezier (..) - , pointAt - , bezierSplitAt - , isClockwise - , inflectionPoints - , realInflectionPoint - ) where - -import Linear -import Control.Lens -import Data.Complex - -data CubicBezier = CubicBezier { _p1 :: V2 Double - , _c1 :: V2 Double - , _c2 :: V2 Double - , _p2 :: V2 Double - } deriving Show - -pointAt :: CubicBezier -> Double -> V2 Double -pointAt bezier t = ((1 - t) ** 3) *^ _p1 bezier + - ((1 - t) ** 2) * 3 * t *^ _c1 bezier + - (t ** 2) * (1 - t) * 3 *^ _c2 bezier + - (t ** 3) *^ _p2 bezier - -bezierSplitAt :: CubicBezier -> Double -> (CubicBezier, CubicBezier) -bezierSplitAt bezier t = (CubicBezier (_p1 bezier) p0 p01 dp, CubicBezier dp p12 p2 (_p2 bezier)) - where - p0 = _p1 bezier + t *^ (_c1 bezier - _p1 bezier) - p1 = _c1 bezier + t *^ (_c2 bezier - _c1 bezier) - p2 = _c2 bezier + t *^ (_p2 bezier - _c2 bezier) - - p01 = p0 + t *^ (p1 - p0) - p12 = p1 + t *^ (p2 - p1) - - dp = p01 + t *^ (p12 - p01) - -isClockwise :: CubicBezier -> Bool -isClockwise bezier = s < 0 - where - s = (_c1 bezier ^. _x - _p1 bezier ^. _x) * (_c1 bezier ^. _y + _p1 bezier ^. _y) - + (_c2 bezier ^. _x - _c1 bezier ^. _x) * (_c2 bezier ^. _y + _c1 bezier ^. _y) - + (_p2 bezier ^. _x - _c2 bezier ^. _x) * (_p2 bezier ^. _y + _c2 bezier ^. _y) - + (_p1 bezier ^. _x - _p2 bezier ^. _x) * (_p1 bezier ^. _y + _p2 bezier ^. _y) - -inflectionPoints :: CubicBezier -> (Complex Double, Complex Double) -inflectionPoints bezier = (t1, t2) - where - pa = _c1 bezier - _p1 bezier - pb = _c2 bezier - _c1 bezier - pa - pc = _p2 bezier - _c2 bezier - pa - 2 *^ pb - - a = (pb ^. _x * pc ^. _y - pb ^. _y * pc ^. _x) :+ 0 - b = (pa ^. _x * pc ^. _y - pa ^. _y * pc ^. _x) :+ 0 - c = (pa ^. _x * pb ^. _y - pa ^. _y * pb ^. _x) :+ 0 - - t1 = (-b + sqrt (b * b - 4 * a * c)) / (2 * a) - t2 = (-b - sqrt (b * b - 4 * a * c)) / (2 * a) - -realInflectionPoint :: Complex Double -> Bool -realInflectionPoint c = imagPart c == 0 && realPart c > 0 && realPart c < 1
+ CubicBezier.hs view
@@ -0,0 +1,60 @@+module CubicBezier ( CubicBezier (..) + , pointAt + , bezierSplitAt + , isClockwise + , inflectionPoints + , realInflectionPoint + ) where + +import Linear +import Control.Lens +import Data.Complex + +data CubicBezier = CubicBezier { _p1 :: V2 Double + , _c1 :: V2 Double + , _c2 :: V2 Double + , _p2 :: V2 Double + } deriving Show + +pointAt :: CubicBezier -> Double -> V2 Double +pointAt bezier t = ((1 - t) ** 3) *^ _p1 bezier + + ((1 - t) ** 2) * 3 * t *^ _c1 bezier + + (t ** 2) * (1 - t) * 3 *^ _c2 bezier + + (t ** 3) *^ _p2 bezier + +bezierSplitAt :: CubicBezier -> Double -> (CubicBezier, CubicBezier) +bezierSplitAt bezier t = (CubicBezier (_p1 bezier) p0 p01 dp, CubicBezier dp p12 p2 (_p2 bezier)) + where + p0 = _p1 bezier + t *^ (_c1 bezier - _p1 bezier) + p1 = _c1 bezier + t *^ (_c2 bezier - _c1 bezier) + p2 = _c2 bezier + t *^ (_p2 bezier - _c2 bezier) + + p01 = p0 + t *^ (p1 - p0) + p12 = p1 + t *^ (p2 - p1) + + dp = p01 + t *^ (p12 - p01) + +isClockwise :: CubicBezier -> Bool +isClockwise bezier = s < 0 + where + s = (_c1 bezier ^. _x - _p1 bezier ^. _x) * (_c1 bezier ^. _y + _p1 bezier ^. _y) + + (_c2 bezier ^. _x - _c1 bezier ^. _x) * (_c2 bezier ^. _y + _c1 bezier ^. _y) + + (_p2 bezier ^. _x - _c2 bezier ^. _x) * (_p2 bezier ^. _y + _c2 bezier ^. _y) + + (_p1 bezier ^. _x - _p2 bezier ^. _x) * (_p1 bezier ^. _y + _p2 bezier ^. _y) + +inflectionPoints :: CubicBezier -> (Complex Double, Complex Double) +inflectionPoints bezier = (t1, t2) + where + pa = _c1 bezier - _p1 bezier + pb = _c2 bezier - _c1 bezier - pa + pc = _p2 bezier - _c2 bezier - pa - 2 *^ pb + + a = (pb ^. _x * pc ^. _y - pb ^. _y * pc ^. _x) :+ 0 + b = (pa ^. _x * pc ^. _y - pa ^. _y * pc ^. _x) :+ 0 + c = (pa ^. _x * pb ^. _y - pa ^. _y * pb ^. _x) :+ 0 + + t1 = (-b + sqrt (b * b - 4 * a * c)) / (2 * a) + t2 = (-b - sqrt (b * b - 4 * a * c)) / (2 * a) + +realInflectionPoint :: Complex Double -> Bool +realInflectionPoint c = imagPart c == 0 && realPart c > 0 && realPart c < 1
juicy-gcode.cabal view
@@ -1,5 +1,5 @@ name: juicy-gcode -version: 0.1.0.2 +version: 0.1.0.3 license: BSD3 license-file: LICENSE author: dlacko @@ -18,7 +18,7 @@ executable juicy-gcode main-is: Main.hs - other-modules: Approx BiArc CircularArc CubiCBezier GCode Line Render SvgArcSegment Transformation Types + other-modules: Approx BiArc CircularArc CubicBezier GCode Line Render SvgArcSegment Transformation Types build-depends: base >=4.8 && <4.10, svg-tree >=0.5 && <0.6, matrix >=0.3 && <0.4,text >=1.2 && <1.3, configurator >=0.3 && <0.4, optparse-applicative >=0.13 && <0.14, linear >=1.20 && <1.21, lens >=4.14 && <4.15