mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-13 22:48:33 +00:00
Added Add/Subtract vector operators, and Negate and Clone methods
This commit is contained in:
parent
55bb5ba558
commit
f74592116f
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user