Several more Position implementations

This commit is contained in:
Michael L Smith 2016-02-15 21:18:13 -08:00
parent 8831610bda
commit 294ae7e357
5 changed files with 32 additions and 5 deletions

View File

@ -46,7 +46,8 @@ namespace OSCADSharp.Scripting
public override Vector3 Position() public override Vector3 Position()
{ {
throw new NotImplementedException(); var positions = this.children.Select(child => child.Position());
return Vector3.Average(positions.ToArray());
} }
} }
} }

View File

@ -46,6 +46,32 @@ namespace OSCADSharp
return new Vector3(this.X, this.Y, this.Z); return new Vector3(this.X, this.Y, this.Z);
} }
/// <summary>
/// Returns the average position of the provided positions
/// </summary>
/// <param name="positions"></param>
/// <returns></returns>
public static Vector3 Average(params Vector3[] positions)
{
if(positions == null || positions.Length == 0)
{
return null;
}
else if (positions.Length == 1)
{
return positions[0];
}
var sum = new Vector3();
foreach (var pos in positions)
{
sum += pos;
}
return new Vector3(sum.X / positions.Length, sum.Y / positions.Length, sum.Z / positions.Length);
}
#region Operators/Overrides #region Operators/Overrides
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
@ -81,7 +107,7 @@ namespace OSCADSharp
return new Vector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); return new Vector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
} }
#endregion #endregion
internal Matrix ToMatrix() internal Matrix ToMatrix()
{ {
double[] coords = { this.X, this.Y, this.Z, 0 }; double[] coords = { this.X, this.Y, this.Z, 0 };

View File

@ -50,7 +50,7 @@ namespace OSCADSharp.Transforms
public override Vector3 Position() public override Vector3 Position()
{ {
throw new NotImplementedException(); throw new NotSupportedException();
} }
} }
} }

View File

@ -51,7 +51,7 @@ namespace OSCADSharp.Transforms
public override Vector3 Position() public override Vector3 Position()
{ {
throw new NotImplementedException(); return obj.Position();
} }
} }
} }

View File

@ -51,7 +51,7 @@ namespace OSCADSharp.Transforms
public override Vector3 Position() public override Vector3 Position()
{ {
throw new NotImplementedException(); return obj.Position();
} }
} }
} }