fill method

  1. @override
OpSet fill(
  1. List<PointD> points
)
override

Implementation

@override
OpSet fill(List<PointD> points) {
  final List<Op> ops = [];
  final List<Line> lines = buildFillLines(points, _config);

  for (final Line line in lines) {
    final double length = line.length;
    final double dashSize =
        _config.dashOffset < 1 ? _config.hachureGap : _config.dashOffset;
    final double gapSize =
        _config.dashGap < 1 ? _config.hachureGap : _config.dashGap;

    double distance = 0;
    bool isDash = true;

    while (distance < length) {
      final double segmentLength = isDash ? dashSize : gapSize;
      final double endDistance = min(distance + segmentLength, length);

      if (isDash && endDistance > distance) {
        final double ratio = distance / length;
        final double endRatio = endDistance / length;

        final PointD start = PointD(
          line.source.x + (line.target.x - line.source.x) * ratio,
          line.source.y + (line.target.y - line.source.y) * ratio,
        );

        if (distance == 0) {
          // Draw a dot at the start
          ops
            ..add(Op.move(start))
            ..add(Op.lineTo(start));
        } else {
          // Draw a dash
          final PointD end = PointD(
            line.source.x + (line.target.x - line.source.x) * endRatio,
            line.source.y + (line.target.y - line.source.y) * endRatio,
          );
          ops
            ..add(Op.move(start))
            ..add(Op.lineTo(end));
        }
      }

      distance = endDistance;
      isDash = !isDash;
    }
  }

  return OpSet(type: OpSetType.fillSketch, ops: ops);
}