]> gitweb.michael.orlitzky.com - spline3.git/blob - Point.hs
d0859bfc54208d9b096a4f876404a79682d6423e
[spline3.git] / Point.hs
1 {-# LANGUAGE TypeSynonymInstances #-}
2
3 module Point
4 where
5
6 type Point = (Double, Double, Double)
7
8 x_coord :: Point -> Double
9 x_coord (x, _, _) = x
10
11 y_coord :: Point -> Double
12 y_coord (_, y, _) = y
13
14 z_coord :: Point -> Double
15 z_coord (_, _, z) = z
16
17 instance Num Point where
18 p1 + p2 = (x1+x2, y1+y2, z1+z2)
19 where
20 x1 = x_coord p1
21 x2 = x_coord p2
22 y1 = y_coord p1
23 y2 = y_coord p2
24 z1 = z_coord p1
25 z2 = z_coord p2
26
27 p1 - p2 = (x1-x2, y1-y2, z1-z2)
28 where
29 x1 = x_coord p1
30 x2 = x_coord p2
31 y1 = y_coord p1
32 y2 = y_coord p2
33 z1 = z_coord p1
34 z2 = z_coord p2
35
36 p1 * p2 = (x1*x2, y1*y2, z1*z2)
37 where
38 x1 = x_coord p1
39 x2 = x_coord p2
40 y1 = y_coord p1
41 y2 = y_coord p2
42 z1 = z_coord p1
43 z2 = z_coord p2
44
45 abs (x, y, z) = (abs x, abs y, abs z)
46 signum (x, y, z) = (signum x, signum y, signum z)
47 fromInteger n = (fromInteger n, fromInteger n, fromInteger n)
48
49
50 scale :: Point -> Double -> Point
51 scale (x, y, z) d = (x*d, y*d, z*d)