Replace bresenham with digitalLine
This commit is contained in:
@@ -297,6 +297,7 @@ divideLine x a b = take 5000 $ map (\i -> a +.+ (i / (fromIntegral numPoints) *.
|
||||
|
||||
|
||||
-- pulled the following from the haskell wiki
|
||||
-- it seems to produce an infinite loop sometimes
|
||||
bresenham :: (Int,Int) -> (Int,Int) -> [(Int,Int)]
|
||||
{-# INLINE bresenham #-}
|
||||
bresenham pa@(xa,ya) pb@(xb,yb) = map maySwitch . unfoldr go $ (x1,y1,0)
|
||||
@@ -316,6 +317,18 @@ bresenham pa@(xa,ya) pb@(xb,yb) = map maySwitch . unfoldr go $ (x1,y1,0)
|
||||
then (yTemp+ystep,tempError-deltax)
|
||||
else (yTemp,tempError)
|
||||
|
||||
digitalLine :: (Int,Int) -> (Int,Int) -> [(Int,Int)]
|
||||
digitalLine (x1,y1) (x2,y2)
|
||||
| abs (x1-x2) > abs (y1-y2) = [ (x,( (y1-y2) * x + x1*y2 - x2*y1) `rdiv` (x1-x2) )
|
||||
| x <- intervalList x1 x2 ]
|
||||
| otherwise = [ ( ((x1-x2) * y + y1*x2 - y2*x1) `rdiv` (y1-y2) , y)
|
||||
| y <- intervalList y1 y2 ]
|
||||
where rdiv a b = round $ fromIntegral a / fromIntegral b
|
||||
|
||||
intervalList :: Int -> Int -> [Int]
|
||||
intervalList x y
|
||||
| y >= x = [x .. y]
|
||||
| otherwise = reverse [y..x]
|
||||
|
||||
divideCircle :: Float -> Point2 -> Float -> [Point2]
|
||||
divideCircle x cen rad = map (cen +.+) $ nPointsOnCirc n rad
|
||||
|
||||
Reference in New Issue
Block a user