public IFraction Divide(IFraction other) { if (other == null) { throw new ArgumentNullException("other"); } if (other is IFraction <int> ) { return(Add((IFraction <int>)other)); } if (other.Equals(0)) { throw new DivideByZeroException(); } if (_numerator == 0 && _wholeNumber == 0) { return(other); } if (other.GetMaxUnderlyingValue().CompareTo(int.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(int.MinValue) >= 0) { return(Divide(Convert.ToInt32(other.WholeNumber), Convert.ToInt32(other.Numerator), Convert.ToInt32(other.Denominator))); } return((new Fraction64(this)).Divide(other)); }
public IFraction Multiply(IFraction other) { if (other == null) { throw new ArgumentNullException("other"); } if (other is IFraction <long> ) { return(Add((IFraction <long>)other)); } if (_numerator == 0 && _wholeNumber == 0) { return(other); } if (other.Equals(0)) { return(Fraction64.Zero); } if (other.GetMaxUnderlyingValue().CompareTo(long.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(long.MinValue) >= 0) { return(Multiply(Convert.ToInt64(other.WholeNumber), Convert.ToInt64(other.Numerator), Convert.ToInt64(other.Denominator))); } return((new Fraction64(this)).Multiply(other)); }
public void SelectFraction(IFraction fraction) { fractions.CurrentFraction = fraction; cards = collection.GetFractionCards(fractions.CurrentFraction.Name, true); FirstPages(cards.Count); }
/// <summary> /// Создаёт персонажа. /// </summary> /// <returns> Возвращает созданного персонажа. </returns> private static IPerson CreateStartPerson(string personSchemeSid, IPersonFactory personFactory, IFraction fraction) { var startPerson = personFactory.Create(personSchemeSid, fraction); return(startPerson); }
public Fraction64(IFraction fraction) { long numerator, denominator; _wholeNumber = FractionUtil.GetNormalizedRational64(FractionUtil.ToInt64(fraction.WholeNumber), FractionUtil.ToInt64(fraction.Numerator), FractionUtil.ToInt64(fraction.Denominator, 1), out numerator, out denominator); _numerator = numerator; _denominator = denominator; }
public Fraction16(IFraction fraction) { int numerator, denominator; _wholeNumber = (short)(FractionUtil.GetNormalizedRational(FractionUtil.ToInt32(fraction.WholeNumber), FractionUtil.ToInt32(fraction.Numerator), FractionUtil.ToInt32(fraction.Denominator, 1), out numerator, out denominator)); _numerator = (short)numerator; _denominator = (short)denominator; }
public FractionsButton Assing(Transform parent, IFraction fraction, Action <FractionsButton> click) { (Identifier, this.clickHandler) = (fraction, click); nameFraction.SetKey(fraction.Name); transform.SetParent(parent, false); fon.color = Color.gray; return(this); }
public void Pow(IFraction frc) { var p = (double)frc.ToNumber(); this.Numerator = (decimal)Math.Pow((double)this.Numerator, p); this.Denominator = (decimal)Math.Pow((double)this.Denominator, p); SimplifyFloats(); }
/// <summary> /// Создаёт персонажа. /// </summary> /// <param name="serviceProvider"> Контейнер DI, откуда извлекаются сервисы для создания персонажа. </param> /// <returns> Возвращает созданного персонажа. </returns> public static IPerson CreateStartPerson(IServiceProvider serviceProvider, IFraction fraction) { var personFactory = serviceProvider.GetRequiredService <IPersonFactory>(); var startPerson = personFactory.Create("human-person", fraction); return(startPerson); }
public IPerson Create(string personSchemeSid, IFraction fraction) { var personScheme = _schemeService.GetScheme <IPersonScheme>(personSchemeSid); var person = new HumanPerson(personScheme, fraction); var attributes = new[] { new PersonAttribute(PersonAttributeType.PhysicalStrength, 10), new PersonAttribute(PersonAttributeType.Dexterity, 10), new PersonAttribute(PersonAttributeType.Perception, 10), new PersonAttribute(PersonAttributeType.Constitution, 10) }; var attributesModule = new AttributesModule(attributes); person.AddModule(attributesModule); var inventoryModule = new InventoryModule(); person.AddModule(inventoryModule); var equipmentModule = new EquipmentModule(personScheme.Slots); person.AddModule(equipmentModule); var сonditionModule = new ConditionsModule(); person.AddModule(сonditionModule); var evolutionModule = new EvolutionModule(_schemeService); person.AddModule(evolutionModule); var survivalModule = new HumanSurvivalModule(personScheme, _survivalRandomSource, attributesModule, сonditionModule, evolutionModule, equipmentModule); person.AddModule(survivalModule); var defaultActScheme = _schemeService.GetScheme <ITacticalActScheme>(person.Scheme.DefaultActs.First()); var defaultActSchemes = new[] { defaultActScheme }; var combatActModule = new CombatActModule( defaultActSchemes, equipmentModule, сonditionModule, evolutionModule); person.AddModule(combatActModule); var combatStatsModule = new CombatStatsModule(evolutionModule, equipmentModule); person.AddModule(combatStatsModule); var diseaseModule = new DiseaseModule(сonditionModule); person.AddModule(diseaseModule); return(person); }
IFraction <long> IFraction <long> .Subtract(IFraction <long> other) { if (other == null) { throw new ArgumentNullException("other"); } return(Subtract(other.WholeNumber, other.Numerator, other.Denominator)); }
public Fraction8(IFraction other) { _hashCode = 0; sbyte numerator, denominator; _wholeNumber = FractionUtil.GetNormalizedRational8(FractionUtil.ToSByte(other.WholeNumber), FractionUtil.ToSByte(other.Numerator), FractionUtil.ToSByte(other.Denominator, 1), out numerator, out denominator); _numerator = numerator; _denominator = denominator; }
public void Pow(IComplex z) { if (z.Im.Numerator == 0) { if (this.Im.Numerator == 0) { this.Re.Pow(z.Re); } else { var n = (double)z.Re.ToNumber(); if (n == 0) { this.Re = new Fraction(); this.Im = new Fraction(0, 1); } else if (n == 1) { } if (z.Re.Numerator > 1 && z.Re.Denominator > 1) { //first power using numeratora and this function then root using this function and denominator throw new NotImplementedException("Complex number to power of fraction is not implemnted"); } else if (z.Re.Numerator > 1 && z.Re.Denominator == 1) { var r2 = (double)((Fraction)this.Re * this.Re + (Fraction)this.Im * this.Im).ToNumber(); var r = Math.Pow(r2, 0.5); var y = (double)this.Im.ToNumber(); var rn = Math.Pow(r, n); var phi = Math.Asin(y / r); this.Re = new Fraction((decimal)(rn * Math.Cos(n * phi)), 1); this.Im = new Fraction((decimal)(rn * Math.Sin(n * phi)), 1); } else if (z.Re.Numerator == 1 && z.Re.Denominator > 1) { var r2 = (double)((Fraction)this.Re * this.Re + (Fraction)this.Im * this.Im).ToNumber(); var r = Math.Pow(r2, 0.5); var y = (double)this.Im.ToNumber(); var rn = Math.Pow(r, n); var phi = Math.Asin(y / r); this.Re = new Fraction((decimal)(rn * Math.Cos(n * phi)), 1); this.Im = new Fraction((decimal)(rn * Math.Sin(n * phi)), 1); } } } else { throw new NotImplementedException("Complex number to power of complex number is not implemented"); } }
public Form1() { InitializeComponent(); HttpChannel channel = new HttpChannel(); ChannelServices.RegisterChannel(channel, false); myIFraction = (IFraction)Activator.GetObject( typeof(IFraction), "http://localhost:1234/_Server_"); }
public void Multiply(string dim, decimal val) { if (this.Key == dim) { this.Value = (Fraction)this.Value * val; } else { throw new ArgumentException($"Couldn't find that key '{dim}' in expression dimensions"); } }
public void SetSelecedButton(IFraction fraction) { foreach (var item in buttons) { if (item.Identifier == fraction) { currentButton?.SelectFraction(false); currentButton = null; Select(item); } } }
IFraction <int> IFraction <int> .Add(IFraction <int> other) { if (other == null) { throw new ArgumentNullException("other"); } if (other is Fraction32) { return(Add((Fraction32)other)); } return(Add(other.WholeNumber, other.Numerator, other.Denominator)); }
public void Divide(IFraction frc) { if (this.Denominator % 1 != 0 || frc.Denominator % 1 != 0 || this.Numerator % 1 != 0 || frc.Numerator % 1 != 0) { this.Numerator = this.Numerator * frc.Denominator; this.Denominator = this.Denominator * frc.Numerator; SimplifyFloats(); } else { this.Simplify(this.Numerator * frc.Denominator, this.Denominator * frc.Numerator); } }
IFraction <long> IFraction <long> .Multiply(IFraction <long> other) { if (other == null) { throw new ArgumentNullException("other"); } if (other is Fraction64) { return(Multiply((Fraction64)other)); } return(Multiply(other.WholeNumber, other.Numerator, other.Denominator)); }
public FractionsData() { var temp = Resources.LoadAll <FractionScriptable>("Data/Fractions/").ToList(); Fractions = temp.Where(x => x.Name != "neutral").ToList <IFraction>(); Fractions.Add(temp.Where(x => x.Name == "neutral").First()); //Добавить нейтралов последними в список фракций if (Fractions.Count > 0) { CurrentFraction = Fractions[0]; } else { Debug.LogError("Fractions not found!"); } }
public void Set(string dim, decimal val) { //if (this.Key.ContainsKey(dim)) //{ // this.Key[dim] += val; // if (this.Key[dim] == 0) // { // this.Key.Remove(dim); // } //} //else //{ // this.Key.Add(dim, val); //} this.Key = dim; this.Value = new Fraction(val, 1); }
private int CompareTo(IFraction <int> other) { if (other == null) { return(1); } if (other is Fraction32) { return(CompareTo((Fraction32)other)); } int n, d; int w = FractionUtil.GetNormalizedRational(other.WholeNumber, other.Numerator, other.Denominator, out n, out d); int i = _wholeNumber.CompareTo(w); if (i != 0) { return(i); } if (_wholeNumber == 0) { if (_numerator == 0 || n == 0 || _denominator == d) { return(_numerator.CompareTo(n)); } } else { if (_numerator == 0) { return(n); } if (n == 0) { return(_numerator); } } long n1 = _numerator, d1 = _denominator, n2 = n, d2 = d; FractionUtil.ToCommonDenominator64(ref n1, ref d1, ref n2, ref d2); return(n1.CompareTo(n2)); }
private int CompareTo(IFraction <long> other) { if (other == null) { return(1); } if (other is Fraction64) { return(CompareTo((Fraction64)other)); } long n, d; long w = FractionUtil.GetNormalizedRational64(other.WholeNumber, other.Numerator, other.Denominator, out n, out d); int i = _wholeNumber.CompareTo(w); if (i != 0) { return(i); } if (_wholeNumber == 0) { if (_numerator == 0 || n == 0 || _denominator == d) { return(_numerator.CompareTo(n)); } } else { if (_numerator == 0) { return((n < (long)(int.MinValue)) ? -1 : ((n > 0L) ? 1 : 0)); } if (n == 0) { return((_numerator < (long)(int.MinValue)) ? -1 : ((_numerator > 0L) ? 1 : 0)); } } long n1 = _numerator, d1 = _denominator, n2 = n, d2 = d; FractionUtil.ToCommonDenominator64(ref n1, ref d1, ref n2, ref d2); return(n1.CompareTo(n2)); }
public void Add(IFraction frc) { if (this.Denominator % 1 != 0 || frc.Denominator % 1 != 0 || this.Numerator % 1 != 0 || frc.Numerator % 1 != 0) { this.Numerator = this.Denominator * frc.Numerator + this.Numerator * frc.Denominator; this.Denominator *= frc.Denominator; SimplifyFloats(); } else { var gcf = GCF((int)this.Denominator, (int)frc.Denominator); var den = this.Denominator * frc.Denominator / gcf; var num = this.Numerator * den / this.Denominator + frc.Numerator * den / frc.Denominator; this.Simplify(num, den); } }
public FractionRelation GetRelation(IFraction targetFraction) { if (this == Fractions.MonsterFraction && targetFraction != Fractions.MonsterFraction) { // Фракция монстров нападает на всех, кроме монстров. // У монстров нет друзей. return(FractionRelation.Enmity); } if (this != Fractions.MonsterFraction && targetFraction == Fractions.MonsterFraction) { // С монтсрами никто не дружит. // Все фракции считают их врагами. return(FractionRelation.Enmity); } // Все фракции, кроме монстров, друг к другу относятся нейтрально. return(FractionRelation.Neutral); }
public IFraction Subtract(IFraction other) { if (other == null) { throw new ArgumentNullException("other"); } if (other is IFraction <long> ) { return(Subtract((IFraction <long>)other)); } if (other.GetMaxUnderlyingValue().CompareTo(long.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(long.MinValue) >= 0) { return(Subtract(Convert.ToInt64(other.WholeNumber), Convert.ToInt64(other.Numerator), Convert.ToInt64(other.Denominator))); } return((new Fraction64(this)).Subtract(other)); }
public int CompareTo(IFraction other) { if (other == null) { return(1); } if (other is IFraction <int> ) { return(CompareTo((IFraction <int>)other)); } if (other.GetMaxUnderlyingValue().CompareTo(int.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(int.MinValue) >= 0) { return(CompareTo(new Fraction32(Convert.ToInt32(other.WholeNumber), Convert.ToInt32(other.Numerator), Convert.ToInt32(other.Denominator)))); } return((new Fraction64(this)).CompareTo(other)); }
public bool Equals(IFraction other) { if (other == null) { return(false); } if (other is IFraction <long> ) { return(Equals((IFraction <long>)other)); } if (other.GetMaxUnderlyingValue().CompareTo(long.MaxValue) <= 0 && other.GetMinUnderlyingValue().CompareTo(long.MinValue) >= 0) { return(Equals(new Fraction64(Convert.ToInt64(other.WholeNumber), Convert.ToInt64(other.Numerator), Convert.ToInt64(other.Denominator)))); } return((new Fraction64(this)).Equals(other)); }
IFraction <long> IFraction <long> .Divide(IFraction <long> other) { if (other == null) { throw new ArgumentNullException("other"); } if (other.Numerator == 0 && other.WholeNumber == 0) { throw new DivideByZeroException(); } if ((other = other.AsInverted()) is Fraction64) { return(Multiply((Fraction64)other)); } return(Multiply(other.WholeNumber, other.Numerator, other.Denominator)); }
private static IPersonTemplateScheme[] GetPersonTemplateByFraction(IFraction fraction, ISchemeService schemeService) { if (fraction == Fractions.InterventionistFraction) { return(GetInterventionalistsPersonTemplates(schemeService)); } if (fraction == Fractions.MilitiaFraction) { return(GetMilitiaPersonTemplates(schemeService)); } if (fraction == Fractions.TroublemakerFraction) { return(GetTroublemakerPersonTemplates(schemeService)); } return(GetPlayerPersonTemplates(schemeService)); }