Vector4,还真不怎么常用,偶尔用过几次而已。既然要写就全写出来吧~
Vector4d:
/// Vector4d.cs
///
/// The double type version of the Unity struct Vector4.
/// It can solve the problem that the float type may not be accurate enough.
///
/// Unity Vector4结构体的double版实现,以解决float型精度可能不够的问题。
///
/// Created by D子宇 on 2018.3.17
///
/// Email: [email protected]
using System;
using UnityEngine;
namespace Mathd
{
public struct Vector4d
{
#region public members
public double x;
public double y;
public double z;
public double w;
#endregion
#region constructor
public Vector4d(double p_x, double p_y)
{
x = p_x;
y = p_y;
z = 0;
w = 0;
}
public Vector4d(double p_x, double p_y, double p_z)
{
x = p_x;
y = p_y;
z = p_z;
w = 0;
}
public Vector4d(double p_x, double p_y, double p_z,double p_w)
{
x = p_x;
y = p_y;
z = p_z;
w = p_w;
}
#endregion
#region public properties
public double this[int index] {
get
{
switch (index)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
case 3:
return w;
default:
throw new IndexOutOfRangeException("Invalid Vector4d index!");
}
}
set
{
switch (index)
{
case 0:
x = value;
break;
case 1:
y = value;
break;
case 2:
z = value;
break;
case 3:
w = value;
break;
default:
throw new IndexOutOfRangeException("Invalid Vector4d index!");
}
}
}
public static Vector4d one
{
get
{
return new Vector4d(1, 1, 1, 1);
}
}
public static Vector4d zero
{
get
{
return new Vector4d(0, 0, 0, 0);
}
}
public double magnitude
{
get
{
return Math.Sqrt(sqrMagnitude);