/// marks a PrimitiveBufferComponentConstraint as satisfied as soon as the first component pair is found (reverse loop in buffer) where the constraint returns true public static bool checkAll(IEnumerable <PrimitiveBufferComponentAnyMatchConstraint> constraints, AbstractEvent candidate, IEnumerable <AbstractEvent> activationBuffer) { var unsatisfiedConstraints = new List <PrimitiveBufferComponentAnyMatchConstraint>(constraints); foreach (var bufferedEvent in activationBuffer) { foreach (var primitiveBufferComponent in bufferedEvent.getAllPrimitiveEventComponents()) { foreach (var primitiveCandidateComponent in candidate.getAllPrimitiveEventComponents()) { // reverse loop through constraints to remove the ones that are satisfied in the loop for (int constraintIndex = unsatisfiedConstraints.Count - 1; constraintIndex >= 0; constraintIndex--) { var constraint = unsatisfiedConstraints[constraintIndex]; var nowsatisfied = constraint.check(primitiveCandidateComponent, primitiveBufferComponent); if (nowsatisfied) { unsatisfiedConstraints.RemoveAt(constraintIndex); if (unsatisfiedConstraints.Count == 0) { return(true); } } } } } } return(unsatisfiedConstraints.Count == 0); }
/// marks a PrimitiveBufferComponentAllMatchConstraint as satisfied when the constraint returns true for all component pairs public static bool checkAll(IEnumerable <PrimitiveBufferComponentAllMatchConstraint> constraints, AbstractEvent candidate, IEnumerable <AbstractEvent> activationBuffer) { foreach (var bufferedEvent in activationBuffer) { foreach (var primitiveBufferComponent in bufferedEvent.getAllPrimitiveEventComponents()) { foreach (var primitiveCandidateComponent in candidate.getAllPrimitiveEventComponents()) { foreach (var constraint in constraints) { if (!constraint.check(primitiveCandidateComponent, primitiveBufferComponent)) { return(false); } } } } } return(true); }