From: Reino Ruusu Date: Mon, 14 Oct 2019 14:06:22 +0000 (+0300) Subject: Improvements to java.vecmath bindings to SCL. X-Git-Tag: v1.43.0~195 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f36217aeeb09c0c46f99886ee99772156ce9cfe6;p=simantics%2F3d.git Improvements to java.vecmath bindings to SCL. gitlab #28 Change-Id: Ic6350d7ecbeff7e9e55e053b779fa7592b20ac9a --- diff --git a/org.simantics.g3d/scl/G3D/Math/Tuple3d.scl b/org.simantics.g3d/scl/G3D/Math/Tuple3d.scl index f7779405..2be9c3c9 100644 --- a/org.simantics.g3d/scl/G3D/Math/Tuple3d.scl +++ b/org.simantics.g3d/scl/G3D/Math/Tuple3d.scl @@ -18,35 +18,38 @@ importJava "javax.vecmath.Tuple3d" where data MTuple3d @JavaName getX - getXM :: MTuple3d -> Double + getXM' :: MTuple3d -> Double @JavaName getY - getYM :: MTuple3d -> Double + getYM' :: MTuple3d -> Double @JavaName getZ - getZM :: MTuple3d -> Double + getZM' :: MTuple3d -> Double - setX :: MTuple3d -> Double -> () - setY :: MTuple3d -> Double -> () - setZ :: MTuple3d -> Double -> () + @JavaName setX + setX' :: MTuple3d -> Double -> () + @JavaName setY + setY' :: MTuple3d -> Double -> () + @JavaName setZ + setZ' :: MTuple3d -> Double -> () @JavaName add - addM :: MTuple3d -> Tuple3d -> () + addM' :: MTuple3d -> Tuple3d -> () @JavaName add - addM2 :: MTuple3d -> Tuple3d -> Tuple3d -> () + addM2' :: MTuple3d -> Tuple3d -> Tuple3d -> () @JavaName sub - subM :: MTuple3d -> Tuple3d -> () + subM' :: MTuple3d -> Tuple3d -> () @JavaName sub - subM2 :: MTuple3d -> Tuple3d -> Tuple3d -> () + subM2' :: MTuple3d -> Tuple3d -> Tuple3d -> () @JavaName negate - negateM :: MTuple3d -> () + negateM' :: MTuple3d -> () @JavaName negate - negateM2 :: MTuple3d -> Tuple3d -> () + negateM2' :: MTuple3d -> Tuple3d -> () @JavaName scale - scaleM :: MTuple3d -> Double -> () + scaleM' :: MTuple3d -> Double -> () @JavaName scale - scaleM2 :: MTuple3d -> Double -> Tuple3d -> () + scaleM2' :: MTuple3d -> Double -> Tuple3d -> () @private clone :: Tuple3d -> a @@ -64,17 +67,17 @@ applyMOp f x = runProc let freeze :: MTuple3d -> Tuple3d freeze = Java.unsafeCoerce -addTuple x y = applyMOp (flip addM y) x -subTuple x y = applyMOp (flip subM y) x -negateTuple = applyMOp negateM -scaleTuple x s = applyMOp (flip scaleM s) x +addTuple x y = applyMOp (flip addM' y) x +subTuple x y = applyMOp (flip subM' y) x +negateTuple = applyMOp negateM' +scaleTuple x s = applyMOp (flip scaleM' s) x class Tuple3dClass a where asTuple :: a -> Tuple3d asTuple = Java.unsafeCoerce - asMTuple :: a -> MTuple3d - asMTuple x = copyMTuple3d (asTuple x) + getMTuple :: a -> MTuple3d + getMTuple x = copyMTuple3d (asTuple x) getX :: a -> Double getX = getX' . asTuple @@ -106,3 +109,49 @@ instance Tuple3dClass Tuple3d where sub = subTuple negate = negateTuple scale = scaleTuple + +class MTuple3dClass a where + asMTuple :: a -> MTuple3d + asMTuple = Java.unsafeCoerce + + getXM :: a -> Double + getXM = getXM' . asMTuple + + getYM :: a -> Double + getYM = getYM' . asMTuple + + getZM :: a -> Double + getZM = getZM' . asMTuple + + setX :: a -> Double -> () + setX x v = setX' (asMTuple x) v + + setY :: a -> Double -> () + setY x v = setY' (asMTuple x) v + + setZ :: a -> Double -> () + setZ x v = setZ' (asMTuple x) v + + addM :: Tuple3dClass b => a -> b -> () + addM x y = addM' (asMTuple x) (asTuple y) + + addM2 :: Tuple3dClass b => a -> b -> b -> () + addM2 x y z = addM2' (asMTuple x) (asTuple y) (asTuple z) + + subM :: Tuple3dClass b => a -> b -> () + subM x y = subM' (asMTuple x) (asTuple y) + + subM2 :: Tuple3dClass b => a -> b -> Tuple3d -> () + subM2 x y z = subM2' (asMTuple x) (asTuple y) (asTuple z) + + negateM :: a -> () + negateM x = negateM' (asMTuple x) + + negateM2 :: Tuple3dClass b => a -> b -> () + negateM2 x y = negateM2' (asMTuple x) (asTuple y) + + scaleM :: a -> Double -> () + scaleM x s = scaleM' (asMTuple x) s + + scaleM2 :: Tuple3dClass b => a -> Double -> b -> () + scaleM2 x s y = scaleM2' (asMTuple x) s (asTuple y) diff --git a/org.simantics.g3d/scl/G3D/Math/Vector3d.scl b/org.simantics.g3d/scl/G3D/Math/Vector3d.scl index 59cfdf97..308bb88e 100644 --- a/org.simantics.g3d/scl/G3D/Math/Vector3d.scl +++ b/org.simantics.g3d/scl/G3D/Math/Vector3d.scl @@ -67,6 +67,7 @@ freeze :: MVector3d -> Vector3d freeze = Java.unsafeCoerce instance Tuple3dClass Vector3d +instance MTuple3dClass MVector3d copyVector3d :: Tuple3dClass a => a -> Vector3d copyVector3d = copyVector3d' . asTuple