{-
%------------------------------------------------------------------------------
% Copyright (C) 1997, 1998, 2008 Joern Dinkla, www.dinkla.net
%------------------------------------------------------------------------------
%
% see
%     Joern Dinkla, Geometrische Algorithmen in Haskell, Diploma Thesis,
%     University of Bonn, Germany, 1998. 
%
-}

-- | Many dimensional points implemented with arrays. 

module GeomAlg.PointN (
     module GeomAlg.Point, 
     module GeomAlg.PointN) where

import GeomAlg.Point
import Array (Array, elems, listArray, bounds, (!))

newtype PointN a = PointN (Array Int a) deriving Eq

instance (Show a, Num a) => Show (PointN a) where
    showsPrec d (PointN xs)   = showsPrec d (elems xs)

pointN xs                     = PointN (listArray (1,length xs) xs)

instance Functor PointN where
	fmap f (PointN a) = PointN (fmap f a)

instance Point PointN where
    dimension (PointN a)      = snd (bounds a)
    ith i (PointN a)          = a ! i
    origin                    = error "Point.PointN no origin"
    (PointN x) <==> (PointN y)  
      | bounds x == bounds y  = and (zipWith (==) (elems x) (elems y))
                                -- x == y mag Hugs nicht, obwohl Eq (PointN a) gilt
      | otherwise             = error "Point.PointN dimension /="
    (PointN x) <+> (PointN y) 
      | bounds x == bounds y  = pointN (zipWith (+) (elems x) (elems y))
      | otherwise             = error "Point.PointN dimension /="
    (PointN x) <.> (PointN y) 
      | bounds x ==bounds y   = sum (zipWith (*) (elems x) (elems y))
      | otherwise             = error "Point.PointN dimension"

instance Num a                => Num (PointN a) where
    (+)			      = (<+>)
    (-)			      = (<->)
    negate		      = negateP
    (*)			      = undefined
    abs			      = fmap abs
    signum		      = undefined
    fromInteger		  = undefined