normalize method

void normalize(
  1. double thickness
)

=== Mutators === The following methods modify the current point. Normalizes the GPoint to have the specified thickness but keeping its direction.

If the point is at the origin, it will be set to the positive x-axis direction or the positive y-axis direction (depending on which component is zero).

If the point is not at the origin, it will be scaled to have the specified thickness while keeping its direction.

Implementation

/// Normalizes the [GPoint] to have the specified [thickness] but keeping its
/// direction.
///
/// If the point is at the origin, it will be set to the positive x-axis
/// direction or the positive y-axis direction (depending on which component
/// is zero).
///
/// If the point is not at the origin, it will be scaled to have the specified
/// thickness while keeping its direction.
void normalize(double thickness) {
  if (y == 0) {
    x = x < 0 ? -thickness : thickness;
  } else if (x == 0) {
    y = y < 0 ? -thickness : thickness;
  } else {
    var m = thickness / Math.sqrt(x * x + y * y);
    x *= m;
    y *= m;
  }
}