mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-27 12:58:27 +00:00
Added Union (first Boolean operation)
This commit is contained in:
parent
584049346f
commit
efc981579f
@ -25,7 +25,15 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
.Scale(1, 1, 2)
|
.Scale(1, 1, 2)
|
||||||
.Translate(10, 5, 2);
|
.Translate(10, 5, 2);
|
||||||
|
|
||||||
Console.WriteLine(cube.ToString());
|
OSCADObject cylinder = new Cylinder()
|
||||||
|
{
|
||||||
|
Diameter = 25.4,
|
||||||
|
Height = 50.8
|
||||||
|
}.Translate(10, 5, 2);
|
||||||
|
|
||||||
|
var combined = cube.Union(cylinder);
|
||||||
|
|
||||||
|
Console.WriteLine(combined.ToString());
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
OSCADSharp/OSCADSharp/Booleans/Union.cs
Normal file
38
OSCADSharp/OSCADSharp/Booleans/Union.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp.Booleans
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A union of child nodes. This is the sum of all children (logical or).
|
||||||
|
/// </summary>
|
||||||
|
internal class Union : OSCADObject
|
||||||
|
{
|
||||||
|
private IEnumerable<OSCADObject> children;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a union that is the combination of all children
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="children">OSCADObjects to combine</param>
|
||||||
|
internal Union(IEnumerable<OSCADObject> children)
|
||||||
|
{
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string unionCommand = "union()";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
foreach (var child in this.children)
|
||||||
|
{
|
||||||
|
sb.AppendLine(child.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
var formatter = new BlockFormatter(unionCommand, sb.ToString());
|
||||||
|
return formatter.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using OSCADSharp.Transforms;
|
using OSCADSharp.Booleans;
|
||||||
|
using OSCADSharp.Transforms;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -133,5 +134,19 @@ namespace OSCADSharp
|
|||||||
return this.Translate(new Vector3(x, y, z));
|
return this.Translate(new Vector3(x, y, z));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Boolean Operations
|
||||||
|
public OSCADObject Union(params OSCADObject[] objects)
|
||||||
|
{
|
||||||
|
if (objects == null || objects.Length < 1)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Union requires at least one non-null entities");
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<OSCADObject> children = new List<OSCADObject>() { this };
|
||||||
|
children = children.Concat(objects);
|
||||||
|
return new Union(children);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="BlockFormatter.cs" />
|
<Compile Include="BlockFormatter.cs" />
|
||||||
|
<Compile Include="Booleans\Union.cs" />
|
||||||
<Compile Include="OSCADObject.cs" />
|
<Compile Include="OSCADObject.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Solids\Cube.cs" />
|
<Compile Include="Solids\Cube.cs" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user