Added Intersection boolean operation

This commit is contained in:
Mike Smith 2016-02-07 21:34:40 -08:00
parent 9ccf494e81
commit 8435737df5
4 changed files with 43 additions and 2 deletions

View File

@ -31,7 +31,7 @@ namespace OSCADSharp.ConsoleTests
Height = 50.8
}.Translate(10, 5, 2);
var combined = cube.Difference(cylinder);
var combined = cube.Intersection(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>
/// Creates the intersection of all child nodes
/// </summary>
internal class Intersection : BlockStatementObject
{
/// <summary>
/// Creates the intersection of all child nodes
/// </summary>
/// <param name="children"></param>
public Intersection(IEnumerable<OSCADObject> children) : base("intersection()", children)
{
}
}
}

View File

@ -147,11 +147,29 @@ namespace OSCADSharp
return doBoolean("Union", objects, (children) => { return new Union(children); });
}
/// <summary>
/// Subtracts the 2nd (and all further) child nodes from the first one (logical and not).
/// 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 Difference(params OSCADObject[] objects)
{
return doBoolean("Difference", objects, (children) => { return new Difference(children); });
}
/// <summary>
/// Creates the intersection of all child nodes. This keeps the overlapping portion (logical and).
/// Only the area which is common or shared by all children is retained.
/// 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 Intersection(params OSCADObject[] objects)
{
return doBoolean("Intersection", objects, (children) => { return new Intersection(children); });
}
private OSCADObject doBoolean(string name, OSCADObject[] objects, Func<IEnumerable<OSCADObject>, OSCADObject> factory)
{
if (objects == null || objects.Length < 1)

View File

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