gloss-1.7.8.3: Painless 2D vector graphics, animations and simulations.

Safe Haskell | Safe-Inferred

Graphics.Gloss.Data.Extent

Description

Represents an integral rectangular area of the 2D plane. Using `Int`s (instead of `Float`s) for the bounds means we can safely compare extents for equality.

Synopsis

- data Extent
- type Coord = (Int, Int)
- makeExtent :: Int -> Int -> Int -> Int -> Extent
- takeExtent :: Extent -> (Int, Int, Int, Int)
- squareExtent :: Int -> Extent
- sizeOfExtent :: Extent -> (Int, Int)
- isUnitExtent :: Extent -> Bool
- coordInExtent :: Extent -> Coord -> Bool
- pointInExtent :: Extent -> Point -> Bool
- centerCoordOfExtent :: Extent -> (Int, Int)
- cutQuadOfExtent :: Quad -> Extent -> Extent
- quadOfCoord :: Extent -> Coord -> Maybe Quad
- pathToCoord :: Extent -> Coord -> Maybe [Quad]
- intersectSegExtent :: Point -> Point -> Extent -> Maybe Point
- touchesSegExtent :: Point -> Point -> Extent -> Bool

# Documentation

data Extent Source

A rectangular area of the 2D plane. We keep the type abstract to ensure that invalid extents cannot be constructed.

Instances

Eq Extent |
Show Extent |

type Coord = (Int, Int)Source

An integral coordinate.

makeExtent Source

Arguments

:: Int | y max (north)
-> Int | y min (south)
-> Int | x max (east)
-> Int | x min (west)
-> Extent |

Construct an extent. The north value must be > south, and east > west, else `error`.

takeExtent :: Extent -> (Int, Int, Int, Int)Source

Take the NSEW components of an extent.

squareExtent :: Int -> Extent Source

A square extent of a given size.

sizeOfExtent :: Extent -> (Int, Int)Source

Get the width and height of an extent.

isUnitExtent :: Extent -> Bool Source

Check if an extent is a square with a width and height of 1.

coordInExtent :: Extent -> Coord -> Bool Source

Check whether a coordinate lies inside an extent.

pointInExtent :: Extent -> Point -> Bool Source

Check whether a point lies inside an extent.

centerCoordOfExtent :: Extent -> (Int, Int)Source

Get the coordinate that lies at the center of an extent.

cutQuadOfExtent :: Quad -> Extent -> Extent Source

Cut one quadrant out of an extent.

quadOfCoord :: Extent -> Coord -> Maybe Quad Source

Get the quadrant that this coordinate lies in, if any.

pathToCoord :: Extent -> Coord -> Maybe [Quad]Source

Constuct a path to a particular coordinate in an extent.

intersectSegExtent :: Point -> Point -> Extent -> Maybe Point Source

If a line segment (P1-P2) intersects the outer edge of an extent then return the intersection point, that is closest to P1, if any. If P1 is inside the extent then `Nothing`.

                       P2
                      /
                ----/-
                | /  |
                +    |
               /------
             /
            P1

touchesSegExtent :: Point -> Point -> Extent -> Bool Source

Check whether a line segment's endpoints are inside an extent, or if it intersects with the boundary.