- type Flt = Double
- infinity :: Flt
- deg :: Flt -> Flt
- rad :: Flt -> Flt
- rot :: Flt -> Flt
- dcos :: Flt -> Flt
- clamp :: Flt -> Flt -> Flt -> Flt
- fmin :: Flt -> Flt -> Flt
- fmax :: Flt -> Flt -> Flt
- fmin3 :: Flt -> Flt -> Flt -> Flt
- fmax3 :: Flt -> Flt -> Flt -> Flt
- fmin4 :: Flt -> Flt -> Flt -> Flt -> Flt
- fmax4 :: Flt -> Flt -> Flt -> Flt -> Flt
- fabs :: Flt -> Flt
- iabs :: Int -> Int
- about_equal :: Flt -> Flt -> Bool
- data Vec = Vec !Flt !Flt !Flt
- data Ray = Ray {}
- vec :: Flt -> Flt -> Flt -> Vec
- vzero :: Vec
- vunit :: Vec
- vx :: Vec
- vy :: Vec
- vz :: Vec
- nvx :: Vec
- nvy :: Vec
- nvz :: Vec
- x :: Vec -> Flt
- y :: Vec -> Flt
- z :: Vec -> Flt
- va :: Vec -> Int -> Flt
- vset :: Vec -> Int -> Flt -> Vec
- vdot :: Vec -> Vec -> Flt
- vcross :: Vec -> Vec -> Vec
- vmap :: (Flt -> Flt) -> Vec -> Vec
- vmap2 :: (Flt -> Flt -> Flt) -> Vec -> Vec -> Vec
- vinvert :: Vec -> Vec
- vlensqr :: Vec -> Flt
- vlen :: Vec -> Flt
- vadd :: Vec -> Vec -> Vec
- vadd3 :: Vec -> Vec -> Vec -> Vec
- vsub :: Vec -> Vec -> Vec
- vmul :: Vec -> Vec -> Vec
- vinc :: Vec -> Flt -> Vec
- vdec :: Vec -> Flt -> Vec
- vmax :: Vec -> Vec -> Vec
- vmin :: Vec -> Vec -> Vec
- vmaxaxis :: Vec -> Int
- vscale :: Vec -> Flt -> Vec
- vscaleadd :: Vec -> Vec -> Flt -> Vec
- vnudge :: Vec -> Vec
- vnorm :: Vec -> Vec
- assert_norm :: Vec -> Vec
- bisect :: Vec -> Vec -> Vec
- vdist :: Vec -> Vec -> Flt
- reflect :: Vec -> Vec -> Vec
- vrcp :: Vec -> Vec
- veq :: Vec -> Vec -> Bool
- veqsign :: Vec -> Vec -> Bool
- ray_move :: Ray -> Flt -> Ray
- orth :: Vec -> (Vec, Vec)
- plane_int :: Ray -> Vec -> Vec -> Vec
- plane_int_dist :: Ray -> Vec -> Vec -> Flt
- data Matrix = Matrix !Flt !Flt !Flt !Flt !Flt !Flt !Flt !Flt !Flt !Flt !Flt !Flt
- data Xfm = Xfm Matrix Matrix
- ident_matrix :: Matrix
- ident_xfm :: Xfm
- mat_mult :: Matrix -> Matrix -> Matrix
- xfm_mult :: Xfm -> Xfm -> Xfm
- compose :: [Xfm] -> Xfm
- check_xfm :: Xfm -> Xfm
- vrotate :: Vec -> Ray -> Flt -> Vec
- xfm_point :: Xfm -> Vec -> Vec
- invxfm_point :: Xfm -> Vec -> Vec
- xfm_vec :: Xfm -> Vec -> Vec
- invxfm_vec :: Xfm -> Vec -> Vec
- invxfm_norm :: Xfm -> Vec -> Vec
- xfm_ray :: Xfm -> Ray -> Ray
- invxfm_ray :: Xfm -> Ray -> Ray
- translate :: Vec -> Xfm
- scale :: Vec -> Xfm
- rotate :: Vec -> Flt -> Xfm
- xyz_to_uvw :: Vec -> Vec -> Vec -> Xfm
- uvw_to_xyz :: Vec -> Vec -> Vec -> Xfm
- sas2s :: Flt -> Flt -> Flt -> Flt
- data Bbox = Bbox {}
- data Interval = Interval !Flt !Flt
- bbjoin :: Bbox -> Bbox -> Bbox
- bboverlap :: Bbox -> Bbox -> Bbox
- bbinside :: Bbox -> Vec -> Bool
- bbsplit :: Bbox -> Int -> Flt -> (Bbox, Bbox)
- bbpts :: [Vec] -> Bbox
- bbsa :: Bbox -> Flt
- bbvol :: Bbox -> Flt
- empty_bbox :: Bbox
- everything_bbox :: Bbox
- bbclip :: Ray -> Bbox -> Interval

# Documentation

Performance is pretty similar with Floats or Doubles. Todo: make separate Float and Double instances of this library.

fmin :: Flt -> Flt -> FltSource

Tuning parameter.

Non-polymorphic fmin; this speeds things up in ocaml, not sure about haskell.

about_equal :: Flt -> Flt -> BoolSource

Force user to use fabs or iabs, for performance reasons. Not sure if this really helps, though.

Approximate equality for Flt. True if a and b are almost equal. The (abs $ a-b) test doesn't work if a and b are large.

A Ray is made up of an origin and direction Vec.

Access the Vec as if it were an array indexed from 0..2. Note: this actually accounts for a noticeable amount of cpu time in the Glome ray tracer.

vset :: Vec -> Int -> Flt -> VecSource

Create a new Vec with the Nth field overwritten by new value. I could have used record update syntax.

vdot :: Vec -> Vec -> FltSource

Dot product of 2 vectors. We use this all the time. Dot product of 2 normal vectors is the cosine of the angle between them.

vcross :: Vec -> Vec -> VecSource

Cross product of 2 vectors. Produces a vector perpendicular to the given vectors. We use this for things like making the forward, up, and right camera vectors orthogonal. If the input vectors are normalized, the output vector will be as well.

vmap2 :: (Flt -> Flt -> Flt) -> Vec -> Vec -> VecSource

Apply a binary Flt operator to pairs of fields from 2 Vecs.

vinc :: Vec -> Flt -> VecSource

Add a value to all the fields of a Vec. Useful, for instance, to get one corner of the bounding box around a sphere.

vscaleadd :: Vec -> Vec -> Flt -> VecSource

Take the first Vec, and add to it the second Vec scaled by some amount. This is used quite a lot in Glome.

Normalize a vector. Division is expensive, so we compute the reciprocol of the length and multiply by that. The sqrt is also expensive.

assert_norm :: Vec -> VecSource

Throw an exception if a vector hasn't been normalized.

bisect :: Vec -> Vec -> VecSource

Get the victor bisecting two other vectors (which ought to be the same length).

veqsign :: Vec -> Vec -> BoolSource

Test Vecs for matching sign on all fields. Returns false if any value is zero. Used by packet tracing.

3x4 Transformation matrix. These are described in most graphics texts.

A transformation. Inverting a matrix is expensive, so we keep a forward transformation matrix and a reverse transformation matrix. Note: This can be made a little faster if the matricies are non-strict.

Identity matrix. Transforming a vector by this matrix does nothing.

mat_mult :: Matrix -> Matrix -> MatrixSource

Multiply two matricies. This is unrolled for efficiency, and it's also a little bit easier (in my opinion) to see what's going on.

xfm_mult :: Xfm -> Xfm -> XfmSource

Multiply two tranformations. This just multiplies the forward and reverse transformations.

There is a seemingly-magical property of transformation matricies, that we can combine the effects of any number of transformations into a single transformation just by multiplying them together in reverse order. For instance, we could move a point, then rotate it about the origin by some angle around some vector, then move it again, and this can all be done by a single transformation. This function combines transformations in this way, though it reverses the list first so the transformations take effect in their expected order.

Make sure a transformation is valid. Multipy the forward and reverse matrix and verify that the result is the identity matrix.

invxfm_point :: Xfm -> Vec -> VecSource

Inverse transform a point.

invxfm_vec :: Xfm -> Vec -> VecSource

Inverse transform a vector.

invxfm_norm :: Xfm -> Vec -> VecSource

Inverse transform a normal. This one is tricky: we need to transform by the inverse transpose.

invxfm_ray :: Xfm -> Ray -> RaySource

Inverse transform a Ray.

Basic transforms: stretch along the three axes, by the amount in the given vector. (If x==y==z, then it's uniform scaling.)

xyz_to_uvw :: Vec -> Vec -> Vec -> XfmSource

Basic transforms: Convert coordinate system from canonical xyz coordinates to uvw coordinates.

uvw_to_xyz :: Vec -> Vec -> Vec -> XfmSource

Basic transforms: Convert from uvw coordinates back to normal xyz coordinates.

sas2s :: Flt -> Flt -> Flt -> FltSource

Given a side, angle, and side of a triangle, produce the length of the opposite side.

Axis-aligned Bounding Box (AABB), defined by opposite corners. P1 is the min values, p2 has the max values.

A near-far pair of distances. Basically just a tuple.

bbsplit :: Bbox -> Int -> Flt -> (Bbox, Bbox)Source

Split a bounding box into two, given an axis and offset. Throw exception if the offset isn't inside the bounding box.

Surface area of a bounding box. Useful for cost heuristics when attempting to build optimal bounding box heirarchies. Undefined for degenerate bounding boxes.

Degenerate bounding box that contains an empty volume.

Infinite bounding box.