mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-23 03:08:28 +00:00
Added Difference boolean operation
This commit is contained in:
parent
a34992bfaa
commit
9ccf494e81
@ -31,7 +31,7 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
Height = 50.8
|
Height = 50.8
|
||||||
}.Translate(10, 5, 2);
|
}.Translate(10, 5, 2);
|
||||||
|
|
||||||
var combined = cube.Union(cylinder);
|
var combined = cube.Difference(cylinder);
|
||||||
|
|
||||||
Console.WriteLine(combined.ToString());
|
Console.WriteLine(combined.ToString());
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|||||||
22
OSCADSharp/OSCADSharp/Booleans/Difference.cs
Normal file
22
OSCADSharp/OSCADSharp/Booleans/Difference.cs
Normal 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -136,16 +136,32 @@ namespace OSCADSharp
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Boolean Operations
|
#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)
|
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)
|
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 };
|
IEnumerable<OSCADObject> children = new List<OSCADObject>() { this };
|
||||||
children = children.Concat(objects);
|
children = children.Concat(objects);
|
||||||
return new Union(children);
|
return factory(children);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="BlockFormatter.cs" />
|
<Compile Include="BlockFormatter.cs" />
|
||||||
<Compile Include="BlockStatementObject.cs" />
|
<Compile Include="BlockStatementObject.cs" />
|
||||||
|
<Compile Include="Booleans\Difference.cs" />
|
||||||
<Compile Include="Booleans\Union.cs" />
|
<Compile Include="Booleans\Union.cs" />
|
||||||
<Compile Include="OSCADObject.cs" />
|
<Compile Include="OSCADObject.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user