public void RemoveComponent(HexVectorComponent component) { if (component == null) { throw new ArgumentNullException("component"); } _components.Remove(component); OnComponentsChanged(); }
private void SetComponent(ref HexVectorComponent component, HexVectorComponent newValue) { if (component != null) { _components.Remove(component); } component = newValue; if (newValue != null) { _components.Add(newValue); } }
protected override void OnComponentsChanged() { base.OnComponentsChanged(); _verticalComponent = Components.FirstOrDefault(hvc => hvc.Direction == HexAxis.Up || hvc.Direction == HexAxis.Down); var planarComponents = Components.Where(hvc => hvc.Direction != HexAxis.Up && hvc.Direction != HexAxis.Down).ToList(); planarComponents.Sort((va, vb) => Math.Sign(vb.Magnitude - va.Magnitude)); _primaryCompnoent = planarComponents.Count > 0 ? planarComponents[0] : null; _secondaryComponent = planarComponents.Count > 1 ? planarComponents[1] : null; }
public HexVector( HexAxis directionA, int magnitudeA, HexAxis directionB, int magnitudeB, HexAxis directionZ, int magnitudeZ) : base() { if (directionA == HexAxis.Up || directionA == HexAxis.Down || directionA == HexAxis.Undefined) { throw new ArgumentException(string.Format("DirectionA should be planar and defined, but found {0}", directionA), "directionA"); } if (directionB == HexAxis.Up || directionB == HexAxis.Down || directionB == HexAxis.Undefined) { throw new ArgumentException(string.Format("DirectionB should be planar and defined, but found {0}", directionB), "directionA"); } if ((directionZ != HexAxis.Up && directionZ != HexAxis.Down) || directionZ == HexAxis.Undefined) { throw new ArgumentException(string.Format("DirectionA should be vertical and defined, but found {0}", directionZ), "directionA"); } if (magnitudeA < 0 || magnitudeB < 0 || magnitudeZ < 0) { throw new ArgumentException(string.Format("All magnitudes should be positive (actual magnitudes are: A{0}, B{1}, Z{2}).", magnitudeA, magnitudeB, magnitudeZ)); } if (magnitudeA >= magnitudeB) { PrimaryComponent = new HexVectorComponent(directionA, magnitudeA); SecondaryComponent = new HexVectorComponent(directionB, magnitudeB); } else { PrimaryComponent = new HexVectorComponent(directionB, magnitudeB); SecondaryComponent = new HexVectorComponent(directionA, magnitudeA); } VerticalComponent = new HexVectorComponent(directionZ, magnitudeZ); }