public void DivideInt32() { float from = 123.43F; int divisor = 12; Assert.AreEqual(from / divisor, GenericMath.DivideAlternative(from, divisor)); }
public void AddDateTimeTimeSpan() { DateTime from = DateTime.Today; TimeSpan delta = TimeSpan.FromHours(73.5); Assert.AreEqual(from + delta, GenericMath.AddAlternative(from, delta)); }
public T Divide <T>(T a, T b) { switch (b) { case 0: throw new DivideByZeroException("Numerator is zero"); case 0.0: throw new DivideByZeroException("Numerator is zero"); case double.PositiveInfinity: throw new NotFiniteNumberException("Numerator is positive infinity"); case double.NegativeInfinity: throw new NotFiniteNumberException("Numerator is negative infinity"); default: switch (a) { case double.NegativeInfinity: throw new NotFiniteNumberException("Denumerator is negative infinity"); case double.PositiveInfinity: throw new NotFiniteNumberException("Denumerator is positive infinity"); default: return(GenericMath <T> .Divide(a, b)); } } }
public void AddTestComplex() { Complex a = new Complex(12, 3); Complex b = new Complex(2, 5); Assert.AreEqual(a + b, GenericMath.Add(a, b)); }
/// <inheritdoc /> protected override void Load(ContainerBuilder register) { if (typeof(TKeyType) == typeof(int)) { //Because of active load scene, we have to iterate each scene foreach (var registerable in new SceneUiElementEnumerable()) { //Registers the adapter with the specified Key and Service Type. register.RegisterInstance(registerable) .SingleInstance() .Keyed(registerable.RegisterationKey, registerable.UIServiceType); } } else { //Because of active load scene, we have to iterate each scene foreach (var registerable in new SceneUiElementEnumerable()) { //Registers the adapter with the specified Key and Service Type. register.RegisterInstance(registerable) .SingleInstance() .Keyed(GenericMath.Convert <int, TKeyType>(registerable.RegisterationKey), registerable.UIServiceType); } } }
public GenericChildKeyStrategy(InformationHandlingFlags typeHandling, [NotNull] ITypeSerializerStrategy <TKeyType> keyTypeSerializerStrategy) { if (keyTypeSerializerStrategy == null) { throw new ArgumentNullException(nameof(keyTypeSerializerStrategy)); } int i; if (!Enum.IsDefined(typeof(InformationHandlingFlags), typeHandling) && Int32.TryParse(typeHandling.ToString(), out i)) { throw new ArgumentOutOfRangeException(nameof(typeHandling), "Value should be defined in the InformationHandlingFlags enum."); } /*int i; * * if (!Enum.IsDefined(typeof(InformationHandlingFlags), typeHandling) && Int32.TryParse(typeHandling.ToString(), out i)) * throw new InvalidEnumArgumentException(nameof(typeHandling), (int)typeHandling, * typeof(InformationHandlingFlags));*/ //Try to get the max value for this type DefaultKey = GenericMath.Convert <TKeyType, int>(GenericMath.Convert <int, TKeyType>(Int32.MaxValue)); typeHandlingFlags = typeHandling; KeyTypeSerializerStrategy = keyTypeSerializerStrategy; }
public void SubtractTestComplex() { Complex a = new Complex(12, 3); Complex b = new Complex(2, 5); Assert.AreEqual(a - b, GenericMath.Subtract(a, b)); }
public void MultiplyFloatInt32() { float from = 123.43F; int factor = 12; Assert.AreEqual(from * factor, GenericMath.MultiplyAlternative(from, factor)); }
public void SubtractDateTimeTimeSpan() { DateTime from = DateTime.Today; TimeSpan delta = TimeSpan.FromHours(73.5); Assert.AreEqual(from - delta, GenericMath.SubtractAlternative(from, delta)); }
public T Divide <T>(T num1, T num2) { if (num1.Equals(0) || num2.Equals(0)) { throw new DivideByZeroException("You cannot divide by 0"); } return(GenericMath <T> .Divide(num1, num2)); }
/// <inheritdoc /> public async Task <int> ReadAsync(IWireStreamReaderStrategyAsync source) { //Read the key from the stream. TKeyType key = await KeyTypeSerializerStrategy .ReadAsync(typeHandlingFlags.HasFlag(InformationHandlingFlags.DontConsumeRead)?source.WithOnlyPeekingAsync() : source) .ConfigureAwait(false); return(GenericMath.Convert <TKeyType, int>(key)); }
/// <inheritdoc /> public override Task WriteAsync(TEnumType value, IWireStreamWriterStrategyAsync dest) { if (dest == null) { throw new ArgumentNullException(nameof(dest)); } return(serializerStrategy.WriteAsync(GenericMath.Convert <TEnumType, TBaseType>(value), dest)); }
/// <inheritdoc /> public override void Write(TEnumType value, IWireStreamWriterStrategy dest) { if (dest == null) { throw new ArgumentNullException(nameof(dest)); } serializerStrategy.Write(GenericMath.Convert <TEnumType, TBaseType>(value), dest); }
public void ConvertInt32ToDouble() { int from = 280; double d = GenericMath.Convert <int, double>(from); int i = GenericMath.Convert <double, int>(d); Assert.AreEqual(i, from); Assert.AreEqual(d, (double)i); }
/// <inheritdoc /> public override TEnumType Read(IWireStreamReaderStrategy source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } //TODO: Should be handle exceptions? return(GenericMath.Convert <TBaseType, TEnumType>(serializerStrategy.Read(source))); }
/// <summary> /// Helper extension for setting entity data in <see cref="IEntityDataFieldContainer"/> /// based on the int value of a specified Enum value <see cref="index"/>. /// </summary> /// <typeparam name="TEnumType"></typeparam> /// <param name="container"></param> /// <param name="index"></param> /// <param name="guid"></param> public static void SetFieldValue <TEnumType>(this IEntityDataFieldContainer container, TEnumType index, NetworkEntityGuid guid) where TEnumType : Enum { if (container == null) { throw new ArgumentNullException(nameof(container)); } container.SetFieldValue(GenericMath.Convert <TEnumType, int>(index), guid.RawGuidValue); }
public static TValueType GetEnumFieldValue <TValueType>(this IReadonlyEntityDataFieldContainer container, GameObjectField index) where TValueType : Enum { if (container == null) { throw new ArgumentNullException(nameof(container)); } return(GenericMath.Convert <int, TValueType>(container.GetFieldValue <int>((int)index))); }
/// <summary> /// Determines the size of the collection from the stream. /// </summary> public int Size(IWireStreamReaderStrategy reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } //Read the byte size from the stream. //Readd the addedsize so that we know how many items are really there. return(GenericMath.Convert <TSizeType, int>(SizeTypeSerializerStrategy.Read(reader)) + AddedSize); }
/// <summary> /// Helper extension for setting entity data in <see cref="IEntityDataFieldContainer"/> /// based on the int value of a specified Enum value <see cref="index"/>. /// </summary> /// <typeparam name="TEnumType"></typeparam> /// <typeparam name="TValueType"></typeparam> /// <param name="container"></param> /// <param name="index"></param> /// <param name="value"></param> public static void SetFieldValue <TEnumType, TValueType>(this IEntityDataFieldContainer container, TEnumType index, TValueType value) where TValueType : struct where TEnumType : Enum { if (container == null) { throw new ArgumentNullException(nameof(container)); } container.SetFieldValue(GenericMath.Convert <TEnumType, int>(index), value); }
/// <inheritdoc /> public override async Task <TEnumType> ReadAsync(IWireStreamReaderStrategyAsync source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } //TODO: Should be handle exceptions? return(GenericMath.Convert <TBaseType, TEnumType>(await serializerStrategy.ReadAsync(source) .ConfigureAwait(false))); }
public void DecimalDelta() { Assert.IsTrue(GenericMath.WithinDelta(10m, 15m, 6m)); Assert.IsTrue(GenericMath.WithinDelta(15m, 10m, 6m)); Assert.IsTrue(GenericMath.WithinDelta(10m, 15m, 5m)); Assert.IsTrue(GenericMath.WithinDelta(15m, 10m, 5m)); Assert.IsFalse(GenericMath.WithinDelta(10m, 15m, 4m)); Assert.IsFalse(GenericMath.WithinDelta(15m, 10m, 4m)); }
private void LateUpdate() { //the idea is to create a rotational difference between the actual goal in anim with an arbitrary offset that makes it seem like the player is targeting something //create a rotatioal difference between the animation playing and goal in 3D Vector3 direction = offsetInAnim - virtualEndEffector.position; Quaternion difference = GenericMath.RotateFromTo(transform.position + direction, lookAtAxis); virtualEndEffector.rotation = difference; DirectionalSwingSolver.Process(chain, lookAtAxis, virtualEndEffector); }
private static bool HasOpCodeAttribute <TWireLinkBaseAttributeType, TOpcodeType>(Type t, TOpcodeType opcode) where TWireLinkBaseAttributeType : WireDataContractBaseLinkAttribute { TWireLinkBaseAttributeType attri = t.GetCustomAttribute <TWireLinkBaseAttributeType>(); if (attri == null) { return(false); } return(attri.Index == GenericMath.Convert <TOpcodeType, int>(opcode)); }
/// <inheritdoc /> public int Size(IWireStreamReaderStrategy reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } TSizeType size = sizeSerializer.Read(reader); //Using JonSkeets MiscUtils we can convert objects efficently return(GenericMath <TSizeType, int> .Convert(size) + AddedSize); }
private void WriteCollectionSizeToField(TContainingType obj) { //We must first access the collection to get the size and then write it into the field //before we try to truly serialize it ICollection enumerable = CollectionGetter.Getter(obj) as ICollection; if (enumerable == null) { throw new InvalidOperationException($"Tried to read the size of collection in Type: {typeof(TContainingType).Name} but did not implement {nameof(ICollection)}."); } MemberSetter.Setter(obj, GenericMath.Convert <int, TSizeType>(enumerable.Count)); }
/// <inheritdoc /> public int Read(IWireStreamReaderStrategy source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } //Read the key from the stream. TKeyType key = KeyTypeSerializerStrategy .Read(typeHandlingFlags.HasFlag(InformationHandlingFlags.DontConsumeRead) ? source.WithOnlyPeeking() : source); return(GenericMath.Convert <TKeyType, int>(key)); }
/// <inheritdoc /> public async Task <int> SizeAsync(IWireStreamReaderStrategyAsync reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } TSizeType size = await sizeSerializer.ReadAsync(reader) .ConfigureAwait(false); //Using JonSkeets MiscUtils we can convert objects efficently return(GenericMath <TSizeType, int> .Convert(size) + AddedSize); }
/// <inheritdoc /> public async Task <int> SizeAsync(IWireStreamReaderStrategyAsync reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } //Read the byte size from the stream. TSizeType result = await SizeTypeSerializerStrategy.ReadAsync(reader) .ConfigureAwait(false); //Readd the addedsize so that we know how many items are really there. return(GenericMath.Convert <TSizeType, int>(result) + AddedSize); }
public static void ResizePOT() { AssetDatabase.StartAssetEditing(); foreach (var tex in Selection.GetFiltered <Texture2D>(SelectionMode.DeepAssets)) { var xr = (int)GenericMath.NextPowerOfTwo((uint)tex.width); var yr = (int)GenericMath.NextPowerOfTwo((uint)tex.height); if (xr == tex.width && yr == tex.height) { continue; } SaveResized(tex, xr, yr, (xr - tex.width) / 2, (yr - tex.height) / 2); } AssetDatabase.StopAssetEditing(); }
/// <inheritdoc /> public void Write(int value, IWireStreamWriterStrategy dest) { if (dest == null) { throw new ArgumentNullException(nameof(dest)); } //If the key shouldn't be written then we avoid writing it //It may be that the data is needed to be left in the stream to indicate //something about the type later down the line. if (!typeHandlingFlags.HasFlag(InformationHandlingFlags.DontWrite)) { KeyTypeSerializerStrategy.Write(GenericMath.Convert <int, TKeyType>(value), dest); } }