From fd931db7e07d36627185209343bfec0f8cb4b2ec Mon Sep 17 00:00:00 2001 From: hasufell Date: Sat, 25 Oct 2014 20:39:34 +0200 Subject: [PATCH] Improve readability --- Algorithms/PolygonIntersection/Core.hs | 15 ++++------ Graphics/Diagram/Gtk.hs | 40 +++++++------------------- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/Algorithms/PolygonIntersection/Core.hs b/Algorithms/PolygonIntersection/Core.hs index a54728a..af74594 100644 --- a/Algorithms/PolygonIntersection/Core.hs +++ b/Algorithms/PolygonIntersection/Core.hs @@ -53,7 +53,7 @@ sortLexPoly ps = maybe [] (`shiftM` ps) (elemIndex (yMax ps) ps) -- while saving the origin of that point. This is done in O(n). sortLexPolys :: ([PT], [PT]) -> [PolyPT] sortLexPolys (pA'@(_:_), pB'@(_:_)) = - queueToList . go (Q.fromList . sortLexPoly $ pA') $ + queueToList $ go (Q.fromList . sortLexPoly $ pA') (Q.fromList . sortLexPoly $ pB') where -- Start recursive algorithm, each polygon is represented by a Queue. @@ -130,10 +130,7 @@ intersectionPoints xs' = -- Get the scan line or in other words the -- Segment pairs we are going to check for intersection. scanLine :: [PolyPT] -> ([Segment], [Segment]) - scanLine sp@(_:_) = - (,) - (getSegment isPolyA) - (getSegment isPolyB) + scanLine sp@(_:_) = (,) (getSegment isPolyA) (getSegment isPolyB) where getSegment f = fromMaybe [] ((\x -> [(id' x, suc x), (id' x, pre x)]) @@ -144,10 +141,10 @@ intersectionPoints xs' = -- both polygons we currently examine. This is done in O(1) -- since we have max 4 segments. segIntersections :: ([Segment], [Segment]) -> [PT] - segIntersections (a@(_:_), b@(_:_)) - = catMaybes - . fmap (\[x, y] -> intersectSeg' x y) - $ combinations a b + segIntersections (a@(_:_), b@(_:_)) = + catMaybes + . fmap (\[x, y] -> intersectSeg' x y) + $ combinations a b segIntersections _ = [] -- Gets all unique(!) combinations of two arrays. Both arrays diff --git a/Graphics/Diagram/Gtk.hs b/Graphics/Diagram/Gtk.hs index 1ffaa76..8074dc9 100644 --- a/Graphics/Diagram/Gtk.hs +++ b/Graphics/Diagram/Gtk.hs @@ -13,29 +13,20 @@ import Parser.Meshparser diag :: DiagProp -> Object -> Diagram Cairo R2 diag p obj@(Object _) | alg p == 0 = - mkDiag - (mconcat [coordPointsText, - coordPoints, plotterBG]) - p obj + mkDiag (mconcat [coordPointsText, coordPoints, plotterBG]) + p obj | alg p == 1 = - mkDiag - (mconcat - [convexHPText, - convexHP, convexHLs, - coordPoints, plotterBG]) - p obj + mkDiag (mconcat [convexHPText, convexHP, convexHLs, coordPoints, plotterBG]) + p obj | otherwise = mempty diag p objs@(Objects _) | alg p == 2 = - mkDiag (mconcat [polyLines, coordPointsText, coordPoints, - plotterBG]) - p objs + mkDiag (mconcat [polyLines, coordPointsText, coordPoints, plotterBG]) + p objs | alg p == 3 = - mkDiag (mconcat [polyIntersectionText, - polyIntersection, coordPointsText, - coordPoints, polyLines, - plotterBG]) - p objs + mkDiag (mconcat [polyIntersectionText, polyIntersection, coordPointsText, + coordPoints, polyLines, plotterBG]) + p objs | otherwise = mempty @@ -43,14 +34,5 @@ diag p objs@(Objects _) -- of an obj file. diagS :: DiagProp -> MeshString -> Diagram Cairo R2 diagS p mesh - | alg p == 2 || alg p == 3 = - diag p. - Objects . - facesToArr $ - mesh - | otherwise = - (diag p . - Object . - meshToArr $ - mesh) # - bg white + | alg p == 2 || alg p == 3 = diag p. Objects . facesToArr $ mesh + | otherwise = (diag p . Object . meshToArr $ mesh) # bg white