-- This module provides basic algebra with 2d-vectors and geomtric shapes -- Copyright (C) 2015, Sebastian Jordan -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . module Geom2d.Shape ( Shape , Spatial (..) , circle , rectangle , convexHull , centerPoint ) where import Geom2d.Point import Geom2d.Rotation import Geom2d.Shape.Internal import Geom2d.Translate circle :: Num a => p a -> a -> Shape p a circle m r = ShapeCircle $ mkCircleInt m r rectangle :: (Translate p, Eq a, RealFloat a, Point p, Rotation p) => p a -> a -> a -> Maybe (Shape p a) rectangle m a b = ShapePolygon <$> rectangleInt m a b convexHull :: (Num (p a), Fractional a, Ord a, Scale p, Point p) => [p a] -> Maybe (Shape p a) convexHull list = ShapePolygon <$> convexHull' list centerPoint :: (Fractional a, Scale p, Num (p a)) => Shape p a -> p a centerPoint (ShapeCircle (Circle m _)) = m centerPoint (ShapePolygon (Polygon m vs)) = let n = length vs in m + scale (1/fromIntegral n) (sum vs)