DIAGRAM: small refactor
Enhanced the Diag type and used it for poly functions as well.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
module Graphics.Diagram.Gtk where
|
||||
|
||||
import Algebra.VectorTypes
|
||||
import Diagrams.Backend.Cairo
|
||||
import Diagrams.Prelude
|
||||
import Graphics.Diagram.Plotter
|
||||
@@ -11,63 +10,47 @@ import Parser.Meshparser
|
||||
|
||||
|
||||
-- |Create the Diagram from the points.
|
||||
diag :: DiagProp -> [[PT]] -> Diagram Cairo R2
|
||||
diag p pts = case alg p of
|
||||
0 ->
|
||||
mkDiag
|
||||
(mconcat [maybeDiag (ct p) coordPointsText,
|
||||
coordPoints, xAxis, yAxis,
|
||||
maybeDiag (gd p) grid, whiteRectB])
|
||||
p (head pts)
|
||||
1 ->
|
||||
mkDiag
|
||||
(mconcat
|
||||
[maybeDiag (ct p) convexHPText,
|
||||
convexHP, convexHLs,
|
||||
coordPoints, xAxis, yAxis,
|
||||
maybeDiag (gd p) grid, whiteRectB])
|
||||
p (head pts)
|
||||
2 -> polys
|
||||
3 ->
|
||||
polyIntText
|
||||
`atop`
|
||||
polyIntersection (head pts) (pts !! 1) p
|
||||
`atop`
|
||||
polys
|
||||
_ -> mempty
|
||||
where
|
||||
polys =
|
||||
diag :: DiagProp -> Object -> Diagram Cairo R2
|
||||
diag p obj@(Object _)
|
||||
| alg p == 0 =
|
||||
mkDiag
|
||||
(mconcat [maybeDiag (ct p) coordPointsText, coordPoints, polyLines])
|
||||
p (head pts)
|
||||
`atop`
|
||||
(mconcat [maybeDiag (ct p) coordPointsText,
|
||||
coordPoints, plotterBG])
|
||||
p obj
|
||||
| alg p == 1 =
|
||||
mkDiag
|
||||
(mconcat
|
||||
[maybeDiag (ct p) coordPointsText,
|
||||
polyLines, coordPoints, xAxis, yAxis,
|
||||
maybeDiag (gd p) grid, whiteRectB])
|
||||
p (pts !! 1)
|
||||
polyIntText = if ct p
|
||||
then polyIntersectionText (head pts) (pts !! 1) p
|
||||
else mempty
|
||||
|
||||
[maybeDiag (ct p) convexHPText,
|
||||
convexHP, convexHLs,
|
||||
coordPoints, plotterBG])
|
||||
p obj
|
||||
| otherwise = mempty
|
||||
diag p objs@(Objects _)
|
||||
| alg p == 2 =
|
||||
mkDiag (mconcat [polyLines, maybeDiag (ct p) coordPointsText, coordPoints,
|
||||
plotterBG])
|
||||
p objs
|
||||
| alg p == 3 =
|
||||
mkDiag (mconcat [maybeDiag (ct p) polyIntersectionText,
|
||||
polyIntersection, maybeDiag (ct p) coordPointsText,
|
||||
coordPoints, polyLines,
|
||||
plotterBG])
|
||||
p objs
|
||||
| otherwise = mempty
|
||||
|
||||
|
||||
-- |Create the Diagram from a String which is supposed to be the contents
|
||||
-- of an obj file.
|
||||
diagS :: DiagProp -> MeshString -> Diagram Cairo R2
|
||||
diagS p mesh = case alg p of
|
||||
2 ->
|
||||
diag p.
|
||||
facesToArr $
|
||||
mesh
|
||||
3 ->
|
||||
diag p.
|
||||
facesToArr $
|
||||
mesh
|
||||
_ ->
|
||||
(diag p .
|
||||
(:[]) .
|
||||
meshToArr $
|
||||
mesh) #
|
||||
bg white
|
||||
diagS p mesh
|
||||
| alg p == 2 || alg p == 3 =
|
||||
diag p.
|
||||
Objects .
|
||||
facesToArr $
|
||||
mesh
|
||||
| otherwise =
|
||||
(diag p .
|
||||
Object .
|
||||
meshToArr $
|
||||
mesh) #
|
||||
bg white
|
||||
|
||||
Reference in New Issue
Block a user