dashPath function

Path dashPath(
  1. Path path,
  2. List<double> dash
)

给定一个Path和dash数据返回一个新的Path

Implementation

Path dashPath(Path path, List<double> dash) {
  if (dash.isEmpty) {
    return path;
  }
  double dashLength = dash[0];
  double dashGapLength = dashLength >= 2 ? dash[1] : dash[0];
  DashedPathProperties properties = DashedPathProperties(
    path: Path(),
    dashLength: dashLength,
    dashGapLength: dashGapLength,
  );
  final metricsIterator = path.computeMetrics().iterator;
  while (metricsIterator.moveNext()) {
    final metric = metricsIterator.current;
    properties.extractedPathLength = 0.0;
    while (properties.extractedPathLength < metric.length) {
      if (properties.addDashNext) {
        properties.addDash(metric, dashLength);
      } else {
        properties.addDashGap(metric, dashGapLength);
      }
    }
  }
  return properties.path;
}