geom2d-0.2.1: Geom2d/Distance.hs
-- 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 <http://www.gnu.org/licenses/>.
{-# LANGUAGE MultiParamTypeClasses #-}
-- | This module provides a type class to modell distance between
-- geometric objects.
module Geom2d.Distance where
import Linear.V2
import Geom2d.Point.Internal
-- | The Distance between objects that have no volume, like points,
-- should satisfy the triangle inequality.
class Distance p q where
distance :: (Ord a, Floating a) => p a -> q a -> a
instance Distance Point' Point' where
distance (Point' (a1,a2)) (Point' (b1,b2)) =
sqrt $ (a1 - b1)^(2::Int) + (a2 - b2)^(2::Int)
instance Distance V2 V2 where
distance (V2 a1 a2) (V2 b1 b2) =
sqrt $ (a1 - b1)^(2::Int) + (a2 - b2)^(2::Int)