Skip to content

Commit

Permalink
Transformable Segment, Trust
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoruiz committed Mar 8, 2015
1 parent 378b2df commit 273ab2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/base/src/Util/Geometry.hs
Expand Up @@ -54,7 +54,8 @@ module Util.Geometry
intersectionLineSegment,
Polygon(..),
orientation, polygonSides,
DMat
DMat,
Trust(..)
) where

import Util.Small
Expand Down Expand Up @@ -230,6 +231,15 @@ apMat :: (Vectorlike a, Vectorlike b, Matrixlike t) => (Mat -> Mat) -> t -> [a]
apMat _ _ [] = []
apMat g h xs = (map unsafeFromVector . toRows) . (<> (g.trans) (toMatrix h)) . fromRows . (map toVector) $ xs

newtype Trust t = Trust t

instance Transformable Homography x => Transformable (Trust (Matrix Double)) x
where
type TResult (Trust (Matrix Double)) x = TResult Homography x
apTrans (Trust m) = apTrans h
where
h = unsafeFromMatrix m :: Homography

instance Transformable Homography [HPoint]
where
type TResult Homography [HPoint] = [HPoint]
Expand Down Expand Up @@ -645,7 +655,6 @@ instance Transformable Homography Polyline
apTrans h (Closed ps) = Closed (apTrans h ps)
apTrans h (Open ps) = Open (apTrans h ps)


--------------------------------------------------------------------------------

newtype Polygon = Polygon { polygonNodes :: [Point] }
Expand Down Expand Up @@ -674,6 +683,16 @@ instance Storable Segment where
pokeElemOff pb 0 a
pokeElemOff pb 1 b

instance Transformable Homography [Segment]
where
type TResult Homography [Segment] = [Segment]
apTrans h = map (apTrans h)

instance Transformable Homography Segment
where
type TResult Homography Segment = Segment
apTrans t (Segment p q) = Segment (apTrans t p) (apTrans t q)

--------------------------------------------------------------------------------

-- | linear interpolation between two points
Expand Down
2 changes: 2 additions & 0 deletions packages/base/src/Util/Small.hs
Expand Up @@ -19,6 +19,8 @@ Stability : provisional
Type safe small arrays.
(superseded by HMatrix.Static (to be done))
-}
-----------------------------------------------------------------------------

Expand Down

0 comments on commit 273ab2a

Please sign in to comment.