Added Difference boolean operation

This commit is contained in:
Mike Smith 2016-02-07 21:29:41 -08:00
parent a34992bfaa
commit 9ccf494e81
4 changed files with 42 additions and 3 deletions

View File

@ -31,7 +31,7 @@ namespace OSCADSharp.ConsoleTests
Height = 50.8
}.Translate(10, 5, 2);
var combined = cube.Union(cylinder);
var combined = cube.Difference(cylinder);
Console.WriteLine(combined.ToString());
Console.ReadKey();

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.Booleans
{
/// <summary>
/// Subtracts the 2nd (and all further) child nodes from the first one (logical and not).
/// </summary>
internal class Difference : BlockStatementObject
{
/// <summary>
/// Creates a subtraction of child nodes
/// </summary>
/// <param name="children"></param>
public Difference(IEnumerable<OSCADObject> children) : base("difference()", children)
{
}
}
}

View File

@ -136,16 +136,32 @@ namespace OSCADSharp
#endregion
#region Boolean Operations
/// <summary>
/// Creates a union of all its child nodes. This is the sum of all children (logical or).
/// May be used with either 2D or 3D objects, but don't mix them.
/// </summary>
/// <param name="objects">child nodes</param>
/// <returns></returns>
public OSCADObject Union(params OSCADObject[] objects)
{
return doBoolean("Union", objects, (children) => { return new Union(children); });
}
public OSCADObject Difference(params OSCADObject[] objects)
{
return doBoolean("Difference", objects, (children) => { return new Difference(children); });
}
private OSCADObject doBoolean(string name, OSCADObject[] objects, Func<IEnumerable<OSCADObject>, OSCADObject> factory)
{
if (objects == null || objects.Length < 1)
{
throw new ArgumentException("Union requires at least one non-null entities");
throw new ArgumentException(name + " requires at least one non-null entities");
}
IEnumerable<OSCADObject> children = new List<OSCADObject>() { this };
children = children.Concat(objects);
return new Union(children);
return factory(children);
}
#endregion
}

View File

@ -42,6 +42,7 @@
<ItemGroup>
<Compile Include="BlockFormatter.cs" />
<Compile Include="BlockStatementObject.cs" />
<Compile Include="Booleans\Difference.cs" />
<Compile Include="Booleans\Union.cs" />
<Compile Include="OSCADObject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />