getDashedPath method
Implementation
Path getDashedPath({
required math.Point<double> a,
required math.Point<double> b,
required num gap,
}) {
final size = Size(b.x - a.x, b.y - a.y);
final path = Path();
path.moveTo(a.x, a.y);
var shouldDraw = true;
var currentPoint = math.Point<double>(a.x, a.y);
final num radians = math.atan(size.height / size.width);
final num dx = math.cos(radians) * gap < 0
? math.cos(radians) * gap * -1
: math.cos(radians) * gap;
final num dy = math.sin(radians) * gap < 0
? math.sin(radians) * gap * -1
: math.sin(radians) * gap;
while (currentPoint.x <= b.x && currentPoint.y <= b.y) {
shouldDraw
? path.lineTo(currentPoint.x, currentPoint.y)
: path.moveTo(currentPoint.x, currentPoint.y);
shouldDraw = !shouldDraw;
currentPoint = math.Point<double>(
currentPoint.x + dx,
currentPoint.y + dy,
);
}
return path;
}