public HexVectorComponent CreateHexVectorComponent(HexAxis positiveDirection, int magnitude) { return(new HexVectorComponent { Direction = magnitude >= 0 ? positiveDirection : _oppositeDirections[positiveDirection], Magnitude = Math.Abs(magnitude) }); }
private int GetComponent(HexAxis axis) { if (_selectedUnit == null || _selectedUnit.Vectors == null) { return(0); } return(_selectedUnit.GetDirectionValue(axis)); }
private void AssingComponentValue(int value, HexAxis axis) { if (_selectedUnit == null || _selectedUnit.Vectors == null) { return; } _selectedUnit.AssginDirectionValue(axis, (uint)Math.Abs(value)); }
public int GetMagnitudeAlongDirection(RawHexVector rawVector, HexAxis direction) { if (rawVector == null || rawVector.Components == null) { return(0); } return(GetValueAlongDirection(direction, rawVector.Components)); }
private int VectorComponentToMagnitude(HexVectorComponent vectorComponent, HexAxis positiveDirection) { if (vectorComponent == null) { return(0); } int coordinateSign = vectorComponent.Direction == positiveDirection ? +1 : -1; return(coordinateSign * vectorComponent.Magnitude); }
private HexVectorComponent ConsolidateCardinalDirection(HexAxis direction, IEnumerable <HexVectorComponent> components) { int speedSum = GetValueAlongDirection(direction, components); speedSum -= GetValueAlongDirection(_oppositeDirections[direction], components); return(new HexVectorComponent { Direction = speedSum >= 0 ? direction : _oppositeDirections[direction], Magnitude = Math.Abs(speedSum) }); }
private void CheckVector(HexAxis primaryAxis, int primaryMag, HexAxis secondaryAxis, int secondaryMag, HexAxis verticalAxis, int verticalMag) { var vectorA = new HexVector(primaryAxis, primaryMag, secondaryAxis, secondaryMag, verticalAxis, verticalMag); var result = ServiceFactory.Library.AvidCalculator.ProjectVectorToAvid(vectorA); result.Should().NotBeNull(); result.AbovePlane.Should().BeTrue(); result.Ring.Should().Be(AvidRing.Magenta); result.Direction.Should().Be(AvidDirection.Undefined); result.Magnitude.Should().Be(27); }
private void CheckMovement(int initialCf, int initialDa, int initialAlt, HexAxis moveAxis, uint moveMagnitude, int finalCf, int finalDa, int finalAlt, int finalDaValue) { var coordinate = new HexGridCoordinate { CfCoordinate = initialCf, DaCoordinate = initialDa, Altitude = initialAlt }; _calculator.Move(coordinate, moveAxis, moveMagnitude); CheckCoord(coordinate, finalCf, finalDa, finalAlt, finalDaValue); }
public void AddOrUpdateVectorDirection(RawHexVector rawVector, int value, HexAxis direction) { var affectedComponents = rawVector.Components.Where(hvc => hvc.Direction == direction).ToList(); if (value > 0) { if (affectedComponents.Count > 0) { var firstComponent = affectedComponents[0]; affectedComponents.Remove(firstComponent); firstComponent.Magnitude = value; } else { rawVector.AddComponent(direction, value); } } rawVector.RemoveComponents(affectedComponents); }
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); }
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); }
public VectorComponentViewModel(HexAxis direction) { _direction = direction; _hexVectorUtility = ServiceFactory.Library.HexVectorUtility; }
public HexVectorComponent(HexAxis direction, int magnitude) { Direction = direction; Magnitude = magnitude; }
public void Move(HexGridCoordinate position, HexAxis direction, uint distance) { position.AddComponent(new HexVectorComponent(direction, (int)distance)); _hexVectorUtility.ConsolidateVector(position); EliminateBeComponent(position); }
public void AddComponent(HexAxis direction, int magnitude) { AddComponent(new HexVectorComponent(direction, magnitude)); }
private HexVectorComponent ReplaceVectorComponent(int coordinateValue, HexVectorComponent existingComponent, HexAxis positiveAxis, HexAxis negativeAxis) { if (existingComponent != null) { _components.Remove(existingComponent); } var newComponent = new HexVectorComponent(coordinateValue >= 0 ? positiveAxis : negativeAxis, Math.Abs(coordinateValue)); _components.Add(newComponent); return(newComponent); }
private HexVectorComponent ReplaceVectorComponent(int coordinateValue, HexVectorComponent existingComponent, HexAxis positiveAxis, HexAxis negativeAxis) { if (existingComponent != null) { _components.Remove(existingComponent); } var newComponent = new HexVectorComponent(coordinateValue >= 0 ? positiveAxis : negativeAxis, Math.Abs(coordinateValue)); _components.Add(newComponent); return newComponent; }
public void EliminateComponentsAlongCardinalDirection(RawHexVector rawVector, HexAxis direction) { var affectedComponents = rawVector.Components.Where(hvc => hvc.Direction == direction || hvc.Direction == _oppositeDirections[direction]).ToArray(); foreach (var component in affectedComponents) { rawVector.RemoveComponent(component); } }
public static void CheckComponent(HexVectorComponent component, HexAxis expectedDirection, int expectedMagnitude) { component.Direction.Should().Be(expectedDirection); component.Magnitude.Should().Be(expectedMagnitude); }
private void CheckVectorComponent(HexGridCoordinate testCoordinate, int expectedMagnitude, HexAxis positiveAxis, HexAxis negativeAxis) { if (expectedMagnitude == 0) { return; } testCoordinate.Components.Should().ContainSingle(hvc => hvc.Magnitude == Math.Abs(expectedMagnitude) && hvc.Direction == (expectedMagnitude < 0 ? negativeAxis : positiveAxis)); }
private int GetValueAlongDirection(HexAxis direction, IEnumerable <HexVectorComponent> components) { return(components.Where(hvc => hvc.Direction.Equals(direction)).Sum(hvc => hvc.Magnitude)); }
public void AssginDirectionValue(HexAxis direction, uint newValue) { _hexVectorUtility.AddOrUpdateVectorDirection(Vectors, (int)newValue, direction); OnVelocityChanged(); }
public int GetDirectionValue(HexAxis direction) { return _hexVectorUtility.GetMagnitudeAlongDirection(Vectors, direction); }
public int GetDirectionValue(HexAxis direction) { return(_hexVectorUtility.GetMagnitudeAlongDirection(Vectors, direction)); }
private int GetComponent(HexAxis axis) { if (_selectedUnit == null || _selectedUnit.Vectors == null) { return 0; } return _selectedUnit.GetDirectionValue(axis); }
private int VectorComponentToMagnitude(HexVectorComponent vectorComponent, HexAxis positiveDirection) { if (vectorComponent == null) { return 0; } int coordinateSign = vectorComponent.Direction == positiveDirection ? +1 : -1; return coordinateSign * vectorComponent.Magnitude; }
public void Move(HexAxis direction) { _hexGridCalculator.Move(Position, direction, 1); OnMoved(); }
public int GetMagnitudeAlongCardinalDirection(RawHexVector rawVector, HexAxis direction) { var component = ConsolidateCardinalDirection(direction, rawVector.Components); return(component.Direction == direction ? component.Magnitude : -component.Magnitude); }