computeDepthForGroup method

void computeDepthForGroup(
  1. ParticleGroup group
)

Implementation

void computeDepthForGroup(ParticleGroup group) {
  for (final particle in group.particles) {
    particle.accumulation = 0.0;
  }
  for (final contact in contactBuffer) {
    final particleA = contact.particleA;
    final particleB = contact.particleB;
    if (group.contains(particleA) && group.contains(particleB)) {
      final w = contact.weight;
      particleA.accumulation += w;
      particleB.accumulation += w;
    }
  }
  for (final particle in group.particles) {
    particle.depth = particle.accumulation < 0.8 ? 0.0 : double.maxFinite;
  }
  for (var t = 0; t < group.particles.length; t++) {
    var updated = false;
    for (final contact in contactBuffer) {
      final particleA = contact.particleA;
      final particleB = contact.particleB;
      if (group.contains(particleA) && group.contains(particleB)) {
        final r = 1 - contact.weight;
        if (particleA.depth > particleB.depth + r) {
          particleA.depth = particleB.depth + r;
          updated = true;
        }
        if (particleB.depth > particleA.depth + r) {
          particleB.depth = particleA.depth + r;
          updated = true;
        }
      }
    }
    if (!updated) {
      break;
    }
  }
  for (final particle in group.particles) {
    if (particle.depth < double.maxFinite) {
      // TODO(spydon): it will always go into this case?
      particle.depth *= particleDiameter;
    } else {
      particle.depth = 0.0;
    }
  }
}