Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 45 lines (39 sloc) 1.099 kB
8a65d26 `-\'
Nik Nyby authored
1 module Rectangle (
2 Rectangle(..),
3 boxAroundRect,
4 vertexRect,
1b38b1c generalized within to Rectangle
Nik Nyby authored
5 within,
8a65d26 `-\'
Nik Nyby authored
6 ) where
7 import Graphics.UI.GLUT
8
1b38b1c generalized within to Rectangle
Nik Nyby authored
9 import Util
10
8a65d26 `-\'
Nik Nyby authored
11 data Rectangle =
12 Rectangle
13 {
14 rectX :: GLdouble,
15 rectY :: GLdouble,
16 rectWidth :: GLdouble,
17 rectHeight :: GLdouble
18 } deriving (Show, Eq)
19
20 -- return a list of four vertices for a rectangle, given position and size
21 vertexRect :: Rectangle -> [Vertex2 GLdouble]
22 vertexRect (Rectangle x y width height) =
23 [(Vertex2 (x-w) (y+h))
24 , (Vertex2 (x-w) (y-h))
25 , (Vertex2 (x+w) (y-h))
26 , (Vertex2 (x+w) (y+h))]
27 where
28 w = width / 2
29 h = height / 2
30
31 boxAroundRect :: Rectangle -> GLdouble -> Rectangle
32 boxAroundRect r i = r {
33 rectWidth = rectWidth r + i,
34 rectHeight = rectHeight r + i
35 }
1b38b1c generalized within to Rectangle
Nik Nyby authored
36
37 -- returns True if the point lies within the rect's area
38 within :: Position -> Rectangle -> Bool
39 within (Position px py) (Rectangle rx ry rw rh) =
40 (x <= (rx+(rw/2))) && (x >= (rx-(rw/2)))
41 && (y <= (ry+(rh/2))) && (y >= (ry-(rh/2)))
42 where
43 x = conv px
44 y = conv py
Something went wrong with that request. Please try again.