mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 21:48:34 +00:00
+ Removed Mimic, because it doesn't really make sense with the new Position() and Bounds() features
This commit is contained in:
parent
8c5dde2ce7
commit
511cb45b6f
@ -43,44 +43,7 @@ namespace OSCADSharp.UnitTests
|
||||
//But the child should be a different instance
|
||||
Assert.IsFalse(clone.Children().FirstOrDefault() == text.Children().FirstOrDefault());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OSCADObject_MimickedObjectHasSameTransform()
|
||||
{
|
||||
var cube = new Cube(null, true).Translate(10, 0, 5);
|
||||
var sphere = new Sphere().Mimic(cube);
|
||||
|
||||
Assert.IsTrue(sphere.GetType() == cube.GetType());
|
||||
Assert.IsTrue(cube.ToString().StartsWith("translate("));
|
||||
Assert.IsTrue(sphere.ToString().StartsWith("translate("));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OSCADObject_MimicTakesMultipleTransformsFromObject()
|
||||
{
|
||||
var cube = new Cube(null, true)
|
||||
.Translate(10, 0, 5).Rotate(0, 30, 0).Scale(1, 1.5, 1);
|
||||
var sphere = new Sphere().Mimic(cube);
|
||||
|
||||
|
||||
Assert.IsTrue(sphere.GetType() == cube.GetType());
|
||||
var mimicedChildren = sphere.Children();
|
||||
|
||||
Assert.IsTrue(mimicedChildren.ElementAt(0).ToString().StartsWith("rotate("));
|
||||
Assert.IsTrue(mimicedChildren.ElementAt(1).ToString().StartsWith("translate("));
|
||||
Assert.IsTrue(mimicedChildren.ElementAt(2).ToString().StartsWith("sphere("));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OSCADObject_MimicDoesNothingOnObjectWithNoTransforms()
|
||||
{
|
||||
var cube = new Cube(null, true);
|
||||
var sphere = new Sphere().Mimic(cube);
|
||||
|
||||
Assert.IsFalse(sphere.GetType() == cube.GetType());
|
||||
Assert.AreEqual(0, sphere.Children().Count());
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void OSCADObject_IdsAreSequentialAndDistinct()
|
||||
{
|
||||
|
||||
@ -302,33 +302,7 @@ namespace OSCADSharp
|
||||
{
|
||||
return this.Children().Where(predicate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the transforms that have been applied to another OSCADObject, and applies
|
||||
/// the same transforms to this object. (Only pure transforms, like Translate, Rotate, Scale, Color)
|
||||
/// </summary>
|
||||
/// <param name="other"></param>
|
||||
/// <returns></returns>
|
||||
public OSCADObject Mimic(OSCADObject other)
|
||||
{
|
||||
OSCADObject finalObject = this;
|
||||
|
||||
Stack<OSCADObject> toTraverse = new Stack<OSCADObject>();
|
||||
toTraverse.Push(other);
|
||||
other.Children().ToList().ForEach(child => toTraverse.Push(child));
|
||||
|
||||
while(toTraverse.Count > 0)
|
||||
{
|
||||
var current = toTraverse.Pop() as IMimic;
|
||||
if(current != null)
|
||||
{
|
||||
finalObject = current.MimicObject(finalObject);
|
||||
}
|
||||
}
|
||||
|
||||
return finalObject;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Writes the script for this OSCADObject to the file specified
|
||||
///
|
||||
|
||||
@ -47,7 +47,6 @@
|
||||
<Compile Include="Spatial\Bounds.cs" />
|
||||
<Compile Include="Spatial\Matrix.cs" />
|
||||
<Compile Include="Transforms\HulledObject.cs" />
|
||||
<Compile Include="Transforms\IMimicer.cs" />
|
||||
<Compile Include="Transforms\LinearExtrudedObject.cs" />
|
||||
<Compile Include="Scripting\SingleBlockFormatter.cs" />
|
||||
<Compile Include="Scripting\MultiBlockStatementObject.cs" />
|
||||
|
||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// An object that has color and/or opacity applied to it
|
||||
/// </summary>
|
||||
internal class ColoredObject : OSCADObject, IMimic
|
||||
internal class ColoredObject : OSCADObject
|
||||
{
|
||||
#region Attributes
|
||||
internal string ColorName { get; set; } = "Yellow";
|
||||
@ -49,12 +49,7 @@ namespace OSCADSharp.Transforms
|
||||
Name = this.Name
|
||||
};
|
||||
}
|
||||
|
||||
public OSCADObject MimicObject(OSCADObject obj)
|
||||
{
|
||||
return new ColoredObject(obj, this.ColorName, this.Opacity);
|
||||
}
|
||||
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
return this.obj.Position();
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OSCADSharp.Transforms
|
||||
{
|
||||
internal interface IMimic
|
||||
{
|
||||
OSCADObject MimicObject(OSCADObject obj);
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// An object that's mirrored on a plane
|
||||
/// </summary>
|
||||
internal class MirroredObject : OSCADObject, IMimic
|
||||
internal class MirroredObject : OSCADObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The normal vector of a plane intersecting the origin of the object,
|
||||
@ -49,11 +49,6 @@ namespace OSCADSharp.Transforms
|
||||
};
|
||||
}
|
||||
|
||||
public OSCADObject MimicObject(OSCADObject obj)
|
||||
{
|
||||
return new MirroredObject(obj, this.Normal);
|
||||
}
|
||||
|
||||
// TODO: This will yield incorrect positions if mirroring on multiple axes
|
||||
// fix mirrored positions for multiple-axis mirroring
|
||||
public override Vector3 Position()
|
||||
|
||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// An object that's been resized to a specified set of X/Y/Z dimensions
|
||||
/// </summary>
|
||||
internal class ResizedObject : OSCADObject, IMimic
|
||||
internal class ResizedObject : OSCADObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Size of the object in terms of X/Y/Z
|
||||
@ -47,12 +47,7 @@ namespace OSCADSharp.Transforms
|
||||
Name = this.Name
|
||||
};
|
||||
}
|
||||
|
||||
public OSCADObject MimicObject(OSCADObject obj)
|
||||
{
|
||||
return new ResizedObject(obj, this.Size);
|
||||
}
|
||||
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
throw new NotSupportedException("Position is not supported on Resized objects.");
|
||||
|
||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// An object with rotation applied
|
||||
/// </summary>
|
||||
internal class RotatedObject : OSCADObject, IMimic
|
||||
internal class RotatedObject : OSCADObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The angle to rotate, in terms of X/Y/Z euler angles
|
||||
@ -47,12 +47,7 @@ namespace OSCADSharp.Transforms
|
||||
Name = this.Name
|
||||
};
|
||||
}
|
||||
|
||||
public OSCADObject MimicObject(OSCADObject obj)
|
||||
{
|
||||
return new RotatedObject(obj, this.Angle);
|
||||
}
|
||||
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
return Matrix.GetRotatedPoint(this.obj.Position(), this.Angle.X, this.Angle.Y, this.Angle.Z);
|
||||
|
||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// An object that's been rescaled
|
||||
/// </summary>
|
||||
internal class ScaledObject : OSCADObject, IMimic
|
||||
internal class ScaledObject : OSCADObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The scale factor to be applied
|
||||
@ -47,12 +47,7 @@ namespace OSCADSharp.Transforms
|
||||
Name = this.Name
|
||||
};
|
||||
}
|
||||
|
||||
public OSCADObject MimicObject(OSCADObject obj)
|
||||
{
|
||||
return new ScaledObject(obj, this.ScaleFactor);
|
||||
}
|
||||
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
return obj.Position() * this.ScaleFactor;
|
||||
|
||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// An object or objects that have been moved along the specified vector
|
||||
/// </summary>
|
||||
internal class TranslatedObject : OSCADObject, IMimic
|
||||
internal class TranslatedObject : OSCADObject
|
||||
{
|
||||
internal Vector3 Vector { get; set; }
|
||||
private OSCADObject obj;
|
||||
@ -44,12 +44,7 @@ namespace OSCADSharp.Transforms
|
||||
Name = this.Name
|
||||
};
|
||||
}
|
||||
|
||||
public OSCADObject MimicObject(OSCADObject obj)
|
||||
{
|
||||
return new TranslatedObject(obj, this.Vector);
|
||||
}
|
||||
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
return this.obj.Position() + this.Vector;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user