diagrams-lib-1.4.6.2: Embedded domain-specific language for declarative graphics
Copyright(c) 2013 diagrams-lib team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Diagrams.Trace

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 :: Type -> Type) n #

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

Instances details
Ord n => Monoid (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

Methods

mempty :: Trace v n #

mappend :: Trace v n -> Trace v n -> Trace v n #

mconcat :: [Trace v n] -> Trace v n #

Ord n => Semigroup (Trace v n)

Traces form a semigroup with pointwise minimum as composition. Hence, if t1 is the trace for diagram d1, and e2 is the trace for d2, then e1 `mappend` e2 is the trace for d1 `atop` d2.

Instance details

Defined in Diagrams.Core.Trace

Methods

(<>) :: Trace v n -> Trace v n -> Trace v n #

sconcat :: NonEmpty (Trace v n) -> Trace v n #

stimes :: Integral b => b -> Trace v n -> Trace v n #

Show (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

Methods

showsPrec :: Int -> Trace v n -> ShowS #

show :: Trace v n -> String #

showList :: [Trace v n] -> ShowS #

(Additive v, Num n) => HasOrigin (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

Methods

moveOriginTo :: Point (V (Trace v n)) (N (Trace v n)) -> Trace v n -> Trace v n #

(Additive v, Ord n) => Traced (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: Trace v n -> Trace (V (Trace v n)) (N (Trace v n)) #

(Additive v, Num n) => Transformable (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

Methods

transform :: Transformation (V (Trace v n)) (N (Trace v n)) -> Trace v n -> Trace v n #

(Metric v, OrderedField n) => Alignable (Trace v n) Source # 
Instance details

Defined in Diagrams.Align

Methods

alignBy' :: (InSpace v0 n0 (Trace v n), Fractional n0, HasOrigin (Trace v n)) => (v0 n0 -> Trace v n -> Point v0 n0) -> v0 n0 -> n0 -> Trace v n -> Trace v n Source #

defaultBoundary :: (V (Trace v n) ~ v0, N (Trace v n) ~ n0) => v0 n0 -> Trace v n -> Point v0 n0 Source #

alignBy :: (InSpace v0 n0 (Trace v n), Fractional n0, HasOrigin (Trace v n)) => v0 n0 -> n0 -> Trace v n -> Trace v n Source #

Wrapped (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

Associated Types

type Unwrapped (Trace v n) #

Methods

_Wrapped' :: Iso' (Trace v n) (Unwrapped (Trace v n)) #

Rewrapped (Trace v n) (Trace v' n') 
Instance details

Defined in Diagrams.Core.Trace

type N (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

type N (Trace v n) = n
type V (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

type V (Trace v n) = v
type Unwrapped (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

type Unwrapped (Trace v n) = Point v n -> v n -> SortedList n

class (Additive (V a), Ord (N a)) => Traced a #

Traced abstracts over things which have a trace.

Minimal complete definition

getTrace

Instances

Instances details
Traced b => Traced (Set b) 
Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: Set b -> Trace (V (Set b)) (N (Set b)) #

Traced t => Traced (TransInv t) 
Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: TransInv t -> Trace (V (TransInv t)) (N (TransInv t)) #

(Traced a, Num (N a)) => Traced (Located a) Source #

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

Instance details

Defined in Diagrams.Located

Methods

getTrace :: Located a -> Trace (V (Located a)) (N (Located a)) #

(Fractional n, Ord n) => Traced (Box n) Source # 
Instance details

Defined in Diagrams.ThreeD.Shapes

Methods

getTrace :: Box n -> Trace (V (Box n)) (N (Box n)) #

(RealFloat n, Ord n) => Traced (CSG n) Source # 
Instance details

Defined in Diagrams.ThreeD.Shapes

Methods

getTrace :: CSG n -> Trace (V (CSG n)) (N (CSG n)) #

OrderedField n => Traced (Ellipsoid n) Source # 
Instance details

Defined in Diagrams.ThreeD.Shapes

Methods

getTrace :: Ellipsoid n -> Trace (V (Ellipsoid n)) (N (Ellipsoid n)) #

(RealFloat n, Ord n) => Traced (Frustum n) Source # 
Instance details

Defined in Diagrams.ThreeD.Shapes

Methods

getTrace :: Frustum n -> Trace (V (Frustum n)) (N (Frustum n)) #

Traced b => Traced [b] 
Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: [b] -> Trace (V [b]) (N [b]) #

Traced b => Traced (Map k b) 
Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: Map k b -> Trace (V (Map k b)) (N (Map k b)) #

(Additive v, Ord n) => Traced (Trace v n) 
Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: Trace v n -> Trace (V (Trace v n)) (N (Trace v n)) #

RealFloat n => Traced (BoundingBox V2 n) Source # 
Instance details

Defined in Diagrams.BoundingBox

Methods

getTrace :: BoundingBox V2 n -> Trace (V (BoundingBox V2 n)) (N (BoundingBox V2 n)) #

TypeableFloat n => Traced (BoundingBox V3 n) Source # 
Instance details

Defined in Diagrams.BoundingBox

Methods

getTrace :: BoundingBox V3 n -> Trace (V (BoundingBox V3 n)) (N (BoundingBox V3 n)) #

RealFloat n => Traced (Path V2 n) Source # 
Instance details

Defined in Diagrams.TwoD.Path

Methods

getTrace :: Path V2 n -> Trace (V (Path V2 n)) (N (Path V2 n)) #

OrderedField n => Traced (FixedSegment V2 n) Source # 
Instance details

Defined in Diagrams.TwoD.Segment

RealFloat n => Traced (Trail V2 n) Source # 
Instance details

Defined in Diagrams.TwoD.Path

Methods

getTrace :: Trail V2 n -> Trace (V (Trail V2 n)) (N (Trail V2 n)) #

(Additive v, Ord n) => Traced (Point v n)

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).

Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: Point v n -> Trace (V (Point v n)) (N (Point v n)) #

(Traced a, Traced b, SameSpace a b) => Traced (a, b) 
Instance details

Defined in Diagrams.Core.Trace

Methods

getTrace :: (a, b) -> Trace (V (a, b)) (N (a, b)) #

OrderedField n => Traced (Segment Closed V2 n) Source # 
Instance details

Defined in Diagrams.TwoD.Segment

(Metric v, OrderedField n, Semigroup m) => Traced (QDiagram b v n m) 
Instance details

Defined in Diagrams.Core.Types

Methods

getTrace :: QDiagram b v n m -> Trace (V (QDiagram b v n m)) (N (QDiagram b v n m)) #

(OrderedField n, Metric v, Semigroup m) => Traced (Subdiagram b v n m) 
Instance details

Defined in Diagrams.Core.Types

Methods

getTrace :: Subdiagram b v n m -> Trace (V (Subdiagram b v n m)) (N (Subdiagram b v n m)) #

Diagram traces

trace :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Lens' (QDiagram b v n m) (Trace v n) #

Lens onto the Trace of a QDiagram.

setTrace :: forall b (v :: Type -> Type) n m. (OrderedField n, Metric v, Semigroup m) => Trace v n -> QDiagram b v n m -> QDiagram b v n m #

Replace the trace of a diagram.

withTrace :: (InSpace v n a, Metric v, OrderedField n, Monoid' m, Traced a) => a -> QDiagram b v n m -> QDiagram b v n 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 :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (V a n) #

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 :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n) #

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 :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (V a n) #

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 :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n) #

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 :: (OrderedField n, Metric v, Semigroup m) => Subdiagram b v n m -> v n -> Point v n 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 :: (Metric v, OrderedField n, Semigroup m) => Subdiagram b v n m -> v n -> Maybe (Point v n) 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.