Added Bounds() on OSCADObject + initial stubs in derived classes.

This commit is contained in:
Michael L Smith 2016-02-20 22:06:43 -08:00
parent 4dc79e8bc2
commit 6865c19886
15 changed files with 163 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using OSCADSharp.Booleans;
using OSCADSharp.Spatial;
using OSCADSharp.Transforms;
using System;
using System.Collections.Generic;
@ -226,7 +227,13 @@ namespace OSCADSharp
/// of the position.
/// </summary>
/// <returns></returns>
public abstract Vector3 Position();
public abstract Vector3 Position();
/// <summary>
/// Returns the approximate boundaries of this OpenSCAD object
/// </summary>
/// <returns></returns>
public abstract Bounds Bounds();
/// <summary>
/// Creates a copy of this object and all of its children

View File

@ -44,6 +44,7 @@
<ItemGroup>
<Compile Include="Ids.cs" />
<Compile Include="Sizes.cs" />
<Compile Include="Spatial\Bounds.cs" />
<Compile Include="Spatial\Matrix.cs" />
<Compile Include="Transforms\HulledObject.cs" />
<Compile Include="Transforms\IMimicer.cs" />

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Scripting
{
@ -49,5 +50,10 @@ namespace OSCADSharp.Scripting
var positions = this.children.Select(child => child.Position());
return Vector3.Average(positions.ToArray());
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Solids
{
@ -105,6 +106,15 @@ namespace OSCADSharp.Solids
return position;
}
/// <summary>
/// Returns the approximate boundaries of this OpenSCAD object
/// </summary>
/// <returns></returns>
public override Bounds Bounds()
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Solids
{
@ -118,7 +119,6 @@ namespace OSCADSharp.Solids
#endregion
#region Overrides
/// <summary>
/// Converts this object to an OpenSCAD script
/// </summary>
@ -167,6 +167,15 @@ namespace OSCADSharp.Solids
return position;
}
/// <summary>
/// Returns the approximate boundaries of this OpenSCAD object
/// </summary>
/// <returns></returns>
public override Bounds Bounds()
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Solids
{
@ -98,6 +99,15 @@ namespace OSCADSharp.Solids
{
return new Vector3();
}
/// <summary>
/// Returns the approximate boundaries of this OpenSCAD object
/// </summary>
/// <returns></returns>
public override Bounds Bounds()
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Solids
{
@ -140,6 +141,15 @@ namespace OSCADSharp.Solids
{
return new Vector3();
}
/// <summary>
/// Returns the approximate boundaries of this OpenSCAD object
/// </summary>
/// <returns></returns>
public override Bounds Bounds()
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.Spatial
{
/// <summary>
/// A set of boundaries
/// </summary>
public class Bounds
{
/// <summary>
/// Creates a set of boundaries with the corners specified
/// to define its extremities
/// </summary>
/// <param name="bottomLeft"></param>
/// <param name="topRight"></param>
public Bounds(Vector3 bottomLeft, Vector3 topRight)
{
this.BottomLeft = bottomLeft;
this.TopRight = topRight;
}
#region Public Properties
/// <summary>
/// Represents the top-right corner of the bounds (prior to any transforms)
/// </summary>
public Vector3 TopRight { get; private set; }
/// <summary>
/// Represents the bottom-left corner of the bounds (prior to any transforms)
/// </summary>
public Vector3 BottomLeft { get; private set; }
/// <summary>
/// X position with the greatest value
/// </summary>
public double X_Max { get { return TopRight.X > BottomLeft.X ? TopRight.X : BottomLeft.X; } }
/// <summary>
/// X position with the smallest value
/// </summary>
public double X_Min { get { return TopRight.X < BottomLeft.X ? TopRight.X : BottomLeft.X; } }
/// <summary>
/// Y position with the greatest value
/// </summary>
public double Y_Max { get { return TopRight.Y > BottomLeft.Y ? TopRight.Y : BottomLeft.Y; } }
/// <summary>
/// Y position with the smallest value
/// </summary>
public double Y_Min { get { return TopRight.Y < BottomLeft.Y ? TopRight.Y : BottomLeft.Y; } }
/// <summary>
/// Z position with the greatest value
/// </summary>
public double Z_Max { get { return TopRight.Z > BottomLeft.Z ? TopRight.Z : BottomLeft.Z; } }
/// <summary>
/// Z position with the smallest value
/// </summary>
public double Z_Min { get { return TopRight.Z < BottomLeft.Z ? TopRight.Z : BottomLeft.Z; } }
#endregion
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Transforms
{
@ -55,5 +56,10 @@ namespace OSCADSharp.Transforms
{
return this.obj.Position();
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Transforms
{
@ -52,5 +53,10 @@ namespace OSCADSharp.Transforms
{
throw new NotSupportedException();
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}

View File

@ -74,5 +74,10 @@ namespace OSCADSharp.Transforms
return (this.Normal.X != 0 && (this.Normal.Y != 0 || this.Normal.Z != 0)) ||
(this.Normal.Y != 0 && (this.Normal.X != 0 || this.Normal.Z != 0));
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Transforms
{
@ -53,5 +54,10 @@ namespace OSCADSharp.Transforms
{
throw new NotSupportedException("Position is not supported on Resized objects.");
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}

View File

@ -54,5 +54,10 @@ namespace OSCADSharp.Transforms
{
return Matrix.GetRotatedPoint(this.obj.Position(), this.Angle.X, this.Angle.Y, this.Angle.Z);
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Transforms
{
@ -53,5 +54,10 @@ namespace OSCADSharp.Transforms
{
return obj.Position() * this.ScaleFactor;
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
namespace OSCADSharp.Transforms
{
@ -50,5 +51,10 @@ namespace OSCADSharp.Transforms
{
return this.obj.Position() + this.Vector;
}
public override Bounds Bounds()
{
throw new NotImplementedException();
}
}
}