directionFromAngle static method

TextDirection directionFromAngle(
  1. Offset from,
  2. Offset to
)

Suggest the best text direction for a string that sits on a given line, by using the start and end points of that line.

Implementation

static TextDirection directionFromAngle(Offset from, Offset to) {
  var angle = math.atan2(
    to.dy - from.dy,
    to.dx - from.dx,
  );

  if (angle < -math.pi / 2 || angle > math.pi / 2) {
    return TextDirection.rightToLeft;
  } else {
    return TextDirection.leftToRight;
  }
}