calculateNearestAlignment method

Alignment calculateNearestAlignment({
  1. required Offset offset,
})

Implementation

Alignment calculateNearestAlignment({
  required Offset offset,
}) {
  AlignmentDistance calculateDistance(Alignment alignment) {
    final distance = alignment
        .offset(_context, size)
        .translate(
          -offset.dx,
          -offset.dy,
        )
        .distanceSquared;

    return AlignmentDistance(
      alignment: alignment,
      distance: distance,
    );
  }

  final distances =
      GrxAlignmentExtension.values.map(calculateDistance).toList();

  distances.sort((a, b) => a.distance.compareTo(b.distance));

  return distances.first.alignment;
}