oscpacking-0.2.1.1: Graphics/OscPacking/Boundary.hs
{--
This file is part of the OscPacking library.
Copyright 2016 Christopher Howard.
OscPacking 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.
OscPacking 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 OscPacking. If not, see <http://www.gnu.org/licenses/>.
--}
module Graphics.OscPacking.Boundary where
import Graphics.OscPacking.Geometry
type Boundary = Point -> Maybe Float
circleB :: Point -> Float -> Boundary
circleB originP r testP =
if d > r then Nothing else Just (r - d) where d = euclidean originP testP
rectB :: Point -> Float -> Float -> Boundary
rectB (bLX, bLY) width height (tPX, tPY) =
if or [tPX < bLX,
tPX > bLX + width,
tPY < bLY,
tPY > bLY + height]
then Nothing
else Just $ foldr min (1/0)
[tPX - bLX,
bLX + width - tPX,
tPY - bLY,
bLY + height - tPY]