VEC: Fix the inRange function

It now takes a PROPER square, as in ((xmin, ymin), (xmax, ymax))
instead of ((xmin, xmax), (ymin, ymax)) and also works
with negative values.

Because the meaning of the arguments has changed, we also
had to fix all uses of it.
This commit is contained in:
2014-12-17 03:35:33 +01:00
parent c33827b63e
commit 2ccb52eb62
6 changed files with 59 additions and 33 deletions

View File

@@ -35,9 +35,9 @@ data DiagProp = MkProp {
-- |The thickness of the dots.
dotSize :: Double,
-- |The dimensions of the x-axis.
xDimension :: Coord,
xDimension :: (Double, Double),
-- |The dimensions of the y-axis.
yDimension :: Coord,
yDimension :: (Double, Double),
-- |Algorithm to use.
algo :: Int,
-- |If we want to show the grid.
@@ -135,7 +135,14 @@ maybeDiag b d
filterValidPT :: DiagProp -> [PT] -> [PT]
filterValidPT p = filter (inRange (xDimension p, yDimension p))
filterValidPT =
filter
. inRange
. diagDimSquare
diagDimSquare :: DiagProp -> Square
diagDimSquare p = dimToSquare (xDimension p) $ yDimension p
-- |Draw a list of points.
@@ -154,9 +161,13 @@ drawP vt ds =
rectByDiagonal :: (Double, Double) -- ^ sw point
-> (Double, Double) -- ^ nw point
-> Diagram Cairo R2
rectByDiagonal (xmin, xmax) (ymin, ymax) =
rect (xmax - xmin) (ymax - ymin)
# moveTo (p2 ((xmax + xmin) / 2, (ymax + ymin) / 2))
rectByDiagonal (xmin, ymin) (xmax, ymax) =
fromVertices [p2 (xmin, ymin)
, p2 (xmax, ymin)
, p2 (xmax, ymax)
, p2 (xmin, ymax)
, p2 (xmin, ymin)
]
-- |Creates a Diagram from a point that shows the coordinates