Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- pointOnTrajectory :: Sequential list => list Vec2 -> Double -> Vec2
- reassembleLines :: (Ord point, Foldable f) => (line -> (point, point)) -> f line -> [[point]]
- simplifyTrajectoryRdp :: Sequential vector => Double -> vector Vec2 -> Vector Vec2
- simplifyTrajectoryRdpBy :: Sequential vector => Double -> (a -> Vec2) -> vector a -> Vector a
- simplifyTrajectoryVW :: Sequential vector => Double -> vector Vec2 -> Vector Vec2
- simplifyTrajectoryVWBy :: (Ord a, Sequential vector) => Double -> (a -> Vec2) -> vector a -> Vector a
- simplifyTrajectoryRadial :: Sequential vector => Double -> vector Vec2 -> [Vec2]
- simplifyTrajectoryRadialBy :: Sequential vector => Double -> (a -> Vec2) -> vector a -> [a]
Various
pointOnTrajectory :: Sequential list => list Vec2 -> Double -> Vec2 Source #
Walk a certain Distance
on a trajectory defined by its points.
This caches the internal LUT when partially applied, so that the following will only compute it once for repeated lookups:
let goto =pointOnTrajectory
[…]
:: (Ord point, Foldable f) | |
=> (line -> (point, point)) | How to extract two neighbouring points from the data given |
-> f line | Collection of neighbouring points |
-> [[point]] | List of trajectories consisting of points |
Given a collection of lines that fit together back-to-back (as in ==
),
reassemble them to extract the underlying points in order. This works even for
collections of multiple cut-up trajectories, as long as they do not share
any points.
In a way, this can be seen as the inverse of pairing up points to line segments,
reassembleLines
(zipWith
Line
xs (tail
xs))==
xs
Unsafety warning: This algorithm wasn’t tested for cases when multiple trajectories share points. I have no idea what happens in that case, but certainly nothing useful.
Path simplifiers
simplifyTrajectoryRdp Source #
:: Sequential vector | |
=> Double | Discard points closer than \(\varepsilon\) to the connecting line of two points. Larger values yield simpler results. |
-> vector Vec2 | Trajectory |
-> Vector Vec2 | Simplified trajectory |
Simplify a path by dropping unnecessary points, using the the Ramer-Douglas-Peucker algorithm. The larger the tolerance distance, the simpler the result will be.
This is very useful in conjunction with bezierSmoothen
: first drop the
redundancies, then smoothen using Bezier curves again, to yield a result
visually similar to the original data, but with a much smaller data footprint
(SVGs can become huge!).
If your trajectory contains more than just the points you want to simplify on,
use simplifyTrajectoryRdpBy
.
simplifyTrajectoryRdpBy Source #
:: Sequential vector | |
=> Double | Discard points closer than \(\varepsilon\) to the connecting line of two points. Larger values yield simpler results. |
-> (a -> Vec2) | Extract the relevant |
-> vector a | Trajectory |
-> Vector a | Simplified trajectory |
simplifyTrajectoryRdp
, but allows specifying a function for how to extract the points
to base simplifying on from the input.
This is useful when your trajectory contains metadata, such as the velocity at each point.
:: Sequential vector | |
=> Double | Cutoff parameter. We remove points that span triangles smaller than this. Larger values yield simpler results. |
-> vector Vec2 | Trajectory |
-> Vector Vec2 | Simplified trajectory |
Simplify a path by dropping unnecessary points using the the Visvalingam-Whyatt algorithm. The larger the cutoff parameter, the simpler the result will be.
This is very useful in conjunction with bezierSmoothen
: first drop the
redundancies, then smoothen using Bezier curves again, to yield a result
visually similar to the original data, but with a much smaller data footprint
(SVGs can become huge!).
If your trajectory contains more than just the points you want to simplify on,
use simplifyTrajectoryVWBy
.
simplifyTrajectoryVWBy Source #
:: (Ord a, Sequential vector) | |
=> Double | Cutoff parameter. We remove points that span triangles smaller than this. Larger values yield simpler results. |
-> (a -> Vec2) | Extract the relevant |
-> vector a | Trajectory |
-> Vector a | Simplified trajectory |
simplifyTrajectoryVWBy
, but allows specifying a function for how to extract the points
to base simplifying on from the input.
This is useful when your trajectory contains metadata, such as the velocity at each point.
simplifyTrajectoryRadial Source #
:: Sequential vector | |
=> Double | Cutoff parameter: minimum distance to the next neighbour. Higher values yield fewer points. |
-> vector Vec2 | Trajectory |
-> [Vec2] | Simplified trajectory |
Simplify a path by dropping points too close to their neighbours. The larger the cutoff parameter, the simpler the result will be.
simplifyTrajectoryRadialBy Source #
:: Sequential vector | |
=> Double | Cutoff parameter: minimum distance to the next neighbour. Higher values yield fewer points. |
-> (a -> Vec2) | Extract the relevant |
-> vector a | Trajectory |
-> [a] | Simplified trajectory |
simplifyTrajectoryRadial
, but allows specifying a function for how to extract the points
to base simplifying on from the input.