C# Creating generic Vector4 class? -
Is anyone good the way to create a normal vector 4 square in C #? I have some units (force, distance, moment, rotation, acceleration, velocity etc), which all require 3D representation and they all behave equally and hence supporting basic tasks for adding, multiplying etc. should do.
Each category includes some special cases, for example force_distance = moment so I Vector4
I am using this legacy-based approach, where every unit was found with vector 4, so far, but it creates some problems because when I add for example (force 1, force) 2), I get a base class, vector 4, instead of a force 3d, so I'm either casting or copying the add-function for each unit.
I have a I am trying every possible way, but I always try to redefine too many things. Overloading operators, a solution that tells how to do this by using a library of net sketts . To get the right type in the results of the methods, you can use something like this: Vector4 < Double & gt;
and vector 4 & lt; Force & gt; Without redefining all basic tasks for adding, multiplying, etc. (primarily with real operators, which seems impossible). It also adds some new problems because the best solution is to get the force double, but all the base types are closed, so I have to make a containerclass and instead I replace the original operators for numbers. I define.
public square vector & lt; T & gt; {Public T X {get; } Receive Public TY {}; }} Public Squared VectorWith Operators & lt; TVCutter, T & gt; : Vector & lt; T & gt; Where TVCctor: Vector & lt; T & gt;, new () Return to Public TV GetSomeResult ()} New TVector (); }} Public Class Force 3D: VectorWith Operators & lt; Force 3D, Double & gt; {}
Comments
Post a Comment