private void SetConfig(StrutConfig cfg) { foreach (StrutConnection s in cfg) { s.from.ConnectTo(s.to); } }
private StrutConfig GetConfig() { StrutConfig cfg = new StrutConfig(); foreach (Strut s in this) { if (s.target) { cfg.Add(s, s.target, 0); } } return(cfg); }
public bool Equals(StrutConfig v) { if ((!v) || (v.Count != Count)) { return(false); } foreach (StrutConnection c in this) { if (!v.Find(c)) { return(false); } } return(true); }
// Determine a "desired" strut configuration. If it differs from // current one, then the struts need to be rebuilt. private StrutConfig DesiredConfig() { StrutConfig cfg = new StrutConfig(); Counterparts counterparts = GetCounterparts(); // FIXME: 'naive' algorythm glitches a lot. // A better solution would be to minimize a sum of connection lengths // amongst all the configurations possible. foreach (Strut s in mStruts) { float min = Mathf.Infinity; Strut cMin = null; foreach (Tosh_AutoStrut c in counterparts) { foreach (Strut cs in c.mStruts) { float v = (s.position - cs.position).sqrMagnitude; if (v < min) { min = v; cMin = cs; } } } if (cMin) { cfg.Add(s, cMin, min); // 'add' method eliminates double links } // and replaces longer ones automatically. } return(cfg); }