summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-06-03 09:15:21 -0400
committerJoe Crayne <joe@jerkface.net>2019-06-03 09:15:21 -0400
commitd9584d5877f428928dd562a169f81763d8f63902 (patch)
tree0aa9091422facce4537a0d12b597b516e55d0cba
parent7bc96f3d0f6192d2e7d8119892dd3148792ff88c (diff)
Fix bug in subdivideCurve.
-rw-r--r--Bezier.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/Bezier.hs b/Bezier.hs
index ed464d8..941ad5b 100644
--- a/Bezier.hs
+++ b/Bezier.hs
@@ -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
23type AllocatedRange = Polygonization 24type AllocatedRange = Polygonization
24 25
@@ -37,12 +38,13 @@ xz :: Vector Float -> (Float,Float)
37xz v = (v!0, v!2) 38xz v = (v!0, v!2)
38 39
39subdivideCurve :: Monad m => Float -> Curve -> AllocatedRange -> StorePoint m -> m Polygonization 40subdivideCurve :: Monad m => Float -> Curve -> AllocatedRange -> StorePoint m -> m Polygonization
41subdivideCurve δ curve range store | curveSegmentCount range < 2 = return range { curveSegmentCount = 0 }
40subdivideCurve δ curve range store = do 42subdivideCurve δ 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 }