diff --git a/CG2.cabal b/CG2.cabal index 1630043..dd6a951 100644 --- a/CG2.cabal +++ b/CG2.cabal @@ -54,7 +54,7 @@ executable CG2 main-is: Main.hs -- Modules included in this executable, other than Main. - other-modules: Defaults Diagram Gtk Meshparser Parser Util + other-modules: Defaults Diagram Gtk Parser.Meshparser Parser.Core OS.FileExt LinearAlgebra.Vector -- LANGUAGE extensions used by modules in this package. -- other-extensions: diff --git a/Diagram.hs b/Diagram.hs index 10e157e..2c1e614 100644 --- a/Diagram.hs +++ b/Diagram.hs @@ -12,8 +12,8 @@ module Diagram (t, import Defaults import Diagrams.Prelude import Diagrams.Backend.Cairo -import Meshparser -import Util +import LinearAlgebra.Vector +import Parser.Meshparser -- |Represents a Cairo Diagram. This allows us to create multiple diff --git a/Gtk.hs b/Gtk.hs index 36dfe2f..d8bb18f 100644 --- a/Gtk.hs +++ b/Gtk.hs @@ -12,8 +12,7 @@ import Graphics.UI.Gtk import Graphics.UI.Gtk.Glade import System.Directory import Text.Read -import Util - +import OS.FileExt -- |Monolithic object passed to various GUI functions in order -- to keep the API stable and not alter the parameters too much. diff --git a/LinearAlgebra/Vector.hs b/LinearAlgebra/Vector.hs new file mode 100644 index 0000000..80808ac --- /dev/null +++ b/LinearAlgebra/Vector.hs @@ -0,0 +1,27 @@ +{-# OPTIONS_HADDOCK ignore-exports #-} + +module LinearAlgebra.Vector where + +import Data.Vector.Class + + +type Angle = Double + + +-- |Checks whether the Coordinates are in a given dimension. +inRange :: (Double, Double) -- ^ X dimension + -> (Double, Double) -- ^ Y dimension + -> (Double, Double) -- ^ Coordinates + -> Bool -- ^ result +inRange (xlD, xuD) (ylD, yuD) (x,y) + = x <= xuD && x >= xlD && y <= yuD && y >= ylD + + +-- |Get the angle between two vectors in degrees. +getAngle :: (Vector v) => v -> v -> Angle +getAngle a b = (*) 180.0 . + flip (/) pi . + acos . + flip (/) (vmag a * vmag b) . + vdot a $ + b diff --git a/Util.hs b/OS/FileExt.hs similarity index 68% rename from Util.hs rename to OS/FileExt.hs index d027c2b..571f63f 100644 --- a/Util.hs +++ b/OS/FileExt.hs @@ -1,17 +1,6 @@ {-# OPTIONS_HADDOCK ignore-exports #-} -module Util where - - --- |Checks whether the Coordinates are in a given dimension. -inRange :: (Double, Double) -- ^ X dimension - -> (Double, Double) -- ^ Y dimension - -> (Double, Double) -- ^ Coordinates - -> Bool -- ^ result -inRange (xlD, xuD) (ylD, yuD) (x,y) - | x <= xuD && x >= xlD && - y <= yuD && y >= ylD = True - | otherwise = False +module OS.FileExt where -- |Compare the extension of a file with the given String. diff --git a/Parser.hs b/Parser/Core.hs similarity index 98% rename from Parser.hs rename to Parser/Core.hs index cf44139..3fd78a6 100644 --- a/Parser.hs +++ b/Parser/Core.hs @@ -1,6 +1,6 @@ {-# OPTIONS_HADDOCK ignore-exports #-} -module Parser (Parser, +module Parser.Core (Parser, runParser, satisfy, char, diff --git a/Meshparser.hs b/Parser/Meshparser.hs similarity index 92% rename from Meshparser.hs rename to Parser/Meshparser.hs index 3098109..3428541 100644 --- a/Meshparser.hs +++ b/Parser/Meshparser.hs @@ -1,9 +1,9 @@ {-# OPTIONS_HADDOCK ignore-exports #-} -module Meshparser (VTable, meshToArr) where +module Parser.Meshparser (VTable, meshToArr) where import Control.Applicative -import Parser +import Parser.Core -- |The VTable is represented by a 'Double' tuple, 2-dimensional. type VTable = [(Double, Double)]