-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.hs
30 lines (23 loc) · 817 Bytes
/
Util.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Util (
conv,
Pos,
posConv,
posOp,
) where
import Graphics.UI.GLUT
-- generalize an Integral
conv :: (Integral a, Num b) => a -> b
conv = fromInteger . toInteger
{- TODO: GL uses `Position' but I don't know how to get the x and y values out
- of a Position without pattern matching, because it's defined as:
- data Position = Position !GLint !GLint
- So I made a tuple type for co-ordinates but I'm worried it's unnecessary and
- it's annoying to have another type to worry about converting to and from.
-}
type Pos = (GLdouble,GLdouble)
-- convert from a GL Position
posConv :: Position -> Pos
posConv (Position x y) = (conv x,conv y)
-- apply a binary function over Pos
posOp :: (GLdouble -> GLdouble -> GLdouble) -> Pos -> Pos -> Pos
posOp op (a,b) (x,y) = (a `op` x, b `op` y)