Difference between revisions of "Talk:Graham Scan Implementation"

From HaskellWiki
Jump to navigation Jump to search
m
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
   
 
The buttonLeft function can be simplified using foldr like so:
 
The buttonLeft function can be simplified using foldr like so:
  +
<haskell>
 
 
buttonLeft :: [Pt] -> Pt
 
buttonLeft :: [Pt] -> Pt
 
buttonLeft = folrd minY (Pt (1/0, 1/0)) where
 
buttonLeft = folrd minY (Pt (1/0, 1/0)) where
minY (Pt (ax, ay)) (Pt (bx, by))
+
minY (Pt (ax, ay)) (Pt (bx, by))
| ay > by = Pt (bx, by)
+
| ay > by = Pt (bx, by)
| ay < by = Pt (ax, ay)
+
| ay < by = Pt (ax, ay)
| ax < bx = Pt (ax, ay)
+
| ax < bx = Pt (ax, ay)
| otherwise = Pt (bx, by)
+
| otherwise = Pt (bx, by)
  +
</haskell>

Latest revision as of 06:29, 1 September 2014

Use foldr to simplify buttonLeft

The buttonLeft function can be simplified using foldr like so:

buttonLeft :: [Pt] -> Pt
buttonLeft = folrd minY (Pt (1/0, 1/0)) where
  minY (Pt (ax, ay)) (Pt (bx, by))
    | ay > by = Pt (bx, by)
    | ay < by = Pt (ax, ay)
    | ax < bx = Pt (ax, ay)
    | otherwise = Pt (bx, by)