diff options
author | Joe Crayne <joe@jerkface.net> | 2019-06-03 09:15:21 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-06-03 09:15:21 -0400 |
commit | d9584d5877f428928dd562a169f81763d8f63902 (patch) | |
tree | 0aa9091422facce4537a0d12b597b516e55d0cba | |
parent | 7bc96f3d0f6192d2e7d8119892dd3148792ff88c (diff) |
Fix bug in subdivideCurve.
-rw-r--r-- | Bezier.hs | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -19,6 +19,7 @@ data Polygonization = Polygonization | |||
19 | , curveStartIndex :: Int | 19 | , curveStartIndex :: Int |
20 | , curveSegmentCount :: Int | 20 | , curveSegmentCount :: Int |
21 | } | 21 | } |
22 | deriving Show | ||
22 | 23 | ||
23 | type AllocatedRange = Polygonization | 24 | type AllocatedRange = Polygonization |
24 | 25 | ||
@@ -37,12 +38,13 @@ xz :: Vector Float -> (Float,Float) | |||
37 | xz v = (v!0, v!2) | 38 | xz v = (v!0, v!2) |
38 | 39 | ||
39 | subdivideCurve :: Monad m => Float -> Curve -> AllocatedRange -> StorePoint m -> m Polygonization | 40 | subdivideCurve :: Monad m => Float -> Curve -> AllocatedRange -> StorePoint m -> m Polygonization |
41 | subdivideCurve δ curve range store | curveSegmentCount range < 2 = return range { curveSegmentCount = 0 } | ||
40 | subdivideCurve δ curve range store = do | 42 | subdivideCurve δ curve range store = do |
41 | let ts = sort $ take (curveSegmentCount range - 2) $ sampleCurve δ curve | 43 | let ts = sort $ take (curveSegmentCount range - 2) $ sampleCurve δ curve |
42 | n <- (\f -> foldr f (return 0) (zip [0..] (0 : ts))) $ \(i,t) _ -> do | 44 | n <- (\f -> foldr f return (zip [0..] (0 : ts)) 0) $ \(i,t) ret _ -> do |
43 | let v = bezierEval curve t | 45 | let v = bezierEval curve t |
44 | store (curveBufferID range) (curveStartIndex range + i) v | 46 | store (curveBufferID range) (curveStartIndex range + i) v |
45 | return i | 47 | ret i |
46 | let v = bezierEval curve 1.0 | 48 | let v = bezierEval curve 1.0 |
47 | store (curveBufferID range) (curveStartIndex range + n + 1) v | 49 | store (curveBufferID range) (curveStartIndex range + n + 1) v |
48 | return range { curveSegmentCount = n + 2 } | 50 | return range { curveSegmentCount = n + 2 } |