normalizeAxes static method

Map<String, dynamic> normalizeAxes([
  1. double? x,
  2. double? y
])

Implementation

static Map<String,dynamic> normalizeAxes([double? x, double? y]) {
  x ??= 0;
  y ??= 0;
  double xAxis = x;
  double yAxis = y;

  // Determine if the point is outside the bounds of the circle
  // and, if so, place it on the edge of the circle
  final hypotenuse = math.sqrt((x * x) + (y * y));
  if (hypotenuse > 1) {
    final theta = math.atan2(y, x);
    xAxis = math.cos(theta);
    yAxis = math.sin(theta);
  }

  // Scale and move the circle so values are in the interpolation range.  The circle's origin moves
  // from (0, 0) to (0.5, 0.5). The circle's radius scales from 1 to be 0.5.
  final result = {
    'normalizedXAxis': (xAxis * 0.5) + 0.5,
    'normalizedYAxis': (yAxis * 0.5) + 0.5
  };
  return result;
}