mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 21:48:34 +00:00
Several more Position implementations
This commit is contained in:
parent
8831610bda
commit
294ae7e357
@ -46,7 +46,8 @@ namespace OSCADSharp.Scripting
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var positions = this.children.Select(child => child.Position());
|
||||
return Vector3.Average(positions.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,32 @@ namespace OSCADSharp
|
||||
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
|
||||
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);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
internal Matrix ToMatrix()
|
||||
{
|
||||
double[] coords = { this.X, this.Y, this.Z, 0 };
|
||||
|
||||
@ -50,7 +50,7 @@ namespace OSCADSharp.Transforms
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ namespace OSCADSharp.Transforms
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return obj.Position();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ namespace OSCADSharp.Transforms
|
||||
|
||||
public override Vector3 Position()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return obj.Position();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user