VEC: add sortedX and sortedY
This commit is contained in:
parent
c20d0e2eb1
commit
c831c29b14
@ -4,6 +4,7 @@ module Algebra.Vector where
|
|||||||
|
|
||||||
import Algebra.VectorTypes
|
import Algebra.VectorTypes
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
import Data.List (sortBy)
|
||||||
import Diagrams.TwoD.Types
|
import Diagrams.TwoD.Types
|
||||||
import Graphics.Gloss.Geometry.Line
|
import Graphics.Gloss.Geometry.Line
|
||||||
import GHC.Float
|
import GHC.Float
|
||||||
@ -112,6 +113,22 @@ sortedXY :: [PT] -> [PT]
|
|||||||
sortedXY = fmap p2 . sortLex . fmap unp2
|
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.
|
-- |Apply a function on the coordinates of a point.
|
||||||
onPT :: ((Double, Double) -> (Double, Double)) -> PT -> PT
|
onPT :: ((Double, Double) -> (Double, Double)) -> PT -> PT
|
||||||
onPT f = p2 . f . unp2
|
onPT f = p2 . f . unp2
|
||||||
|
Loading…
Reference in New Issue
Block a user