packages feed

twentefp-graphs 0.1.0.1 → 0.1.0.2

raw patch · 2 files changed

+13/−4 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ FPPrac.Graphs: instance Eq GraphOutput
+ FPPrac.Graphs: instance Eq Thickness
+ FPPrac.Graphs: instance Show GraphOutput
+ FPPrac.Graphs: instance Show Thickness

Files

src/FPPrac/Graphs.hs view
@@ -21,6 +21,7 @@ import EventLoop        
 import EventLoop.Input as EI
 import EventLoop.Output
+import Debug.Trace (trace)
 
 type Vector = (Float, Float)
         
@@ -55,6 +56,7 @@ 
 data Thickness = Thin
                | Thick
+               deriving (Eq, Show)
 
 data Directed  = Directed
                | Undirected
@@ -72,6 +74,7 @@                  | RemoveNodeG Label
                  | RemoveEdgeG Label Label
                  | ClearAllG
+                 deriving (Eq, Show)
 
 nodeRadius   = 20 :: Float                 
 textSize     = 16 :: Float
@@ -168,7 +171,11 @@                                                                                 arrow1End          = posOnVector yArrowSize upPerpLineVector arrowPerpStart  
                                                                                 arrow2End          = posOnVector yArrowSize downPerpLineVector arrowPerpStart 
 
-graphOutputToGraphical (WeightedLineG n1@(l1, pos1, _) n2@(l2, pos2, _) w colG thick direct) = lineGraphical ++ [Draw text name]
+graphOutputToGraphical (WeightedLineG n1@(l1, pos1, _) n2@(l2, pos2, _) w colG thick direct) = trace (  " halfSize: " ++ (show halfSize)
+                                                                                              ++ " upPerpLineVector: " ++ (show upPerpLineVector)
+                                                                                              ++ " textPerpStart: " ++ (show textPerpStart)
+                                                                                              ++ " textPos: " ++ (show textPos)
+                                                                                              ) lineGraphical ++ [Draw text name]
                                                                 where
                                                                     name          = lineName l1 l2
                                                                     col           = colorGToColor colG
@@ -242,14 +249,16 @@                                       where
                                           (xv, yv) = vectorize (x1, y1) (x2, y2)
                                           size     = vectorSize (xv, yv)
-                                          sign     = xv / (abs xv)
+                                          sign     = case xv of
+                                                        0 -> (-1)
+                                                        _ -> xv / (abs xv)
                                             
                                             
 -- | Returns the vector perpendicular on the given vector between the 2 points. Always has negative y and vector length 1; y is inverted in canvas
 upPerpendicularTo :: Pos -> Pos -> Vector
 upPerpendicularTo p1 p2 = ((-1) * xp, (-1) * yp)
                         where
-                            (xp, yp) = upPerpendicularTo p1 p2
+                            (xp, yp) = downPerpendicularTo p1 p2
                           
 -- | Returns the size of the vector                          
 vectorSize :: Vector -> Float
twentefp-graphs.cabal view
@@ -1,5 +1,5 @@ name:                twentefp-graphs
-version:             0.1.0.1
+version:             0.1.0.2
 synopsis:            Lab Assignments Environment at Univeriteit Twente
 description:         Lab Assignments Environment at Univeriteit Twente
 license:             BSD3