mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-27 21:08:29 +00:00
+ Reworked Cylinder so that if $f* values are omitted, they don't appear in output.
This commit is contained in:
parent
ddb0a319c9
commit
3a7875ee51
@ -57,5 +57,34 @@ namespace OSCADSharp.UnitTests
|
|||||||
Assert.AreEqual(new Vector3(2.5, 2.5, 10), obj.Bounds().TopRight);
|
Assert.AreEqual(new Vector3(2.5, 2.5, 10), obj.Bounds().TopRight);
|
||||||
Assert.AreEqual(new Vector3(-2.5, -2.5, -10), obj.Bounds().BottomLeft);
|
Assert.AreEqual(new Vector3(-2.5, -2.5, -10), obj.Bounds().BottomLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cylinder_ScriptOutputDoesNotContainResolutionValuesIfNotSpecified()
|
||||||
|
{
|
||||||
|
var cylinder = new Cylinder();
|
||||||
|
|
||||||
|
string script = cylinder.ToString();
|
||||||
|
|
||||||
|
Assert.IsTrue(!script.Contains("$fn"));
|
||||||
|
Assert.IsTrue(!script.Contains("$fa"));
|
||||||
|
Assert.IsTrue(!script.Contains("$fs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cylinder_ScriptOutpuHasResolutionValuesIfSpecified()
|
||||||
|
{
|
||||||
|
var cylinder = new Cylinder()
|
||||||
|
{
|
||||||
|
Resolution = 40,
|
||||||
|
MinimumAngle = 5,
|
||||||
|
MinimumCircumferentialLength = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
string script = cylinder.ToString();
|
||||||
|
|
||||||
|
Assert.IsTrue(script.Contains("$fn"));
|
||||||
|
Assert.IsTrue(script.Contains("$fa"));
|
||||||
|
Assert.IsTrue(script.Contains("$fs"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ namespace OSCADSharp.Scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
SB.Append(name);
|
SB.Append(name);
|
||||||
SB.Append("=");
|
SB.Append(" = ");
|
||||||
SB.Append(value);
|
SB.Append(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using OSCADSharp.Spatial;
|
using OSCADSharp.Spatial;
|
||||||
|
using OSCADSharp.Scripting;
|
||||||
|
|
||||||
namespace OSCADSharp.Solids
|
namespace OSCADSharp.Solids
|
||||||
{
|
{
|
||||||
@ -81,19 +82,19 @@ namespace OSCADSharp.Solids
|
|||||||
/// Minimum angle (in degrees) of each cylinder fragment.
|
/// Minimum angle (in degrees) of each cylinder fragment.
|
||||||
/// ($fa in OpenSCAD)
|
/// ($fa in OpenSCAD)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MinimumAngle { get; set; } = 12;
|
public int? MinimumAngle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Minimum circumferential length of each fragment.
|
/// Minimum circumferential length of each fragment.
|
||||||
/// ($fs in OpenSCAD)
|
/// ($fs in OpenSCAD)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MinimumCircumferentialLength { get; set; } = 2;
|
public int? MinimumCircumferentialLength { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of fragments in 360 degrees. Values of 3 or more override MinimumAngle and MinimumCircumferentialLength
|
/// Number of fragments in 360 degrees. Values of 3 or more override MinimumAngle and MinimumCircumferentialLength
|
||||||
/// ($fn in OpenSCAD)
|
/// ($fn in OpenSCAD)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Resolution { get; set; } = 0;
|
public int? Resolution { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -125,9 +126,18 @@ namespace OSCADSharp.Solids
|
|||||||
/// <returns>Script for this object</returns>
|
/// <returns>Script for this object</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("cylinder($fn = {0}, $fa = {1}, $fs = {2}, h = {3}, r1 = {4}, r2 = {5}, center = {6}); {7}",
|
var sb = new StatementBuilder();
|
||||||
Resolution.ToString(), MinimumAngle.ToString(), MinimumCircumferentialLength.ToString(),
|
sb.Append("cylinder(");
|
||||||
Height.ToString(), Radius1.ToString(), Radius2.ToString(), Center.ToString().ToLower(), Environment.NewLine);
|
sb.AppendValuePairIfExists("center", this.Center.ToString().ToLower());
|
||||||
|
sb.AppendValuePairIfExists("r1", this.Radius1, true);
|
||||||
|
sb.AppendValuePairIfExists("r2", this.Radius2, true);
|
||||||
|
sb.AppendValuePairIfExists("h", this.Height, true);
|
||||||
|
sb.AppendValuePairIfExists("$fn", this.Resolution, true);
|
||||||
|
sb.AppendValuePairIfExists("$fa", this.MinimumAngle, true);
|
||||||
|
sb.AppendValuePairIfExists("$fs", this.MinimumCircumferentialLength, true);
|
||||||
|
sb.Append(");");
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -145,6 +145,7 @@ namespace OSCADSharp.Solids
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the approximate boundaries of this OpenSCAD object
|
/// Returns the approximate boundaries of this OpenSCAD object
|
||||||
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Bounds Bounds()
|
public override Bounds Bounds()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user