protected override void MetaOperate(List <MutableObject> entryList, UnaryOperators operation) { switch (operation) { case UnaryOperators.Value: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue(Operand.GetValue(subEntry), subEntry); } break; case UnaryOperators.Abs: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue(Mathf.Abs(Operand.GetValue(subEntry)), subEntry); } break; case UnaryOperators.Sum: float total = 0; foreach (var subEntry in Operand.GetEntries(entryList)) { total += Operand.GetValue(subEntry); } foreach (var subEntry in OutputValue.GetEntries(entryList)) { OutputValue.SetValue(total, subEntry); } break; case UnaryOperators.Average: total = 0; int count = 0; foreach (var subEntry in Operand.GetEntries(entryList)) { total += Operand.GetValue(subEntry); count++; } total /= count; foreach (var subEntry in OutputValue.GetEntries(entryList)) { OutputValue.SetValue(total, subEntry); } break; case UnaryOperators.Max: float max = float.MinValue; foreach (var subEntry in Operand.GetEntries(entryList)) { var foundVal = Operand.GetValue(subEntry); if (max < foundVal) { max = foundVal; } } foreach (var subEntry in OutputValue.GetEntries(entryList)) { OutputValue.SetValue(max, subEntry); } break; case UnaryOperators.Min: float min = float.MaxValue; foreach (var subEntry in Operand.GetEntries(entryList)) { var foundVal = Operand.GetValue(subEntry); if (min > foundVal) { min = foundVal; } } foreach (var subEntry in OutputValue.GetEntries(entryList)) { OutputValue.SetValue(min, subEntry); } break; case UnaryOperators.Accumulate: total = 0f; foreach (var subEntry in Operand.GetEntries(entryList)) { total += Operand.GetValue(subEntry); OutputValue.SetValue(total, subEntry); } break; case UnaryOperators.Diff: bool first = true; var prior = 0f; foreach (var subEntry in Operand.GetEntries(entryList)) { var foundEntry = Operand.GetValue(subEntry); prior = foundEntry - prior; if (first) { first = false; OutputValue.SetValue(0f, subEntry); prior = foundEntry; continue; } OutputValue.SetValue(prior, subEntry); prior = foundEntry; } break; case UnaryOperators.Sign: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue((Operand.GetValue(subEntry) >= 0?1f:-1f), subEntry); } break; case UnaryOperators.Sin: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue(Mathf.Sin(Operand.GetValue(subEntry)), subEntry); } break; case UnaryOperators.Cos: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue(Mathf.Cos(Operand.GetValue(subEntry)), subEntry); } break; case UnaryOperators.Tan: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue(Mathf.Tan(Operand.GetValue(subEntry)), subEntry); } break; default: throw new Exception("Unknown operation type!"); } }
protected override void MetaOperate(List <MutableObject> entryList, UnaryOperators operation) { switch (operation) { case UnaryOperators.Value: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue(Operand.GetValue(subEntry), subEntry); } break; case UnaryOperators.Accumulate: var total = Vector3.zero; foreach (var subEntry in Operand.GetEntries(entryList)) { total += Operand.GetValue(subEntry); OutputValue.SetValue(total, subEntry); } break; case UnaryOperators.Diff: bool first = true; var prior = Vector3.zero; foreach (var subEntry in Operand.GetEntries(entryList)) { var foundEntry = Operand.GetValue(subEntry); prior = foundEntry - prior; if (first) { first = false; OutputValue.SetValue(0, subEntry); prior = foundEntry; continue; } OutputValue.SetValue(prior, subEntry); prior = foundEntry; } break; case UnaryOperators.Sign: foreach (var subEntry in Operand.GetEntries(entryList)) { OutputValue.SetValue(Vector3.Normalize(Operand.GetValue(subEntry)), subEntry); } break; case UnaryOperators.Sin: foreach (var subEntry in Operand.GetEntries(entryList)) { var result = Operand.GetValue(subEntry); OutputValue.SetValue( new Vector3( Mathf.Sin(result.x), Mathf.Sin(result.y), Mathf.Sin(result.z)), subEntry); } break; case UnaryOperators.Cos: foreach (var subEntry in Operand.GetEntries(entryList)) { var result = Operand.GetValue(subEntry); OutputValue.SetValue( new Vector3( Mathf.Cos(result.x), Mathf.Cos(result.y), Mathf.Cos(result.z)), subEntry); } break; case UnaryOperators.Tan: foreach (var subEntry in Operand.GetEntries(entryList)) { var result = Operand.GetValue(subEntry); OutputValue.SetValue( new Vector3( Mathf.Tan(result.x), Mathf.Tan(result.y), Mathf.Tan(result.z)), subEntry); } break; default: throw new Exception("Unhandled operation type!"); } }