Maintainer | diagrams-discuss@googlegroups.com |
---|---|

Safe Haskell | None |

Diagrams defines the core library of primitives forming the basis of an embedded domain-specific language for describing and rendering diagrams.

The `Trace`

module defines a data type and type class for
"traces", aka functional boundaries, essentially corresponding to
embedding a raytracer with each diagram.

- newtype Trace v = Trace {}
- inTrace :: ((Point v -> v -> PosInf (Scalar v)) -> Point v -> v -> PosInf (Scalar v)) -> Trace v -> Trace v
- mkTrace :: (Point v -> v -> PosInf (Scalar v)) -> Trace v
- class (Ord (Scalar (V a)), VectorSpace (V a)) => Traced a where
- traceV :: Traced a => Point (V a) -> V a -> a -> Maybe (V a)
- traceP :: Traced a => Point (V a) -> V a -> a -> Maybe (Point (V a))
- maxTraceV :: Traced a => Point (V a) -> V a -> a -> Maybe (V a)
- maxTraceP :: Traced a => Point (V a) -> V a -> a -> Maybe (Point (V a))

# Traces

Every diagram comes equipped with a *trace*. Intuitively, the trace for a diagram is like a raytracer: given a line (represented as a base point + direction), the trace computes the distance from the base point along the line to the first intersection with the diagram. The distance can be negative if the intersection is in the opposite direction from the base point, or infinite if the ray never intersects the diagram. Note: to obtain the distance to the *furthest* intersection instead of the *closest*, just negate the direction vector and then negate the result.

Note that the output should actually be interpreted not as an
absolute distance, but as a multiplier relative to the input
vector. That is, if the input vector is `v`

and the returned
scalar is `s`

, the distance from the base point to the
intersection is given by `s *^ magnitude v`

.

Show (Trace v) | |

Ord (Scalar v) => Monoid (Trace v) | |

Ord (Scalar v) => Semigroup (Trace v) | |

(VectorSpace (V (Trace v)), VectorSpace v) => HasOrigin (Trace v) | |

(HasLinearMap (V (Trace v)), HasLinearMap v) => Transformable (Trace v) | |

(Ord (Scalar (V (Trace v))), VectorSpace (V (Trace v)), Ord (Scalar v), VectorSpace v) => Traced (Trace v) | |

Newtype (QDiagram b v m) (DUALTree (DownAnnots v) (UpAnnots b v m) () (Prim b v)) |

inTrace :: ((Point v -> v -> PosInf (Scalar v)) -> Point v -> v -> PosInf (Scalar v)) -> Trace v -> Trace vSource

# Traced class

class (Ord (Scalar (V a)), VectorSpace (V a)) => Traced a whereSource

`Traced`

abstracts over things which have a trace.

(Ord (Scalar (V [b])), VectorSpace (V [b]), Traced b) => Traced [b] | |

(Ord (Scalar (V (Set b))), VectorSpace (V (Set b)), Traced b) => Traced (Set b) | |

(Ord (Scalar (V (Point v))), VectorSpace (V (Point v)), Ord (Scalar v), VectorSpace v) => Traced (Point v) | The trace of a single point is the empty trace, |

(Ord (Scalar (V (Trace v))), VectorSpace (V (Trace v)), Ord (Scalar v), VectorSpace v) => Traced (Trace v) | |

(Ord (Scalar (V (a, b))), VectorSpace (V (a, b)), Traced a, Traced b, ~ * (V a) (V b)) => Traced (a, b) | |

(Ord (Scalar (V (Map k b))), VectorSpace (V (Map k b)), Traced b) => Traced (Map k b) | |

(Ord (Scalar (V (Subdiagram b v m))), VectorSpace (V (Subdiagram b v m)), Ord (Scalar v), VectorSpace v, HasLinearMap v) => Traced (Subdiagram b v m) | |

(Ord (Scalar (V (QDiagram b v m))), VectorSpace (V (QDiagram b v m)), HasLinearMap v, VectorSpace v, Ord (Scalar v)) => Traced (QDiagram b v m) |

# Computing with traces

traceV :: Traced a => Point (V a) -> V a -> a -> Maybe (V a)Source

Compute the vector from the given point to the boundary of the
given object in the given direction, or `Nothing`

if there is no
intersection.

traceP :: Traced a => Point (V a) -> V a -> a -> Maybe (Point (V a))Source

Given a base point and direction, compute the closest point on
the boundary of the given object, or `Nothing`

if there is no
intersection in the given direction.