packages feed

HGamer3D-Data 0.1.9 → 0.2.0

raw patch · 4 files changed

+105/−48 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- HGamer3D.Data.Angle: degrees :: Radians -> Degrees
- HGamer3D.Data.Angle: instance Angle Degrees
- HGamer3D.Data.Angle: instance Angle Radians
- HGamer3D.Data.Angle: radians :: Degrees -> Radians
+ HGamer3D.Data.Angle: Deg :: Float -> Angle
+ HGamer3D.Data.Angle: Rad :: Float -> Angle
+ HGamer3D.Data.Angle: acosA :: Float -> Angle
+ HGamer3D.Data.Angle: addA :: Angle -> Angle -> Angle
+ HGamer3D.Data.Angle: asinA :: Float -> Angle
+ HGamer3D.Data.Angle: atanA :: Float -> Angle
+ HGamer3D.Data.Angle: cosA :: Angle -> Float
+ HGamer3D.Data.Angle: data Angle
+ HGamer3D.Data.Angle: divA :: Angle -> Float -> Angle
+ HGamer3D.Data.Angle: fromAngle :: Angles a => Angle -> a
+ HGamer3D.Data.Angle: instance Angles Degrees
+ HGamer3D.Data.Angle: instance Angles Float
+ HGamer3D.Data.Angle: instance Angles Radians
+ HGamer3D.Data.Angle: instance Eq Angle
+ HGamer3D.Data.Angle: instance Ord Angle
+ HGamer3D.Data.Angle: instance Show Angle
+ HGamer3D.Data.Angle: mulA :: Angle -> Float -> Angle
+ HGamer3D.Data.Angle: sinA :: Angle -> Float
+ HGamer3D.Data.Angle: subA :: Angle -> Angle -> Angle
+ HGamer3D.Data.Angle: tanA :: Angle -> Float

Files

HGamer3D-Data.cabal view
@@ -1,5 +1,5 @@ Name:                HGamer3D-Data
-Version:             0.1.9
+Version:             0.2.0
 Synopsis:            Windows Game Engine for the Haskell Programmer - Data Definitions
 Description:         
 	HGamer3D is a game engine for developing 3D games in the programming 
@@ -13,15 +13,15 @@ Author:              Peter Althainz
 Maintainer:          althainz@gmail.com
 Build-Type:          Simple
-Cabal-Version:       >=1.2
+Cabal-Version:       >=1.4
 Homepage:            http://www.hgamer3d.org
-Category:            Game
+Category:            Game Engine
 Extra-source-files:  Setup.hs 
 
 Library
   Build-Depends:     base >= 3 && < 5, vect
 
-  Exposed-modules:   HGamer3D.Data.Vector,HGamer3D.Data.Colour,HGamer3D.Data.HG3DClass,HGamer3D.Data.Angle
+  Exposed-modules:   HGamer3D.Data.Vector,HGamer3D.Data.Vector.Instances,HGamer3D.Data.Colour,HGamer3D.Data.HG3DClass,HGamer3D.Data.Angle
   Other-modules:     
 
   c-sources:         
HGamer3D/Data/Angle.hs view
@@ -20,63 +20,83 @@ 
 {- |
 	Angles as Degrees or Radians, based on Float datatype
-	copied and changed to float from AC-Angle packet
 -}
 
 module HGamer3D.Data.Angle 
 
 (
 	-- export Radians and Degrees 
-	Radians (Radians),
-	Degrees (Degrees),
-	degrees,
-	radians
-	
-	-- instances are automatically exported
-	-- Angle, sine, cosine, tangent, arcsine, arccosine, arctangent
+	Angle (..),
+	fromAngle,
+	addA,
+	subA,
+	mulA,
+	divA,
+	sinA,
+	cosA,
+	tanA,
+	asinA,
+	acosA,
+	atanA,
 	
+	Radians (..),
+	Degrees (..),
 )
 
 where
 
--- | An angle in radians.
-data Radians = Radians Float deriving (Eq, Ord, Show)
 
--- | An angle in degrees.
-data Degrees = Degrees Float deriving (Eq, Ord, Show)
+data Angle = Rad Float | Deg Float deriving (Eq, Ord, Show)
 
--- | Convert from radians to degrees.
-degrees :: Radians -> Degrees
-degrees (Radians x) = Degrees (x/pi*180)
+sinA :: Angle -> Float
+sinA = sin . fromAngle
 
--- | Convert from degrees to radians.
-radians :: Degrees -> Radians
-radians (Degrees x) = Radians (x/180*pi)
+cosA :: Angle -> Float
+cosA = cos . fromAngle
 
--- | Type-class for angles.
-class Angle a where
-  sine    :: a -> Float
-  cosine  :: a -> Float
-  tangent :: a -> Float
+tanA :: Angle -> Float
+tanA = tan . fromAngle
 
-  arcsine    :: Float -> a
-  arccosine  :: Float -> a
-  arctangent :: Float -> a
+asinA :: Float -> Angle
+asinA = Rad . asin
 
-instance Angle Radians where
-  sine    (Radians x) = sin x
-  cosine  (Radians x) = cos x
-  tangent (Radians x) = tan x
+acosA :: Float -> Angle
+acosA = Rad . acos
 
-  arcsine    x = Radians (asin x)
-  arccosine  x = Radians (acos x)
-  arctangent x = Radians (atan x)
+atanA :: Float -> Angle
+atanA = Rad . atan
 
-instance Angle Degrees where
-  sine    =    sine . radians
-  cosine  =  cosine . radians
-  tangent = tangent . radians
+addA :: Angle -> Angle -> Angle
+addA a b = Rad $ (fromAngle a) + (fromAngle b)
 
-  arcsine    = degrees . arcsine
-  arccosine  = degrees . arccosine
-  arctangent = degrees . arctangent
+subA :: Angle -> Angle -> Angle
+subA a b = Rad $ (fromAngle a) - (fromAngle b)
+
+mulA :: Angle -> Float -> Angle
+mulA a b = Rad $ (fromAngle a) * b
+
+divA :: Angle -> Float -> Angle
+divA a b = Rad $ (fromAngle a) / b
+
+data Radians = Radians Float deriving (Eq, Ord, Show)
+data Degrees = Degrees Float deriving (Eq, Ord, Show)
+
+class Angles a where
+	toAngle :: a -> Angle
+	fromAngle :: Angle -> a
+	
+instance Angles Float where
+	toAngle r = Rad r
+	fromAngle (Rad r) = r
+	fromAngle (Deg d) = d/180*pi
+	
+instance Angles Radians where
+	toAngle (Radians r) = Rad r
+	fromAngle (Rad r) = (Radians r)
+	fromAngle (Deg d) = (Radians (d/180*pi))
+	
+instance Angles Degrees where
+	toAngle (Degrees d) = Deg d
+	fromAngle (Deg d) = (Degrees d)
+	fromAngle (Rad r) = (Degrees (r/pi*180))
+	
HGamer3D/Data/Vector.hs view
@@ -20,15 +20,17 @@ 
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 
+-- book: math3d vector lib
+-- |Includes the right pieces of the Vect libray of Balazs Komuves.
+-- see: <http://hackage.haskell.org/package/vect>
 module HGamer3D.Data.Vector
-
 (
-		module Data.Vect.Float,
-		module Data.Vect.Float.Util.Quaternion
+	module Data.Vect.Float,
+	module Data.Vect.Float.Util.Quaternion
 )
 
 where
 
 import Data.Vect.Float
 import Data.Vect.Float.Util.Quaternion
-
+-- book: end
+ HGamer3D/Data/Vector/Instances.hs view
@@ -0,0 +1,35 @@+-- This source file is part of HGamer3D
+-- (A project to enable 3D game development in Haskell)
+-- For the latest info, see http://www.althainz.de/HGamer3D.html
+--
+-- (c) 2011 Peter Althainz
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+-- Vector2.hs
+
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+
+-- book: math3d vector lib
+-- |Includes the right pieces of the Vect libray of Balazs Komuves.
+-- see: <http://hackage.haskell.org/package/vect>
+
+module HGamer3D.Data.Vector.Instances
+(
+	module Data.Vect.Float.Instances,
+)
+
+where
+
+import Data.Vect.Float.Instances
+-- book: end