generatePath method
Path
generatePath(
{ - required Rect rect,
})
Implementation
Path generatePath({required Rect rect}) {
final Path path = Path();
final width = rect.width;
final height = rect.height;
final double diagonalAngleRadAbs = this.angle.angleRadians.abs();
final bool isDirectionLeft = this.direction == DiagonalDirection.Left;
final double perpendicularHeight = (rect.width * tan(diagonalAngleRadAbs));
switch (this.position) {
case DiagonalPosition.Bottom:
if (isDirectionLeft) {
path.moveTo(0, 0);
path.lineTo(width, 0);
path.lineTo(width, height - perpendicularHeight);
path.lineTo(0, height);
path.close();
} else {
path.moveTo(width, height);
path.lineTo(0, height - perpendicularHeight);
path.lineTo(0, 0);
path.lineTo(width, 0);
path.close();
}
break;
case DiagonalPosition.Top:
if (isDirectionLeft) {
path.moveTo(width, height);
path.lineTo(width, 0 + perpendicularHeight);
path.lineTo(0, 0);
path.lineTo(0, height);
path.close();
} else {
path.moveTo(width, height);
path.lineTo(width, 0);
path.lineTo(0, 0 + perpendicularHeight);
path.lineTo(0, height);
path.close();
}
break;
case DiagonalPosition.Right:
if (isDirectionLeft) {
path.moveTo(0, 0);
path.lineTo(width, 0);
path.lineTo(width - perpendicularHeight, height);
path.lineTo(0, height);
path.close();
} else {
path.moveTo(0, 0);
path.lineTo(width - perpendicularHeight, 0);
path.lineTo(width, height);
path.lineTo(0, height);
path.close();
}
break;
case DiagonalPosition.Left:
if (isDirectionLeft) {
path.moveTo(0 + perpendicularHeight, 0);
path.lineTo(width, 0);
path.lineTo(width, height);
path.lineTo(0, height);
path.close();
} else {
path.moveTo(0, 0);
path.lineTo(width, 0);
path.lineTo(width, height);
path.lineTo(0 + perpendicularHeight, height);
path.close();
}
break;
}
return path;
}