hgeometry-kernel
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageGHC2024

HGeometry.Viewport

Description

A Geometric viewport; i.e. some way of "viewing" only one particular rectangular region of a larger 2d space.

Synopsis

Documentation

data Viewport r Source #

Represents a viewport ; i.e. a rectangle through which we view the world.

Constructors

Viewport (Rectangle (Point 2 r)) (Transformation 2 r) 

Instances

Instances details
Show r => Show (Viewport r) Source # 
Instance details

Defined in HGeometry.Viewport

Eq r => Eq (Viewport r) Source # 
Instance details

Defined in HGeometry.Viewport

Methods

(==) :: Viewport r -> Viewport r -> Bool Source #

(/=) :: Viewport r -> Viewport r -> Bool Source #

viewPort :: forall r f. Functor f => (Rectangle (Point 2 r) -> f (Rectangle (Point 2 r))) -> Viewport r -> f (Viewport r) Source #

Lens to access the viewport rectangle

worldToHost :: forall r f. Functor f => (Transformation 2 r -> f (Transformation 2 r)) -> Viewport r -> f (Viewport r) Source #

The transformation

hostToWorld :: Fractional r => Getter (Viewport r) (Transformation 2 r) Source #

Host to world transformation, i.e. given a point in the host coordinate system, we can compute the point in world coordinates using this transformation.

Smart constructors

centeredOrigin :: (Fractional r, Rectangle_ rectangle point, Point_ point 2 r) => rectangle -> Viewport r Source #

Creates a viewport in which the origin is at the center of the viewport

alignedOrigin :: Num r => Rectangle (Point 2 r) -> Viewport r Source #

Creates a viewport in which the origin at the bottom left of the viewport

graphicsOrigin :: Num r => Rectangle (Point 2 r) -> Viewport r Source #

Same as alignedOrigin, except that we also flip the y-direction.

From the view of a math coordinate system, this puts the origin in the top-left, and has the y-coordinates going down.

From the view of a "graphics" coordiante system, this actually puts the origin in the bottom left of the rectangle and the y-axixs up; so it turns the viewport into a "proper" math viewport.

normalizedCenteredOrigin :: (Fractional r, Rectangle_ rectangle point, Point_ point 2 r) => rectangle -> Viewport r Source #

Create a viewport whose world-space is \([-1,1] \times [-1,1]\) whose origin is in the center of the screen (which is defined by the given input rectangle)

Low level constructors

mkViewport :: (Rectangle_ rectangle point, Point_ point 2 r, Fractional r) => rectangle -> Transformation 2 r -> Viewport r Source #

Creates a viewport from the given rectangle and the transformation. The transformation is applied with respect to the center of the viewport.

fromSize :: (Num r, Vector_ vector 2 r) => vector -> Viewport r Source #

Given a vector with widht w and height h, crates a viewport with focussing on [0,w] x [0,h]

flipY Source #

Arguments

:: (Num r, Vector_ vector 2 r) 
=> vector

the dimensions of the viewport

-> Viewport r 

Flips the y-coordinate so that the origin is in the bottom left.

Functions

toWorldIn :: (IsTransformable g, NumType g ~ r, Dimension g ~ 2, Fractional r) => Viewport r -> g -> g Source #

Convert some geometry in host coordinates to world coordinates in the viewport

toHostFrom :: (IsTransformable g, NumType g ~ r, Dimension g ~ 2, Num r) => Viewport r -> g -> g Source #

Convert some geometry in world coordinates to host coordinates according to the viewport

wrtCenter :: Fractional r => Viewport r -> Transformation 2 r -> Transformation 2 r Source #

make the transformation with respect to the center of the viewport

ZoomConfiging

data ZoomConfig r Source #

Data type representing possibilities for zooming in and out in a viewport.

Constructors

ZoomConfig (ClosedInterval r) r 

Instances

Instances details
Functor ZoomConfig Source # 
Instance details

Defined in HGeometry.Viewport

Methods

fmap :: (a -> b) -> ZoomConfig a -> ZoomConfig b Source #

(<$) :: a -> ZoomConfig b -> ZoomConfig a Source #

Foldable ZoomConfig Source # 
Instance details

Defined in HGeometry.Viewport

Methods

fold :: Monoid m => ZoomConfig m -> m Source #

foldMap :: Monoid m => (a -> m) -> ZoomConfig a -> m Source #

foldMap' :: Monoid m => (a -> m) -> ZoomConfig a -> m Source #

foldr :: (a -> b -> b) -> b -> ZoomConfig a -> b Source #

foldr' :: (a -> b -> b) -> b -> ZoomConfig a -> b Source #

foldl :: (b -> a -> b) -> b -> ZoomConfig a -> b Source #

foldl' :: (b -> a -> b) -> b -> ZoomConfig a -> b Source #

foldr1 :: (a -> a -> a) -> ZoomConfig a -> a Source #

foldl1 :: (a -> a -> a) -> ZoomConfig a -> a Source #

toList :: ZoomConfig a -> [a] Source #

null :: ZoomConfig a -> Bool Source #

length :: ZoomConfig a -> Int Source #

elem :: Eq a => a -> ZoomConfig a -> Bool Source #

maximum :: Ord a => ZoomConfig a -> a Source #

minimum :: Ord a => ZoomConfig a -> a Source #

sum :: Num a => ZoomConfig a -> a Source #

product :: Num a => ZoomConfig a -> a Source #

Traversable ZoomConfig Source # 
Instance details

Defined in HGeometry.Viewport

Methods

traverse :: Applicative f => (a -> f b) -> ZoomConfig a -> f (ZoomConfig b) Source #

sequenceA :: Applicative f => ZoomConfig (f a) -> f (ZoomConfig a) Source #

mapM :: Monad m => (a -> m b) -> ZoomConfig a -> m (ZoomConfig b) Source #

sequence :: Monad m => ZoomConfig (m a) -> m (ZoomConfig a) Source #

(Show (ClosedInterval r), Show r) => Show (ZoomConfig r) Source # 
Instance details

Defined in HGeometry.Viewport

(Eq (ClosedInterval r), Eq r) => Eq (ZoomConfig r) Source # 
Instance details

Defined in HGeometry.Viewport

range :: forall r f. Functor f => (ClosedInterval r -> f (ClosedInterval r)) -> ZoomConfig r -> f (ZoomConfig r) Source #

Lens to access the zoom-range

currentLevel :: Ord r => Lens' (ZoomConfig r) r Source #

Clamps the value to the right range on set