beginGrab method

bool beginGrab(
  1. double x,
  2. double y, {
  3. required double radius,
  4. required double pushDepth,
})

Grabs every free node around (x, y) with a smooth falloff. Returns false if nothing could be grabbed.

Implementation

bool beginGrab(
    double x,
    double y, {
      required double radius,
      required double pushDepth,
    }) {
  endGrab();
  _grabX = x;
  _grabY = y;
  _pushDepth = pushDepth;

  for (final PointMass node in nodes) {
    if (node.isPinned) continue;
    final double dx = node.x - x;
    final double dy = node.y - y;
    final double distance = math.sqrt(dx * dx + dy * dy);
    if (distance >= radius) continue;
    final double t = 1.0 - distance / radius;
    node.hold = t * t * (3.0 - 2.0 * t); // smoothstep
    node.holdDx = dx;
    node.holdDy = dy;
    _held.add(node);
  }
  return _held.isNotEmpty;
}