mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-21 02:08:33 +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
@ -44,43 +44,6 @@ namespace OSCADSharp.UnitTests
|
|||||||
Assert.IsFalse(clone.Children().FirstOrDefault() == text.Children().FirstOrDefault());
|
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]
|
[TestMethod]
|
||||||
public void OSCADObject_IdsAreSequentialAndDistinct()
|
public void OSCADObject_IdsAreSequentialAndDistinct()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -303,32 +303,6 @@ namespace OSCADSharp
|
|||||||
return this.Children().Where(predicate);
|
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>
|
/// <summary>
|
||||||
/// Writes the script for this OSCADObject to the file specified
|
/// Writes the script for this OSCADObject to the file specified
|
||||||
///
|
///
|
||||||
|
|||||||
@ -47,7 +47,6 @@
|
|||||||
<Compile Include="Spatial\Bounds.cs" />
|
<Compile Include="Spatial\Bounds.cs" />
|
||||||
<Compile Include="Spatial\Matrix.cs" />
|
<Compile Include="Spatial\Matrix.cs" />
|
||||||
<Compile Include="Transforms\HulledObject.cs" />
|
<Compile Include="Transforms\HulledObject.cs" />
|
||||||
<Compile Include="Transforms\IMimicer.cs" />
|
|
||||||
<Compile Include="Transforms\LinearExtrudedObject.cs" />
|
<Compile Include="Transforms\LinearExtrudedObject.cs" />
|
||||||
<Compile Include="Scripting\SingleBlockFormatter.cs" />
|
<Compile Include="Scripting\SingleBlockFormatter.cs" />
|
||||||
<Compile Include="Scripting\MultiBlockStatementObject.cs" />
|
<Compile Include="Scripting\MultiBlockStatementObject.cs" />
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An object that has color and/or opacity applied to it
|
/// An object that has color and/or opacity applied to it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class ColoredObject : OSCADObject, IMimic
|
internal class ColoredObject : OSCADObject
|
||||||
{
|
{
|
||||||
#region Attributes
|
#region Attributes
|
||||||
internal string ColorName { get; set; } = "Yellow";
|
internal string ColorName { get; set; } = "Yellow";
|
||||||
@ -50,11 +50,6 @@ namespace OSCADSharp.Transforms
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public OSCADObject MimicObject(OSCADObject obj)
|
|
||||||
{
|
|
||||||
return new ColoredObject(obj, this.ColorName, this.Opacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
return this.obj.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>
|
/// <summary>
|
||||||
/// An object that's mirrored on a plane
|
/// An object that's mirrored on a plane
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class MirroredObject : OSCADObject, IMimic
|
internal class MirroredObject : OSCADObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The normal vector of a plane intersecting the origin of the object,
|
/// 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
|
// TODO: This will yield incorrect positions if mirroring on multiple axes
|
||||||
// fix mirrored positions for multiple-axis mirroring
|
// fix mirrored positions for multiple-axis mirroring
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An object that's been resized to a specified set of X/Y/Z dimensions
|
/// An object that's been resized to a specified set of X/Y/Z dimensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class ResizedObject : OSCADObject, IMimic
|
internal class ResizedObject : OSCADObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Size of the object in terms of X/Y/Z
|
/// Size of the object in terms of X/Y/Z
|
||||||
@ -48,11 +48,6 @@ namespace OSCADSharp.Transforms
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public OSCADObject MimicObject(OSCADObject obj)
|
|
||||||
{
|
|
||||||
return new ResizedObject(obj, this.Size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
throw new NotSupportedException("Position is not supported on Resized objects.");
|
throw new NotSupportedException("Position is not supported on Resized objects.");
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An object with rotation applied
|
/// An object with rotation applied
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class RotatedObject : OSCADObject, IMimic
|
internal class RotatedObject : OSCADObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The angle to rotate, in terms of X/Y/Z euler angles
|
/// The angle to rotate, in terms of X/Y/Z euler angles
|
||||||
@ -48,11 +48,6 @@ namespace OSCADSharp.Transforms
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public OSCADObject MimicObject(OSCADObject obj)
|
|
||||||
{
|
|
||||||
return new RotatedObject(obj, this.Angle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
return Matrix.GetRotatedPoint(this.obj.Position(), this.Angle.X, this.Angle.Y, this.Angle.Z);
|
return Matrix.GetRotatedPoint(this.obj.Position(), this.Angle.X, this.Angle.Y, this.Angle.Z);
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An object that's been rescaled
|
/// An object that's been rescaled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class ScaledObject : OSCADObject, IMimic
|
internal class ScaledObject : OSCADObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The scale factor to be applied
|
/// The scale factor to be applied
|
||||||
@ -48,11 +48,6 @@ namespace OSCADSharp.Transforms
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public OSCADObject MimicObject(OSCADObject obj)
|
|
||||||
{
|
|
||||||
return new ScaledObject(obj, this.ScaleFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
return obj.Position() * this.ScaleFactor;
|
return obj.Position() * this.ScaleFactor;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Transforms
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An object or objects that have been moved along the specified vector
|
/// An object or objects that have been moved along the specified vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class TranslatedObject : OSCADObject, IMimic
|
internal class TranslatedObject : OSCADObject
|
||||||
{
|
{
|
||||||
internal Vector3 Vector { get; set; }
|
internal Vector3 Vector { get; set; }
|
||||||
private OSCADObject obj;
|
private OSCADObject obj;
|
||||||
@ -45,11 +45,6 @@ namespace OSCADSharp.Transforms
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public OSCADObject MimicObject(OSCADObject obj)
|
|
||||||
{
|
|
||||||
return new TranslatedObject(obj, this.Vector);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
return this.obj.Position() + this.Vector;
|
return this.obj.Position() + this.Vector;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user