vector-space-points-0.1.2.0/0000755000000000000000000000000012027623244013745 5ustar0000000000000000vector-space-points-0.1.2.0/Setup.hs0000644000000000000000000000005612027623244015402 0ustar0000000000000000import Distribution.Simple main = defaultMain vector-space-points-0.1.2.0/LICENSE0000644000000000000000000000276212027623244014761 0ustar0000000000000000Copyright (c) 2011, Brent Yorgey 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 Brent Yorgey 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. vector-space-points-0.1.2.0/vector-space-points.cabal0000644000000000000000000000175712027623244020650 0ustar0000000000000000-- Initial vector-space-points.cabal generated by cabal init. For further -- documentation, see http://haskell.org/cabal/users-guide/ name: vector-space-points version: 0.1.2.0 synopsis: A type for points, as distinct from vectors. description: A type for points, as distinct from vectors, built on top of Data.AffineSpace. license: BSD3 license-file: LICENSE author: Brent Yorgey maintainer: byorgey@cis.upenn.edu copyright: (c) 2011-2012 Brent Yorgey category: Math build-type: Simple cabal-version: >=1.10 source-repository head type: git location: git://github.com/diagrams/vector-space-points.git library exposed-modules: Data.AffineSpace.Point build-depends: base >=4.0 && < 4.7, vector-space >=0.7 && < 0.9, newtype ==0.2.* hs-source-dirs: src default-language: Haskell2010vector-space-points-0.1.2.0/src/0000755000000000000000000000000012027623244014534 5ustar0000000000000000vector-space-points-0.1.2.0/src/Data/0000755000000000000000000000000012027623244015405 5ustar0000000000000000vector-space-points-0.1.2.0/src/Data/AffineSpace/0000755000000000000000000000000012027623244017551 5ustar0000000000000000vector-space-points-0.1.2.0/src/Data/AffineSpace/Point.hs0000644000000000000000000000414712027623244021204 0ustar0000000000000000{-# LANGUAGE TypeFamilies , MultiParamTypeClasses , FlexibleInstances , DeriveFunctor , DeriveDataTypeable #-} ----------------------------------------------------------------------------- -- | -- Module : Data.AffineSpace.Point -- Copyright : (c) 2011 Brent Yorgey -- License : BSD-style (see LICENSE) -- Maintainer : byorgey@cis.upenn.edu -- -- A type for /points/ (as distinct from vectors), with an appropriate -- AffineSpace instance. -- ----------------------------------------------------------------------------- module Data.AffineSpace.Point ( -- * Points Point(..), unPoint, origin, (*.) ) where import Data.VectorSpace import Data.AffineSpace import Control.Newtype import Data.Data (Data) import Data.Typeable (Typeable) ------------------------------------------------------------ -- Points ------------------------------------------------ ------------------------------------------------------------ -- | @Point@ is a newtype wrapper around vectors used to represent -- points, so we don't get them mixed up. The distinction between -- vectors and points is important: translations affect points, but -- leave vectors unchanged. Points are instances of the -- 'AffineSpace' class from "Data.AffineSpace". newtype Point v = P v deriving (Eq, Ord, Read, Show, Data, Typeable, Functor) -- | Convert a point @p@ into the vector from the origin to @p@. This -- should be considered a \"semantically unsafe\" operation; think -- carefully about whether and why you need to use it. The -- recommended way to do this conversion would be to write @(p -- '.-.' 'origin')@. unPoint :: Point v -> v unPoint (P v) = v instance Newtype (Point v) v where pack = P unpack (P v) = v -- | The origin of the vector space @v@. origin :: AdditiveGroup v => Point v origin = P zeroV instance AdditiveGroup v => AffineSpace (Point v) where type Diff (Point v) = v P v1 .-. P v2 = v1 ^-^ v2 P v1 .+^ v2 = P (v1 ^+^ v2) -- | Scale a point by a scalar. (*.) :: VectorSpace v => Scalar v -> Point v -> Point v s *. P v = P (s *^ v)