Commits

Karsten Schmidt committed d0a1e15

adding add/remove methods for collections of behaviours & constraints to VerletParticle2D

Comments (0)

Files changed (1)

src.physics/toxi/physics2d/VerletParticle2D.java

 package toxi.physics2d;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import toxi.geom.ReadonlyVec2D;
         return this;
     }
 
+    public VerletParticle2D addBehaviors(
+            Collection<ParticleBehavior2D> behaviors) {
+        return addBehaviors(behaviors, 1);
+    }
+
+    public VerletParticle2D addBehaviors(
+            Collection<ParticleBehavior2D> behaviors, float timeStemp) {
+        for (ParticleBehavior2D b : behaviors) {
+            addBehavior(b, timeStemp);
+        }
+        return this;
+    }
+
     /**
      * Adds the given constraint implementation to the list of constraints
      * applied to this particle at each time step.
         return this;
     }
 
+    public VerletParticle2D addConstraints(
+            Collection<ParticleConstraint2D> constraints) {
+        for (ParticleConstraint2D c : constraints) {
+            addConstraint(c);
+        }
+        return this;
+    }
+
     public VerletParticle2D addForce(Vec2D f) {
         force.addSelf(f);
         return this;
         return this;
     }
 
-    public boolean removeBehavior(ParticleBehavior2D c) {
-        return behaviors.remove(c);
+    public boolean removeBehavior(ParticleBehavior2D b) {
+        return behaviors.remove(b);
+    }
+
+    public boolean removeBehaviors(Collection<ParticleBehavior2D> behaviors) {
+        return this.behaviors.removeAll(behaviors);
     }
 
     /**
         return constraints.remove(c);
     }
 
+    public boolean removeConstraints(
+            Collection<ParticleConstraint2D> constraints) {
+        return this.constraints.removeAll(constraints);
+    }
+
     public VerletParticle2D scaleVelocity(float scl) {
         prev.interpolateToSelf(this, 1f - scl);
         return this;