getRectAroundLine static method

Path getRectAroundLine(
  1. Offset point1,
  2. Offset point2,
  3. dynamic rectWidth
)

Implementation

static Path getRectAroundLine(Offset point1, Offset point2, rectWidth) {
  Path path = Path();
  Offset pnsv = VectorUtils.normalizeVector(
        VectorUtils.getPerpendicularVector(point1, point2),
      ) *
      rectWidth;

  // rect around line
  path.moveTo(point1.dx + pnsv.dx, point1.dy + pnsv.dy);
  path.lineTo(point2.dx + pnsv.dx, point2.dy + pnsv.dy);
  path.lineTo(point2.dx - pnsv.dx, point2.dy - pnsv.dy);
  path.lineTo(point1.dx - pnsv.dx, point1.dy - pnsv.dy);
  path.close();

  return path;
}