I would like to make a method that "transforms" one space to another. This is quite a simple thing to template in C++ but in C# I'm not sure which interface/type or how I need to use the "where" clause in order to get the compiler to understand what I want. My C++ function looked like this:
template<class T>
T Transform(T s, T s1, T s2, T d1, T d2)
{
T result = (s - s1) / (s2 - s1) * (d2 - d1) + d1;
return result;
}
and my first stab at a generic C# version (in extension methods), looks like this:
public static T Transform<T>(T s, T s1, T s2, T d1, T d2)
{
T result = (s - s1) / (s2 - s1) * (d2 - d1) + d1;
return result;
}
Alas C# would like me to be more specific about the types, i.e.
"error CS0019: Operator '-' cannot be applied to operands of type 'T' and 'T'".
What does C# want me to do?