VEC: add sortedX and sortedY

This commit is contained in:
hasufell 2014-11-29 05:08:54 +01:00
parent c20d0e2eb1
commit c831c29b14
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -4,6 +4,7 @@ module Algebra.Vector where
import Algebra.VectorTypes
import Control.Applicative
import Data.List (sortBy)
import Diagrams.TwoD.Types
import Graphics.Gloss.Geometry.Line
import GHC.Float
@ -112,6 +113,22 @@ sortedXY :: [PT] -> [PT]
sortedXY = fmap p2 . sortLex . fmap unp2
-- |Sort all points according to their X-coordinates only.
sortedX :: [PT] -> [PT]
sortedX xs =
fmap p2
. sortBy (\(a1, _) (a2, _) -> compare a1 a2)
$ fmap unp2 xs
-- |Sort all points according to their Y-coordinates only.
sortedY :: [PT] -> [PT]
sortedY xs =
fmap p2
. sortBy (\(_, b1) (_, b2) -> compare b1 b2)
$ fmap unp2 xs
-- |Apply a function on the coordinates of a point.
onPT :: ((Double, Double) -> (Double, Double)) -> PT -> PT
onPT f = p2 . f . unp2