packages feed

AC-Angle (empty) → 1.0

raw patch · 4 files changed

+85/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ AC-Angle.cabal view
@@ -0,0 +1,22 @@+Cabal-Version: >= 1.6
+Name:          AC-Angle
+Version:       1.0
+Stability:     Experimental
+Synopsis:      Angles in degrees and radians.
+
+Description:
+
+  A simple little library for dealing with geometric angles.
+
+Category:      Data, Math, Numerical
+License:       BSD3
+License-file:  License.txt
+Author:        Andrew Coppin
+Maintainer:    MathematicalOrchid@hotmail.com
+Build-Type:    Simple
+Tested-With:   GHC == 6.10.3
+
+Library
+  Exposed-modules: Data.Angle
+  Build-Depends:   base >= 4 && < 5
+  HS-Source-Dirs:  .
+ Data/Angle.hs view
@@ -0,0 +1,51 @@+{- |
+  Deal with angles measured in degrees or radians.
+
+  Names are kept deliberately different from the standard prelude to avoid name clashes.
+-}
+
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+
+module Data.Angle where
+
+-- | An angle in radians.
+newtype Radians x = Radians x deriving (Eq, Ord, Show, Num, Fractional)
+
+-- | An angle in degrees.
+newtype Degrees x = Degrees x deriving (Eq, Ord, Show, Num, Fractional)
+
+-- | Convert from radians to degrees.
+degrees :: (Floating x) => Radians x -> Degrees x
+degrees (Radians x) = Degrees (x/pi*180)
+
+-- | Convert from degrees to radians.
+radians :: (Floating x) => Degrees x -> Radians x
+radians (Degrees x) = Radians (x/180*pi)
+
+-- | Type-class for angles.
+class Angle a where
+  sine    :: (Floating x) => a x -> x
+  cosine  :: (Floating x) => a x -> x
+  tangent :: (Floating x) => a x -> x
+
+  arcsine    :: (Floating x) => x -> a x
+  arccosine  :: (Floating x) => x -> a x
+  arctangent :: (Floating x) => x -> a x
+
+instance Angle Radians where
+  sine    (Radians x) = sin x
+  cosine  (Radians x) = cos x
+  tangent (Radians x) = tan x
+
+  arcsine    x = Radians (asin x)
+  arccosine  x = Radians (acos x)
+  arctangent x = Radians (atan x)
+
+instance Angle Degrees where
+  sine    =    sine . radians
+  cosine  =  cosine . radians
+  tangent = tangent . radians
+
+  arcsine    = degrees . arcsine
+  arccosine  = degrees . arccosine
+  arctangent = degrees . arctangent
+ License.txt view
@@ -0,0 +1,10 @@+Copyright (c) 2009, Andrew Coppin
+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 Andrew Coppin nor the names of the 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 HOLDER 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple
+main = defaultMain