mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 21:48:34 +00:00
Added numerical negation operator on variables
This commit is contained in:
parent
a048f8baa1
commit
61fc5cf227
@ -222,5 +222,22 @@ namespace OSCADSharp.UnitTests
|
||||
Assert.IsTrue(script.Contains("d2 = mainColumn"));
|
||||
Assert.IsTrue(script.Contains("h = overallHeight"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Cylinder_NegationOnConstructorVariablesProvidesExpectedOutput()
|
||||
{
|
||||
Variable wheelThickness = new Variable("wheelThickness", Inches.Eigth + Inches.Sixteenth);
|
||||
Variable wheelDiameter = new Variable("wheelDiameter", Inches.ToMillimeters(1.5));
|
||||
Variable wheelHoleDiameter = new Variable("wheelHoleDiameter", Inches.Quarter);
|
||||
|
||||
OSCADObject cyl = new Cylinder(wheelHoleDiameter - 1, wheelHoleDiameter - 1, wheelThickness + 2)
|
||||
.Translate(0, -wheelDiameter / 2 + wheelHoleDiameter / 2, 0);
|
||||
|
||||
string script = cyl.ToString();
|
||||
|
||||
Assert.IsTrue(script.Contains("translate(v = [0, -wheelDiameter / 2 + wheelHoleDiameter / 2, 0])"));
|
||||
Assert.IsTrue(script.Contains("cylinder(center = false, d1 = wheelHoleDiameter - 1, d2 = wheelHoleDiameter - 1, h = wheelThickness + 2);"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,6 +113,27 @@ namespace OSCADSharp.Scripting
|
||||
return new Variable(String.Format("{0} - {1}", left.Name, right.Name), VariableCalculator.Subtract(left.Value, right.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Numerical negation on a variable
|
||||
/// </summary>
|
||||
/// <param name="right"></param>
|
||||
/// <returns></returns>
|
||||
public static Variable operator -(Variable right)
|
||||
{
|
||||
object value = null;
|
||||
|
||||
if (VariableCalculator.IsNumeric(right.Value))
|
||||
{
|
||||
value = -Convert.ToDouble(right.Value);
|
||||
}
|
||||
else if(VariableCalculator.IsVector(right.Value))
|
||||
{
|
||||
value = ((Vector3)right.Value).Negate();
|
||||
}
|
||||
|
||||
return new Variable(String.Format("-{0}", right.Name), value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts a value from a variable
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user