angleForHandle static method

double angleForHandle({
  1. required DiagramControlHandleKind kind,
  2. required double axisX,
  3. required double axisY,
  4. required double shapeRotation,
})

Implementation

static double angleForHandle({
  required DiagramControlHandleKind kind,
  required double axisX,
  required double axisY,
  required double shapeRotation,
}) {
  return switch (kind) {
    DiagramControlHandleKind.resize when axisX != 0 && axisY != 0 =>
      // The corner cursor is already drawn on the NE/SW diagonal. The
      // opposite diagonal is the same artwork rotated exactly 90 degrees.
      // Rotating it by atan2(axisY, axisX) would apply the diagonal twice.
      shapeRotation + (axisX * axisY > 0 ? math.pi / 2 : 0),
    DiagramControlHandleKind.resize =>
      shapeRotation + (axisX == 0 ? math.pi / 2 : 0),
    DiagramControlHandleKind.rotate =>
      shapeRotation +
          switch ((axisX, axisY)) {
            (-1, -1) => 0,
            (1, -1) => math.pi / 2,
            (1, 1) => math.pi,
            (-1, 1) => 3 * math.pi / 2,
            _ => math.atan2(axisY, axisX) + 3 * math.pi / 4,
          },
    _ => math.atan2(axisY, axisX) + shapeRotation,
  };
}