using OSCADSharp.Scripting; using OSCADSharp.Spatial; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OSCADSharp.Transforms { /// /// An object with rotation applied /// internal class RotatedObject : SingleStatementObject { /// /// The angle to rotate, in terms of X/Y/Z euler angles /// internal Vector3 Angle { get; set; } = new Vector3(); /// /// Creates an object with rotation applied /// /// The object being rotated /// The angle to rotate internal RotatedObject(OSCADObject obj, Vector3 angle) : base(obj) { this.Angle = angle; } public override string ToString() { string rotateCommand = String.Format("rotate([{0}, {1}, {2}])", this.Angle.X.ToString(), this.Angle.Y.ToString(), this.Angle.Z.ToString()); var formatter = new SingleBlockFormatter(rotateCommand, this.obj.ToString()); return formatter.ToString(); } public override OSCADObject Clone() { return new RotatedObject(this.obj.Clone(), this.Angle) { Name = this.Name }; } public override Vector3 Position() { return Matrix.GetRotatedPoint(this.obj.Position(), this.Angle.X, this.Angle.Y, this.Angle.Z); } public override Bounds Bounds() { var oldBounds = obj.Bounds(); return new Bounds(Matrix.GetRotatedPoint(oldBounds.BottomLeft, this.Angle.X, this.Angle.Y, this.Angle.Z), Matrix.GetRotatedPoint(oldBounds.TopRight, this.Angle.X, this.Angle.Y, this.Angle.Z)); } } }