packages feed

cl3-linear-interface (empty) → 1.0.0.0

raw patch · 6 files changed

+214/−0 lines, 6 filesdep +basedep +cl3dep +linearsetup-changed

Dependencies added: base, cl3, linear

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for cl3-linear-interface++## 1.0.0.0  -- 2018-6-2++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, Nathan Waivio++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Nathan Waivio nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,15 @@++# Cl3 interface to/from Linear++A simple interface supporting to/from: V3, Quaternion, and M22.++The exported functions are:+*  toLinearV3+*  fromLinearV3+*  toLinearQuaternion+*  fromLinearQuaternion+*  toLinearM22+*  fromLinearM22+++
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cl3-linear-interface.cabal view
@@ -0,0 +1,81 @@+-- Initial cl3-linear-interface.cabal generated by cabal init.  For further documentation, +-- see http://haskell.org/cabal/users-guide/++-- The name of the package.+name:                cl3-linear-interface++-- The package version.  See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- https://wiki.haskell.org/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             1.0.0.0++-- A short (one-line) description of the package.+synopsis:            Interface to/from Cl3 and Linear.++-- A longer description of the package.+description:         Haskell Library implementing standard interface functions for the Algebra of Physical Space Cl(3,0) and Linear   ++-- URL for the project homepage or repository.+homepage:            https://github.com/waivio/cl3-linear-interface++bug-reports:         https://github.com/waivio/cl3-linear-interface/issues++-- The license under which the package is released.+license:             BSD3++-- The file containing the license text.+license-file:        LICENSE++-- The package author(s).+author:              Nathan Waivio++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer:          Nathan Waivio <nathan.waivio@gmail.com>++-- A copyright notice.+copyright:           Copyright (C) 2018 Nathan Waivio++category:            Math, Algebra++build-type:          Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+extra-source-files:  ChangeLog.md, README.md++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.10++source-repository head+  type:     git+  location: https://github.com/waivio/cl3-linear-interface.git++library+  -- Modules exported by the library.+  exposed-modules:+    Algebra.Geometric.Cl3.LinearInterface+  +  -- Compiler options+  ghc-options: -Wall -O2+  +  -- LANGUAGE extensions used by modules in this package.+  other-extensions:+    Trustworthy,+    ViewPatterns+  +  -- Other library packages from which modules are imported.+  build-depends:       +    base >=4.8 && <5,+    cl3 >=1.0 && <2,+    linear >=1.2 && <2+  +  -- Directories containing source files.+  hs-source-dirs:      src+  +  -- Base language which the package is written in.+  default-language:    Haskell2010+
+ src/Algebra/Geometric/Cl3/LinearInterface.hs view
@@ -0,0 +1,81 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE ViewPatterns #-}+++--------------------------------------------------------------------------------------------+-- |+-- Copyright   :  (C) 2018 Nathan Waivio+-- License     :  BSD3+-- Maintainer  :  Nathan Waivio <nathan.waivio@gmail.com>+-- Stability   :  Stable+-- Portability :  unportable+-- +-- Interface functions of Cl3 types to/from Linear. +-- +-------------------------------------------------------------------+++module Algebra.Geometric.Cl3.LinearInterface+(+ toLinearV3, + fromLinearV3, + toLinearQuaternion,+ fromLinearQuaternion,+ toLinearM22,+ fromLinearM22+) where++import safe Algebra.Geometric.Cl3 (Cl3(..), toV3, toH, toAPS, reduce)+import qualified Linear (V3(..), Quaternion(..), V2(..), M22)+import safe Data.Complex (Complex(..))++-- | 'toLinearV3' Convert a Cl3 V3 to a Linear V3+toLinearV3 :: Cl3 -> Linear.V3 Double+toLinearV3 (toV3 -> (V3 a1 a2 a3)) = Linear.V3 a1 a2 a3+toLinearV3 _ = error "Pattern Matching failure of toLinearV3 for the toV3/V3 View Pattern"++-- | 'fromLinearV3' Convert from a Linear V3 to a Cl3 V3+fromLinearV3 :: Real a => Linear.V3 a -> Cl3+fromLinearV3 (Linear.V3 (toRational -> a1) (toRational -> a2) (toRational -> a3)) = V3 (fromRational a1) (fromRational a2) (fromRational a3)++-- | 'toLinearQuaternion' Convert a Cl3 H to a Linear Quaternion+toLinearQuaternion :: Cl3 -> Linear.Quaternion Double+toLinearQuaternion (toH -> (H a0 a32 a31 a12)) = Linear.Quaternion a0 (Linear.V3 a32 a31 a12)+toLinearQuaternion _ = error "Pattern Matching failure of toLinearQuaternion for the toH/H View Pattern"++-- | 'fromLinearQuaternion' Convert from a Linear Quaternion to a Cl3 H+fromLinearQuaternion :: Real a => Linear.Quaternion a -> Cl3+fromLinearQuaternion (Linear.Quaternion (toRational -> a0) (Linear.V3 (toRational -> a32) (toRational -> a31) (toRational -> a12))) = +  H (fromRational a0) (fromRational a32) (fromRational a31) (fromRational a12)++-- | 'toLinearM22' Convert a Cl3 Cliffor to a Linear M22+toLinearM22 :: Cl3 -> Linear.M22 (Complex Double)+toLinearM22 (toAPS -> APS a0 a1 a2 a3 a23 a31 a12 a123) = +  let a = (a0+a3) :+ (a123+a12)+      b = (a1+a31) :+ (a23-a2)+      c = (a1-a31) :+ (a23+a2)+      d = (a0-a3) :+ (a123-a12)+  in Linear.V2 (Linear.V2 a b) (Linear.V2 c d)+toLinearM22 _ = error "Pattern Matching failure of toLinearM22 for the toAPS/APS View Pattern"++-- | 'fromLinearM22' Convert from a Linear M22 to a Cl3 Cliffor+fromLinearM22 :: Real a => Linear.M22 (Complex a) -> Cl3+fromLinearM22 (Linear.V2 (Linear.V2 (a :+ ai) (b :+ bi)) (Linear.V2 (c :+ ci) (d :+ di))) =+  let a' = fromRational (toRational a) :: Double+      ai' = fromRational (toRational ai) :: Double+      b' = fromRational (toRational b) :: Double+      bi' = fromRational (toRational bi) :: Double+      c' = fromRational (toRational c) :: Double+      ci' = fromRational (toRational ci) :: Double+      d' = fromRational (toRational d) :: Double+      di' = fromRational (toRational di) :: Double+      a0 = (a' + d') / 2+      a1 = (b' + c') / 2+      a2 = (ci' - bi') / 2+      a3 = (a' - d') / 2+      a23 = (ci' + bi') / 2+      a31 = (b' - c') / 2+      a12 = (ai' - di') / 2+      a123 = (ai' + di') / 2+  in reduce (APS a0 a1 a2 a3 a23 a31 a12 a123)+