Skip to main content

estimate_path_cost

Function estimate_path_cost 

Source
pub(crate) fn estimate_path_cost(
    path: impl IntoIterator<Item = PathSeg>,
    transform: Affine,
    is_stroke: bool,
) -> f32
Expand description

Try to estimate an (admittedly somewhat abstract) “path cost”.

The main point here is that when sending paths to a thread to convert them into sparse strip representation, we might want to batch them. This is especially the case for small, line-only geometries, where handling each path separately would lead to a huge overhead.

Because of this, before rendering a path, we try to estimate a very rough cost based on the following attributes that (usually) have an impact on rendering times:

  • Number of line segments (more line segments -> more work during strip rendering).
  • Number of curve segments (same as line segments, plus we need to flatten them first).
  • Path length (if the path is longer, the covered area is likely to also be larger). However, the path length usually grows much faster than the render time, so we only apply a very small fractional value.
  • Strokes (if we are stroking a path, there is even more overhead for stroke expansion before doing flattening and strip rendering).