Added Add/Subtract vector operators, and Negate and Clone methods

This commit is contained in:
Mike Smith 2016-02-10 23:46:31 -08:00
parent 55bb5ba558
commit f74592116f
2 changed files with 45 additions and 1 deletions

View File

@ -33,7 +33,13 @@ namespace OSCADSharp.ConsoleTests
string script = text.ToString();
File.WriteAllLines("test.scad", new string[] { script.ToString() });
File.WriteAllLines("test.scad", new string[] { script.ToString() });
var vec1 = new Vector3(5, 5, 5);
var vec2 = new Vector3(10, 10, 10);
Console.WriteLine(vec1 - vec2);
Console.ReadKey();
}
}
}

View File

@ -13,9 +13,11 @@ namespace OSCADSharp
/// </summary>
public class Vector3
{
#region Attributes
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
#endregion
public Vector3(double x = 0, double y = 0, double z = 0)
{
@ -23,5 +25,41 @@ namespace OSCADSharp
this.Y = y;
this.Z = z;
}
/// <summary>
/// Negates the values of this vector, returning an inverse of it
/// </summary>
/// <returns>A negated vector</returns>
public Vector3 Negate()
{
return new Vector3(-this.X, -this.Y, -this.Z);
}
/// <summary>
/// Creates a copy of this vector that's a new instance
/// with the same values
/// </summary>
/// <returns>A clone of this vector</returns>
public Vector3 Clone()
{
return new Vector3(this.X, this.Y, this.Z);
}
#region Operators
public static Vector3 operator +(Vector3 left, Vector3 right)
{
return new Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
}
public static Vector3 operator -(Vector3 left, Vector3 right)
{
return new Vector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
}
#endregion
public override string ToString()
{
return String.Format("[X: {0}, Y: {1}, Z: {2}]", this.X.ToString(), this.Y.ToString(), this.Z.ToString());
}
}
}