| Copyright | (C) Frank Staals |
|---|---|
| License | see the LICENSE file |
| Maintainer | Frank Staals |
| Safe Haskell | None |
| Language | GHC2024 |
HGeometry.Viewport
Description
A Geometric viewport; i.e. some way of "viewing" only one particular rectangular region of a larger 2d space.
Synopsis
- data Viewport r = Viewport (Rectangle (Point 2 r)) (Transformation 2 r)
- viewPort :: forall r f. Functor f => (Rectangle (Point 2 r) -> f (Rectangle (Point 2 r))) -> Viewport r -> f (Viewport r)
- worldToHost :: forall r f. Functor f => (Transformation 2 r -> f (Transformation 2 r)) -> Viewport r -> f (Viewport r)
- hostToWorld :: Fractional r => Getter (Viewport r) (Transformation 2 r)
- centeredOrigin :: (Fractional r, Rectangle_ rectangle point, Point_ point 2 r) => rectangle -> Viewport r
- alignedOrigin :: Num r => Rectangle (Point 2 r) -> Viewport r
- graphicsOrigin :: Num r => Rectangle (Point 2 r) -> Viewport r
- normalizedCenteredOrigin :: (Fractional r, Rectangle_ rectangle point, Point_ point 2 r) => rectangle -> Viewport r
- mkViewport :: (Rectangle_ rectangle point, Point_ point 2 r, Fractional r) => rectangle -> Transformation 2 r -> Viewport r
- fromSize :: (Num r, Vector_ vector 2 r) => vector -> Viewport r
- flipY :: (Num r, Vector_ vector 2 r) => vector -> Viewport r
- toWorldIn :: (IsTransformable g, NumType g ~ r, Dimension g ~ 2, Fractional r) => Viewport r -> g -> g
- toHostFrom :: (IsTransformable g, NumType g ~ r, Dimension g ~ 2, Num r) => Viewport r -> g -> g
- wrtCenter :: Fractional r => Viewport r -> Transformation 2 r -> Transformation 2 r
- data ZoomConfig r = ZoomConfig (ClosedInterval r) r
- range :: forall r f. Functor f => (ClosedInterval r -> f (ClosedInterval r)) -> ZoomConfig r -> f (ZoomConfig r)
- currentLevel :: Ord r => Lens' (ZoomConfig r) r
Documentation
Represents a viewport ; i.e. a rectangle through which we view the world.
Constructors
| Viewport (Rectangle (Point 2 r)) (Transformation 2 r) |
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]
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
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