Vector
using Autodesk.DesignScript.Interfaces;
using System.Collections.Generic;
using System.Linq;
namespace Autodesk.DesignScript.Geometry
{
public class Vector : DesignScriptEntity
{
internal IVectorEntity VectorEntity => HostImpl as IVectorEntity;
public double X => VectorEntity.X;
public double Y => VectorEntity.Y;
public double Z => VectorEntity.Z;
public double Length => VectorEntity.Length;
internal Vector(IVectorEntity host, bool persist)
: base(host, persist)
{
}
public override string ToString()
{
return "Vector(X = " + X.ToString(GeometryExtension.DoublePrintFormat) + ", Y = " + Y.ToString(GeometryExtension.DoublePrintFormat) + ", Z = " + Z.ToString(GeometryExtension.DoublePrintFormat) + ", Length = " + Length.ToString(GeometryExtension.DoublePrintFormat) + ")";
}
protected override bool Equals(DesignScriptEntity other)
{
if (base.Equals(other))
return true;
Vector vector = other as Vector;
if (vector == null)
return false;
if (vector.X.Equals(X) && vector.Y.Equals(Y))
return vector.Z.Equals(Z);
return false;
}
protected override int ComputeHashCode()
{
int num = 17;
num = num * 23 + X.GetHashCode();
num = num * 23 + Y.GetHashCode();
return num * 23 + Z.GetHashCode();
}
internal static Vector Wrap(IVectorEntity host, bool persist = true)
{
if (host == null)
return null;
return new Vector(host, persist);
}
internal static Vector[] Wrap(IVectorEntity[] hosts, bool persist = true)
{
return (from x in hosts
select Wrap(x, persist)).ToArray();
}
internal static Vector[][] Wrap(IVectorEntity[][] hosts, bool persist = true)
{
return (from x in hosts
select Wrap(x, persist)).ToArray();
}
internal static IVectorEntity[][] Unwrap(Vector[][] o)
{
return (from x in o
select Unwrap(x)).ToArray();
}
internal static IVectorEntity[] Unwrap(Vector[] o)
{
return (from x in o
select Unwrap(x)).ToArray();
}
internal static IVectorEntity[] Unwrap(IEnumerable<Vector> o)
{
return (from x in o
select Unwrap(x)).ToArray();
}
internal static IVectorEntity Unwrap(Vector o)
{
return o.VectorEntity;
}
public static Vector ByCoordinates(double x = 0, double y = 0, double z = 0)
{
return Wrap(HostFactory.Factory.VectorByCoordinates(x, y, z), true);
}
public static Vector ByCoordinates(double x = 0, double y = 0, double z = 0, bool normalized = false)
{
return Wrap(HostFactory.Factory.VectorByCoordinates(x, y, z, normalized), true);
}
public static Vector ByTwoPoints(Point start, Point end)
{
return Wrap(HostFactory.Factory.VectorByTwoPoints(Point.Unwrap(start), Point.Unwrap(end)), true);
}
public static Vector XAxis()
{
return Wrap(HostFactory.Factory.VectorXAxis(), true);
}
public static Vector YAxis()
{
return Wrap(HostFactory.Factory.VectorYAxis(), true);
}
public static Vector ZAxis()
{
return Wrap(HostFactory.Factory.VectorZAxis(), true);
}
public Point AsPoint()
{
return Point.Wrap(VectorEntity.AsPoint(), true);
}
public Vector Reverse()
{
return Wrap(VectorEntity.Reverse(), true);
}
public Vector Add(Vector vectorToAdd)
{
return Wrap(VectorEntity.Add(Unwrap(vectorToAdd)), true);
}
public Vector Subtract(Vector vectorToSubtract)
{
return Wrap(VectorEntity.Subtract(Unwrap(vectorToSubtract)), true);
}
public Vector Cross(Vector cross)
{
return Wrap(VectorEntity.Cross(Unwrap(cross)), true);
}
public double Dot(Vector vec)
{
return VectorEntity.Dot(Unwrap(vec));
}
public Vector Normalized()
{
return Wrap(VectorEntity.Normalized(), true);
}
public bool IsParallel(Vector other)
{
return VectorEntity.IsParallel(Unwrap(other));
}
public bool IsAlmostEqualTo(Vector other)
{
return VectorEntity.IsAlmostEqualTo(Unwrap(other));
}
public Vector Transform(CoordinateSystem cs)
{
return Wrap(VectorEntity.Transform(CoordinateSystem.Unwrap(cs)), true);
}
public Vector Rotate(Vector axis, double degrees = 0)
{
return Wrap(VectorEntity.Rotate(Unwrap(axis), degrees), true);
}
public Vector Rotate(Plane origin, double degrees = 0)
{
return Wrap(VectorEntity.Rotate(Plane.Unwrap(origin), degrees), true);
}
public Vector Scale(double scale_factor = 1)
{
return Wrap(VectorEntity.Scale(scale_factor), true);
}
public Vector Scale(double xScaleFactor = 1, double yScaleFactor = 1, double zScaleFactor = 1)
{
return Wrap(VectorEntity.Scale(xScaleFactor, yScaleFactor, zScaleFactor), true);
}
public double AngleBetween(Vector otherVector)
{
return VectorEntity.AngleBetween(Unwrap(otherVector));
}
}
}