cubicbezier 0.6.0.1 → 0.6.0.2
raw patch · 4 files changed
+25/−33 lines, 4 files
Files
- Geom2D/CubicBezier/Intersection.hs +14/−14
- Geom2D/CubicBezier/Overlap.lhs +10/−12
- Geom2D/CubicBezier/Stroke.hs +0/−6
- cubicbezier.cabal +1/−1
Geom2D/CubicBezier/Intersection.hs view
@@ -99,7 +99,8 @@ | otherwise -> Left $ let t = closest p q0 vEps newT = tmin * (1-t) + tmax * t- umid = umin + (umax-umin)/2+ umid | umax >= 0.5 = umax+ | otherwise = umin in if | vectorDistance (evalBezier p t) (evalBezier q 0.5) > vEps -> [] | revCurves -> [(umid, newT)]@@ -119,33 +120,32 @@ new_tmin = tmax * chop_tmin + tmin * (1 - chop_tmin) new_tmax = tmax * chop_tmax + tmin * (1 - chop_tmax) if | -- within tolerance - max (umax - umin) (new_tmax - new_tmin) < pEps ->- let newu | umax == 1 = 1- | umin == 0 = 0- | otherwise = umin + (umax-umin)/2- newt | tmax == 1 = 1- | tmin == 0 = 0- | otherwise = new_tmin + (new_tmax-new_tmin)/2+ (max (umax - umin) (new_tmax - new_tmin))*4 < pEps ->+ let newu | umax >= 0.5 = umax+ | otherwise = umin+ newt | new_tmax >= 0.5 = new_tmax+ | otherwise = new_tmin in if revCurves then Right [(newu, newt)] else Right [(newt, newu)] -- not enough reduction, so split the curve in case we have -- multiple intersections | prevClip > 0.8 && newClip > 0.8 ->- if | new_tmax - new_tmin > umax - umin ->+ if | (new_tmax-new_tmin) * (new_tmax-new_tmin) * vectorMagSquare (p3 ^-^ p0) >+ (umax-umin) * (umax-umin) * vectorMagSquare (q3 ^-^ q0) -> -- split the longest segment let (pl, pr) = splitBezier newP 0.5 half_t = new_tmin + (new_tmax - new_tmin) / 2 in Right $ bezierClip q pl umin umax new_tmin half_t- newClip pEps vEps (not revCurves) +++ 0 pEps vEps (not revCurves) ++ bezierClip q pr umin umax half_t new_tmax- newClip pEps vEps (not revCurves)+ 0 pEps vEps (not revCurves) | otherwise -> let (ql, qr) = splitBezier q 0.5- half_t = umin + (umax - umin) / 2- in Right $ bezierClip ql newP umin half_t+ half_u = umin + (umax - umin) / 2+ in Right $ bezierClip ql newP umin half_u new_tmin new_tmax newClip pEps vEps (not revCurves) ++- bezierClip qr newP half_t umax new_tmin new_tmax+ bezierClip qr newP half_u umax new_tmin new_tmax newClip pEps vEps (not revCurves) -- iterate with the curves swapped. | otherwise ->
Geom2D/CubicBezier/Overlap.lhs view
@@ -872,9 +872,7 @@ > where > errMsg = checkSplitCurve b1 b2 n > n = nextIntersection b1 b2 tol $-> bezierIntersection b1 b2 pTol-> pTol = min (bezierParamTolerance b1 tol)-> (bezierParamTolerance b2 tol)+> bezierIntersection b1 b2 tol > b1 = view bezier c1 > b2 = view bezier c2 >@@ -882,10 +880,10 @@ > any (/=p) ps > where x0 = pointX $ cubicC0 c2 > x3 = pointX $ cubicC3 c2-> t0 | pointX (cubicC0 c1) >= pointX (cubicC0 c2) = 0-> | otherwise = findX c1 (pointX (cubicC0 c2)) 1e-7-> t1 | pointX (cubicC3 c1) <= pointX (cubicC3 c2) = 1-> | otherwise = findX c1 (pointX (cubicC3 c2)) 1e-7+> t0 | pointX (cubicC0 c1) >= x0 = 0+> | otherwise = findX c1 x0 1e-7+> t1 | pointX (cubicC3 c1) <= x3 = 1+> | otherwise = findX c1 x3 1e-7 > comp t = let (Point bx by) = evalBezier c1 (t0 + (t1-t0)*t/10) > in compare (pointY (evalBezier c2 (findX c2 bx 1e-7))) by > (p:ps) = map comp [1..9]@@ -898,7 +896,7 @@ > > checkSplitCurve :: CubicBezier Double -> CubicBezier Double -> > (Maybe (CubicBezier Double, CubicBezier Double),-> Maybe (CubicBezier Double, CubicBezier Double)) -> String+> Maybe (CubicBezier Double, CubicBezier Double)) -> String > checkSplitCurve c1 c2 (Nothing, Nothing) = > if checkOverlap c1 c2 > then "Curves overlap: " ++ showCurve c1 ++ " " ++ showCurve c2@@ -977,10 +975,10 @@ > | otherwise = pMid > x1 = evalBezier b1 t1 > x2 = evalBezier b2 t2-> atStart1 = vectorDistance (cubicC0 b1) x1 < 3*tol-> atStart2 = vectorDistance (cubicC0 b2) x2 < 3*tol-> atEnd1 = vectorDistance (cubicC3 b1) x1 < 3*tol-> atEnd2 = vectorDistance (cubicC3 b2) x2 < 3*tol+> atStart1 = vectorDistance (cubicC0 b1) x1 < tol+> atStart2 = vectorDistance (cubicC0 b2) x2 < tol+> atEnd1 = vectorDistance (cubicC3 b1) x1 < tol+> atEnd2 = vectorDistance (cubicC3 b2) x2 < tol > (b1l, b1r) = splitBezier b1 t1 > (b2l, b2r) = splitBezier b2 t2 >
Geom2D/CubicBezier/Stroke.hs view
@@ -14,12 +14,6 @@ data PenSegment a = PenCorner !(Point a) !(Point a) | PenCurve !(Point a) !(CubicBezier a) -{- | PenPath (Point a) (Vector (Point a, PenSegment a)) (Vector (Point a, PenSegment a))--data PenSegment a = PenCorner !(Point a)- | PenCurve !(CubicBezier a)--}- -- | A circular pen with unit radius. penCircle :: (Floating a) => Pen a penCircle = PenEllipse idTrans rotate90L rotate90R
cubicbezier.cabal view
@@ -1,5 +1,5 @@ Name: cubicbezier-Version: 0.6.0.1+Version: 0.6.0.2 Synopsis: Efficient manipulating of 2D cubic bezier curves. Category: Graphics, Geometry, Typography Copyright: Kristof Bastiaensen (2017)