]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/scl/G3D/Math/Vector3d.scl
Removed 3D modelling preferences page description which is equals title
[simantics/3d.git] / org.simantics.g3d / scl / G3D / Math / Vector3d.scl
1 include "./Tuple3d"
2
3 import "JavaBuiltin" as Java
4
5 importJava "javax.vecmath.Vector3d" where
6   // Immutable mapping
7   data Vector3d
8   
9   dot :: Vector3d -> Vector3d -> Double
10   
11   @JavaName length
12   vectorLength :: Vector3d -> Double
13   @JavaName lengthSquared
14   vectorLengthSquared :: Vector3d -> Double
15   
16   angle :: Vector3d -> Vector3d -> Double
17   
18   @JavaName "<init>"
19   createVector3d :: Double -> Double -> Double -> Vector3d
20   @JavaName "<init>"
21   copyVector3d' :: Tuple3d -> Vector3d
22   @JavaName "<init>"
23   defaultVector3d :: Vector3d
24
25   // Mutable mapping
26   data MVector3d
27   
28   @JavaName cross
29   crossM :: MVector3d -> Vector3d -> Vector3d -> <Proc> ()
30
31   @JavaName normalize
32   normalizeM :: MVector3d -> <Proc> ()
33   
34   @JavaName normalize
35   normalizeM2 :: MVector3d -> Vector3d -> <Proc> ()
36   
37   @JavaName dot
38   dotM :: MVector3d -> MVector3d -> <Proc> Double
39   
40   @JavaName length
41   lengthM :: MVector3d -> <Proc> Double
42   @JavaName lengthSquared
43   lengthSquaredM :: MVector3d -> <Proc> Double
44
45   @JavaName angle  
46   angleM :: MVector3d -> MVector3d -> <Proc> Double
47   
48   @JavaName "<init>"
49   createMVector3d :: Double -> Double -> Double -> <Proc> MVector3d
50   @JavaName "<init>"
51   copyMVector3d' :: Tuple3d -> <Proc> MVector3d
52   @JavaName "<init>"
53   defaultMVector3d :: <Proc> MVector3d
54
55 @private
56 applyMOp :: (MVector3d -> <Proc> ()) -> (<Proc> MVector3d) -> Vector3d
57 applyMOp op gen = runProc let
58     z = gen
59     op z
60     in freeze z
61
62 normalize :: Vector3d -> Vector3d
63 normalize v = applyMOp normalizeM (copyMVector3d (asTuple v))
64
65 cross :: Vector3d -> Vector3d -> Vector3d
66 cross x y = applyMOp (\z -> crossM z x y) defaultMVector3d
67
68 freeze :: MVector3d -> <Proc> Vector3d
69 freeze = Java.unsafeCoerce
70
71 instance Tuple3dClass Vector3d
72 instance MTuple3dClass MVector3d
73
74 copyVector3d :: Tuple3dClass a => a -> Vector3d
75 copyVector3d = copyVector3d' . asTuple
76
77 copyMVector3d :: Tuple3dClass a => a -> <Proc> MVector3d
78 copyMVector3d = copyMVector3d' . asTuple