public void Add_3(IVec other) { BuffVec_v2 _other = new BuffVec_v2(); other.GetCoords(_other); this.Set(this.x + _other.x, this.y + _other.y, this.z + _other.z, this.w + _other.w); }
/// <summary> /// Creates a proxy class of the specified Vec*d /// </summary> /// <param name="vec"></param> /// <returns></returns> public static InputArray Create(IVec <double> vec) { if (vec == null) { throw new ArgumentNullException(nameof(vec)); } if (vec is Vec2d v2) { return(new InputArray(new [] { v2.Item0, v2.Item1 })); } if (vec is Vec3d v3) { return(new InputArray(new [] { v3.Item0, v3.Item1, v3.Item2 })); } if (vec is Vec4d v4) { return(new InputArray(new [] { v4.Item0, v4.Item1, v4.Item2, v4.Item3 })); } if (vec is Vec6d v6) { return(new InputArray(new [] { v6.Item0, v6.Item1, v6.Item2, v6.Item3, v6.Item4, v6.Item5 })); } throw new ArgumentException($"Not supported type: '{vec.GetType().Name}'", nameof(vec)); }
/// <summary> /// Creates a proxy class of the specified Vec*b /// </summary> /// <param name="vec"></param> /// <returns></returns> public static InputArray Create(IVec vec) { if (vec == null) { throw new ArgumentNullException(nameof(vec)); } return(vec switch { Vec2b v => new InputArray(new[] { v.Item0, v.Item1 }), Vec3b v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }), Vec4b v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }), Vec6b v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }), Vec2s v => new InputArray(new[] { v.Item0, v.Item1 }), Vec3s v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }), Vec4s v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }), Vec6s v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }), Vec2w v => new InputArray(new[] { v.Item0, v.Item1 }), Vec3w v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }), Vec4w v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }), Vec6w v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }), Vec2i v => new InputArray(new[] { v.Item0, v.Item1 }), Vec3i v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }), Vec4i v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }), Vec6i v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }), Vec2f v => new InputArray(new[] { v.Item0, v.Item1 }), Vec3f v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }), Vec4f v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }), Vec6f v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }), Vec2d v => new InputArray(new[] { v.Item0, v.Item1 }), Vec3d v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }), Vec4d v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }), Vec6d v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }), _ => throw new ArgumentException($"Not supported type: '{vec.GetType().Name}'", nameof(vec)) });
private static ITup_Double GetDouble(IVec v) { ITup_Double aux = v as ITup_Double; if (aux != null) { return(aux); } return(null); }
/// <summary> /// Convert to <see cref="long"/> array use <see cref="BitConverter.DoubleToInt64Bits(double)"/> /// </summary> /// <param name="vec"></param> /// <param name="length">length, -1 is auto get</param> /// <returns></returns> public static long[] ToInt64Bits(this IVec <double> vec, int length = -1) { var c = length < 0 ? vec.Count() : length; long[] output = new long[c]; for (int i = 0; i < c; i++) { output[i] = BitConverter.DoubleToInt64Bits(vec[i]); } return(output); }
/// <summary> /// /// </summary> public Test() { // Create Assembly "Aspect" which includes a proxy for an IVec interface // and the given additional interface IAdditional Weaver weaver = new Weaver("Aspect"); Type aspectType = weaver.WeaveType(typeof(IVec), new Type[] { typeof(IAdditional) }); weaver.Save(); // From the created type create an instance // assign base object and dispatcher IAspectComponent obj = (IAspectComponent)Activator.CreateInstance(aspectType); obj.BaseInstance = new Vec(); obj.AspectDispatcher = new AspectDispatcher(); // assign aspects to methods IAspect ea = new ExampleAspect(); obj.AspectDispatcher.Add(ea, typeof(IVec).GetMethod("SetX")); obj.AspectDispatcher.Add(ea, typeof(IAdditional)); // execute methods IVec vec = (IVec)obj; vec.SetX(10); Log.Info("RetVal: " + vec.SetY(15)); // and also methods implemented by additional interfaces IAdditional add = (IAdditional)obj; int x = add.method(5); Log.Info("RetVal - Additional: " + x); /*Point p = new Point(); * Debug.WriteLine(p.GetX()); * Debug.WriteLine(p.GetY()); * * AspectCompiler ac = new AspectCompiler(); * p = (Point) ac.Deploy(p, new AspectContainer()); * Debug.WriteLine(p.GetX()); * Debug.WriteLine(p.GetY()); * Debug.WriteLine("Test"); */ }
/// <summary> /// DO NOT call frequently. get count by <see cref="ArgumentOutOfRangeException"/> /// </summary> /// <param name="vec"></param> /// <returns></returns> public static int Count(this IVec <double> vec) { int i = 0; try { double tmp = 0; while (true) { tmp = vec[i]; i += 1; } } catch (ArgumentOutOfRangeException) { return(i); } }
public void Add_2(IVec other) { Vec _other = GetDouble(other).GetVec(); this.Set(this.x + _other.x, this.y + _other.y, this.z + _other.z, this.w + _other.w); }
public void Add(IVec other) { ITup_Double _other = GetDouble(other); this.Set(this.x + _other.X, this.y + _other.Y, this.z + _other.Z, this.w + _other.W); }
public Vec Add_2(IVec other) { Vec _other = GetDouble(other).GetVec(); return(new Vec(this.x + _other.x, this.y + _other.y, this.z + _other.z, this.w + _other.w)); }
public Vec Add(IVec other) { ITup_Double _other = GetDouble(other); return(new Vec(this.x + _other.X, this.y + _other.Y, this.z + _other.Z, this.w + _other.W)); }