// -- indexer /// <summary> /// Frequency-based intexer to be able to get the element closest to the given frequency out of the repository. /// The element doesn't need to have the exact frequency. /// </summary> /// <param name="freq">the searced frequency</param> /// <returns>the instance of MaterialPhysics with the closes frequency property or a new constructed instance</returns> public MaterialPhysics this[float freq] { get { var found = new MaterialPhysics(); int index = -1; float delta = float.MaxValue; foreach (var fv in Physics) { float d = fv.Frequency - freq; if (d < delta) { delta = d; index = Physics.IndexOf(fv); } } // finish if (index != -1) { found = Physics[index]; } return(found); } }
public Material(string name, MaterialPhysics physic) : this() { this.Name = name; this.Physics.Add(physic); }