<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Thank you very much Jedai ... this looks much more concise and does not contain the repetitions that I had. I'd need to go over it more to understand it better.<br>I'll ping you if I have any questions about this.<br><br>Regards,<br>Kashyap<br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Chaddaï Fouché <chaddai.fouche@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> CK Kashyap <ck_kashyap@yahoo.com><br><b><span style="font-weight: bold;">Cc:</span></b> haskell-cafe@haskell.org<br><b><span style="font-weight: bold;">Sent:</span></b> Tuesday, July 28, 2009
7:10:38 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Haskell-cafe] Need feedback on my Haskell code<br></font><br>On Tue, Jul 28, 2009 at 3:04 PM, CK Kashyap<<a ymailto="mailto:ck_kashyap@yahoo.com" href="mailto:ck_kashyap@yahoo.com">ck_kashyap@yahoo.com</a>> wrote:<br>> Hi Everyone,<br>> I managed to write up the line drawing function using the following links -<br>> <a href="http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html" target="_blank">http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html</a><br>> <a href="http://rosettacode.org/wiki/Bresenham%27s_line_algorithm#Haskell" target="_blank">http://rosettacode.org/wiki/Bresenham%27s_line_algorithm#Haskell</a><br>><br><br>I tried to simplify your function a little bit :<br><br>line :: Point -> Point -> [Point]<br>line pa@(xa,ya) pb@(xb,yb) = map maySwitch . unfoldr go $ (x1,y1,0)<br> where<br> steep = abs (yb
- ya) > abs (xb - xa)<br> maySwitch = if steep then (\(x,y) -> (y,x)) else id<br> [(x1,y1),(x2,y2)] = sort [maySwitch pa, maySwitch pb]<br> deltax = x2 - x1<br> deltay = abs (y2 - y1)<br> ystep = if y1 < y2 then 1 else -1<br> go (xTemp, yTemp, error)<br> | xTemp > x2 = Nothing<br> | otherwise = Just ((xTemp, yTemp), (xTemp + 1, newY, newError))<br> where<br> tempError = error + deltay<br> (newY, newError) = if (2*tempError) >= deltax<br> then (yTemp+ystep,tempError-deltax)<br> else (yTemp,tempError)<br><br>I think it
will be a bit better, tell me what you think ?<br><br>-- <br>Jedaï<br></div></div></div><br>
</body></html>