chalkboard-0.2: Combinators for building and processing 2D images.

Portability ghc unstable Andy Gill

Graphics.Chalkboard.Utils

Description

This module contains some general utilties.

Synopsis

# Utilties for `R`.

innerSteps :: Int -> [R]Source

innerSteps takes n even steps from 0 .. 1, by not actually touching 0 or 1. The first and last step are 1/2 the size of the others, so that repeated innerSteps can be tiled neatly.

outerSteps :: Int -> [R]Source

outerSteps takes n even steps from 0 .. 1, starting with 0, and ending with 1, returning n+1 elements.

fracPart :: R -> RSource

Extract the fractional part of an `R`.

# Pointwise operators.

Covert a Bool (mask point) into a unit interval.

sample a UI, giving a point of a mask.

withMask :: a -> Bool -> Maybe aSource

Use a mask to create a Just value, or Nothing.

withDefault :: a -> Maybe a -> aSource

With a default if you do not have a Just.

choose :: a -> a -> Bool -> aSource

`choose` between two values.

# Point Utilties.

insideRegion :: (Point, Point) -> Point -> BoolSource

is a `Point` inside a region?

is a `Point` inside a circle, where the first two arguments are the center of the circle, and the radius.

What is the `distance` between two points in R2? This is optimised for the normal form `distance p1 p2 <= v`, which avoids using `sqrt`.

intervalOnLine :: (Point, Point) -> Point -> RSource

`intervalOnLine` find the place on a line (between 0 and 1) that is closest to the given point.

circleOfDots :: Int -> [Point]Source

circleOfDots generates a set of points between (-1..1,-1..1), inside a circle.