class Triplet<scalar>
{
public scalar a, b, c;
public Triplet(scalar A, scalar B, scalar C)
{
a = A; b = B; c = C;
}
public Triplet()
{
}
public static Triplet<scalar> operator +(Triplet<scalar> A, Triplet<scalar> B)
{
return new Triplet<scalar>(A.a + B.a, A.b + B.b, A.c + B.c);
}
public static Triplet<scalar> operator /(Triplet<scalar> A, scalar divisor)
{
return new Triplet<scalar>(A.a / divisor, A.b / divisor, A.c / divisor);
}
public Triplet<scalar> Set(scalar A, scalar B, scalar C)
{
a = A; b = B; c = C;
return this;
}
/// <summary>
/// Returns true if there is a combination of the two triangles points that
/// causes them to be equal. For instance, Triangle 5 0 3 and 3 5 0 would be considered
/// equal.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if(obj.GetType() != typeof(Triplet<scalar>))
return false;
Triplet<scalar> temp = new Triplet<scalar>();
Triplet<scalar> other = (Triplet<scalar>) obj;
if(ExactEqual(this, temp.Set(other.a, other.b, other.c)))
return true;
if(ExactEqual(this, temp.Set(other.b, other.a, other.c)))
return true;
if(ExactEqual(this, temp.Set(other.a, other.c, other.b)))
return true;
if(ExactEqual(this, temp.Set(other.c, other.b, other.a)))
return true;
if(ExactEqual(this, temp.Set(other.b, other.c, other.a)))
return true;
if(ExactEqual(this, temp.Set(other.c, other.a, other.b)))
return true;
return false;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public static bool operator ==(Triplet<scalar> A, Triplet<scalar> B)
{
return Equals(A, B);
}
public static bool operator !=(Triplet<scalar> A, Triplet<scalar> B)
{
return !Equals(A, B);
}
bool ExactEqual(Triplet<scalar> a, Triplet<scalar> b)
{
if(a.a == b.a &&
a.b == b.b &&
a.c == b.c)
return true;
return false;
}
}
Quote:By the looks of it, it doesn't like me trying to use my scalar like a number. From what I read in the MSDN, I don't think there's a way around this directly. Does anyone have an idea of how I could accomplish what I'm after?
C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(22,40): error CS0019: Operator '+' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(22,51): error CS0019: Operator '+' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(22,62): error CS0019: Operator '+' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(27,40): error CS0019: Operator '/' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(27,55): error CS0019: Operator '/' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(27,70): error CS0019: Operator '/' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(89,16): error CS0019: Operator '==' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(90,16): error CS0019: Operator '==' cannot be applied to operands of type 'scalar' and 'scalar' C:\Succession\source\Workspaces\Succession\SimulationData\GeodesicMesh.cs(91,16): error CS0019: Operator '==' cannot be applied to operands of type 'scalar' and 'scalar'