diagrams-lib-1.1.0.3: Embedded domain-specific language for declarative graphics

Copyright(c) 2013 diagrams-lib team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellNone
LanguageHaskell2010

Diagrams.Trace

Contents

Description

"Traces", aka embedded raytracers, for finding points on the edge of a diagram. See Diagrams.Core.Trace for internal implementation details.

Synopsis

Types

data Trace v :: * -> *

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 and a direction vector), the trace computes a sorted list of signed distances from the base point to all intersections of the line with the boundary of the diagram.

Note that the outputs are not absolute distances, but multipliers relative to the input vector. That is, if the base point is p and direction vector is v, and one of the output scalars is s, then there is an intersection at the point p .+^ (s *^ v).

Instances

Action Name (Trace v) 
Show (Trace v) 
Ord (Scalar v) => Semigroup (Trace v) 
Ord (Scalar v) => Monoid (Trace v) 
(Ord (Scalar v), VectorSpace v) => Traced (Trace v) 
HasLinearMap v => Transformable (Trace v) 
VectorSpace v => HasOrigin (Trace v) 
Wrapped (Trace v) 
(InnerSpace v, OrderedField (Scalar v)) => Alignable (Trace v) 
Rewrapped (Trace v) (Trace v') 
type V (Trace v) = v 
type Unwrapped (Trace v) = Point v -> v -> SortedList (Scalar v) 

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

Traced abstracts over things which have a trace.

Minimal complete definition

getTrace

Instances

Traced b => Traced [b] 
Traced b => Traced (Set b) 
(Ord (Scalar v), VectorSpace v) => Traced (Trace v) 
Traced t => Traced (TransInv t) 
(Ord (Scalar v), VectorSpace v) => Traced (Point v)

The trace of a single point is the empty trace, i.e. the one which returns no intersection points for every query. Arguably it should return a single finite distance for vectors aimed directly at the given point, but due to floating-point inaccuracy this is problematic. Note that the envelope for a single point is not the empty envelope (see Diagrams.Core.Envelope).

Traced a => Traced (Located a)

The trace of a Located a is the trace of the a, translated to the location.

Traced (FixedSegment R2) 
Traced (Trail R2) 
Traced (Path R2) 
(Traced a, Traced b, (~) * (V a) (V b)) => Traced (a, b) 
Traced b => Traced (Map k b) 
Traced (Segment Closed R2) 
(HasLinearMap v, VectorSpace v, Ord (Scalar v), InnerSpace v, Semigroup m, Fractional (Scalar v), Floating (Scalar v)) => Traced (QDiagram b v m) 
(OrderedField (Scalar v), HasLinearMap v, InnerSpace v, Semigroup m) => Traced (Subdiagram b v m) 

Diagram traces

trace :: (InnerSpace v, HasLinearMap v, OrderedField (Scalar v), Semigroup m) => Lens' (QDiagram b v m) (Trace v)

Get the trace of a diagram.

setTrace :: (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Semigroup m) => Trace v -> QDiagram b v m -> QDiagram b v m

Replace the trace of a diagram.

withTrace :: (HasLinearMap (V a), Traced a, OrderedField (Scalar (V a)), InnerSpace (V a), Monoid' m) => a -> QDiagram b (V a) m -> QDiagram b (V a) m Source

Use the trace from some object as the trace for a diagram, in place of the diagram's default trace.

Querying traces

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

Compute the vector from the given point p to the "smallest" boundary intersection along the given vector v. The "smallest" boundary intersection is defined as the one given by p .+^ (s *^ v) for the smallest (most negative) value of s. Return Nothing if there is no intersection. See also traceP.

See also rayTraceV which uses the smallest positive intersection, which is often more intuitive behavior.

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

Compute the "smallest" boundary point along the line determined by the given point p and vector v. The "smallest" boundary point is defined as the one given by p .+^ (s *^ v) for the smallest (most negative) value of s. Return Nothing if there is no such boundary point. See also traceV.

See also rayTraceP which uses the smallest positive intersection, which is often more intuitive behavior.

maxTraceV :: Traced a => Point (V a) -> V a -> a -> Maybe (V a)

Like traceV, but computes a vector to the "largest" boundary point instead of the smallest. (Note, however, the "largest" boundary point may still be in the opposite direction from the given vector, if all the boundary points are, as in the third example shown below.)

maxTraceP :: Traced a => Point (V a) -> V a -> a -> Maybe (Point (V a))

Like traceP, but computes the "largest" boundary point instead of the smallest. (Note, however, the "largest" boundary point may still be in the opposite direction from the given vector, if all the boundary points are.)

Subdiagram traces

boundaryFrom :: (HasLinearMap v, OrderedField (Scalar v), InnerSpace v, Semigroup m) => Subdiagram b v m -> v -> Point v Source

Compute the furthest point on the boundary of a subdiagram, beginning from the location (local origin) of the subdiagram and moving in the direction of the given vector. If there is no such point, the origin is returned; see also boundaryFromMay.

boundaryFromMay :: (HasLinearMap v, OrderedField (Scalar v), Semigroup m, InnerSpace v) => Subdiagram b v m -> v -> Maybe (Point v) Source

Compute the furthest point on the boundary of a subdiagram, beginning from the location (local origin) of the subdiagram and moving in the direction of the given vector, or Nothing if there is no such point.