module Graphics.Render where
import Data.Ext
import Control.Lens
import Data.Geometry.Point
import Data.Geometry.Triangle
import Data.Geometry.LineSegment
import Data.Geometry.Transformation
import Data.Geometry.Properties
renderTriangle :: Fractional r => Transformation 3 r -> Triangle 3 p r -> Triangle 2 p r
renderTriangle = renderWithTransform projectTriangle
where
projectTriangle (Triangle p q r) = Triangle (p&core %~ projectPoint)
(q&core %~ projectPoint)
(r&core %~ projectPoint)
renderPoint :: Fractional r => Transformation 3 r -> Point 3 r -> Point 2 r
renderPoint = renderWithTransform projectPoint
renderLineSegment :: Fractional r => Transformation 3 r -> LineSegment 3 p r -> LineSegment 2 p r
renderLineSegment = renderWithTransform project
where
project s = s&endPoints.core %~ projectPoint
renderWithTransform :: (Fractional r, IsTransformable g, Dimension g ~ 3, NumType g ~ r)
=> (g -> g')
-> Transformation 3 r
-> g
-> g'
renderWithTransform project t = project . transformBy t