diff --git a/Runtime/Extension/Unity/Vector/Vector2/Vector2.Extend.cs b/Runtime/Extension/Unity/Vector/Vector2/Vector2.Extend.cs
index 7e62929f..01d93be6 100644
--- a/Runtime/Extension/Unity/Vector/Vector2/Vector2.Extend.cs
+++ b/Runtime/Extension/Unity/Vector/Vector2/Vector2.Extend.cs
@@ -62,10 +62,7 @@ public static float Distance(this Vector2 source, in float x, in float y = 0)
/// 3:一个矢量和本身进行点积的结果 是该矢量的模的平方 公式:v*v=source*source+target*target+v3*v3+v.*v.=|v|²
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(this Vector2 source, in Vector2 target)
- {
- return source.x * target.x + source.y * target.y;
- }
+ public static float Dot(this Vector2 source, in Vector2 target) { return source.x * target.x + source.y * target.y; }
///
/// 点积 内积 乘积
@@ -77,10 +74,7 @@ public static float Dot(this Vector2 source, in Vector2 target)
/// 3:一个矢量和本身进行点积的结果 是该矢量的模的平方 公式:v*v=v1*v1+v2*v2+v3*v3+v.*v.=|v|²
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(this Vector2 source, in float x, in float y = 0)
- {
- return source.x * x + source.y * y;
- }
+ public static float Dot(this Vector2 source, in float x, in float y = 0) { return source.x * x + source.y * y; }
///
/// 叉积 外积
@@ -92,10 +86,7 @@ public static float Dot(this Vector2 source, in float x, in float y = 0)
/// 3:叉积不满足结合律 (a*b)*c!=a*(b*c)
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Cross(this Vector2 source, in Vector2 target)
- {
- return new Vector3(0, 0, source.x * target.y - source.y * target.x);
- }
+ public static Vector2 Cross(this Vector2 source, in Vector2 target) { return new Vector3(0, 0, source.x * target.y - source.y * target.x); }
///
/// 叉积 外积
@@ -107,18 +98,22 @@ public static Vector2 Cross(this Vector2 source, in Vector2 target)
/// 3:叉积不满足结合律 (a*b)*c!=a*(b*c)
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Cross(this Vector2 source, in float x, in float y)
- {
- return new Vector3(0, 0, source.x * y - source.y * x);
- }
+ public static Vector3 Cross(this Vector2 source, in float x, in float y) { return new Vector3(0, 0, source.x * y - source.y * x); }
///
/// 计算角度
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static double Angle(this Vector2 source, in Vector2 target)
+ public static double Angle(this Vector2 source, in Vector2 target) { return Vector2.Angle(source, target); }
+
+ ///
+ /// 是否约等于另一个向量
+ ///
+ public static Vector2Int RoundToInt(this Vector2 v)
{
- return Vector2.Angle(source, target);
+ var x = Mathf.RoundToInt(v.x);
+ var y = Mathf.RoundToInt(v.y);
+ return new Vector2Int(x, y);
}
}
-}
\ No newline at end of file
+}
diff --git a/Runtime/Extension/Unity/Vector/Vector3/Vector3.Extend.cs b/Runtime/Extension/Unity/Vector/Vector3/Vector3.Extend.cs
index c7ccdf60..47b57efd 100644
--- a/Runtime/Extension/Unity/Vector/Vector3/Vector3.Extend.cs
+++ b/Runtime/Extension/Unity/Vector/Vector3/Vector3.Extend.cs
@@ -47,9 +47,9 @@ public static float Distance(this Vector3 source, in Vector3 target)
public static Vector3 Cross(this Vector3 source, in float x, in float y, in float z)
{
return new Vector3(
- source.y * z - source.z * y,
- source.z * x - source.x * z,
- source.x * y - source.y * x);
+ source.y * z - source.z * y,
+ source.z * x - source.x * z,
+ source.x * y - source.y * x);
}
///
@@ -65,9 +65,9 @@ public static Vector3 Cross(this Vector3 source, in float x, in float y, in floa
public static Vector3 Cross(this Vector3 source, in Vector3 target)
{
return new Vector3(
- source.y * target.z - source.z * target.y,
- source.z * target.x - source.x * target.z,
- source.x * target.y - source.y * target.x);
+ source.y * target.z - source.z * target.y,
+ source.z * target.x - source.x * target.z,
+ source.x * target.y - source.y * target.x);
}
//Dot > 0 方向基本相同,夹角在0°到90°之间
@@ -84,10 +84,7 @@ public static Vector3 Cross(this Vector3 source, in Vector3 target)
/// 3:一个矢量和本身进行点积的结果 是该矢量的模的平方 公式:v*v=v1*v1+v2*v2+v3*v3+v.*v.=|v|²
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(this Vector3 source, in float x, in float y = 0, in float z = 0)
- {
- return source.x * x + source.y * y + source.z * z;
- }
+ public static float Dot(this Vector3 source, in float x, in float y = 0, in float z = 0) { return source.x * x + source.y * y + source.z * z; }
///
/// 点积 内积 乘积
@@ -99,10 +96,7 @@ public static float Dot(this Vector3 source, in float x, in float y = 0, in floa
/// 3:一个矢量和本身进行点积的结果 是该矢量的模的平方 公式:v*v=v1*v1+v2*v2+v3*v3+v.*v.=|v|²
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(this Vector3 source, in Vector3 target)
- {
- return source.x * target.x + source.y * target.y + source.z * target.z;
- }
+ public static float Dot(this Vector3 source, in Vector3 target) { return source.x * target.x + source.y * target.y + source.z * target.z; }
///
/// Is the or or NaN?
@@ -126,5 +120,16 @@ public static bool Approximately(this Vector3 sourceValue, Vector3 targetValue)
sourceValue.y.Approximately(targetValue.y) &&
sourceValue.z.Approximately(targetValue.z);
}
+
+ ///
+ /// 是否约等于另一个向量
+ ///
+ public static Vector3Int RoundToInt(this Vector3 v)
+ {
+ var x = Mathf.RoundToInt(v.x);
+ var y = Mathf.RoundToInt(v.y);
+ var z = Mathf.RoundToInt(v.z);
+ return new Vector3Int(x, y, z);
+ }
}
-}
\ No newline at end of file
+}
diff --git a/Runtime/Extension/Unity/Vector/Vector4/Vector4.Extend.cs b/Runtime/Extension/Unity/Vector/Vector4/Vector4.Extend.cs
index 415b322c..f460fef3 100644
--- a/Runtime/Extension/Unity/Vector/Vector4/Vector4.Extend.cs
+++ b/Runtime/Extension/Unity/Vector/Vector4/Vector4.Extend.cs
@@ -49,10 +49,10 @@ public static float Distance(this Vector4 source, in Vector4 target)
public static Vector4 Cross(this in Vector4 source, in Vector4 target)
{
return new Vector4(
- source.y * target.z - source.z * target.y,
- source.z * target.w - source.w * target.z,
- source.w * target.x - source.x * target.w,
- source.x * target.y - source.y * target.x);
+ source.y * target.z - source.z * target.y,
+ source.z * target.w - source.w * target.z,
+ source.w * target.x - source.x * target.w,
+ source.x * target.y - source.y * target.x);
}
///
@@ -68,10 +68,10 @@ public static Vector4 Cross(this in Vector4 source, in Vector4 target)
public static Vector4 Cross(this in Vector4 source, in float x, in float y = 0, in float z = 0, in float w = 0)
{
return new Vector4(
- source.y * z - source.z * y,
- source.z * w - source.w * z,
- source.w * x - source.x * w,
- source.x * y - source.y * x);
+ source.y * z - source.z * y,
+ source.z * w - source.w * z,
+ source.w * x - source.x * w,
+ source.x * y - source.y * x);
}
//Dot > 0 方向基本相同,夹角在0°到90°之间
@@ -107,4 +107,4 @@ public static bool IsNaN(this Vector4 vector)
float.IsNaN(vector.w);
}
}
-}
\ No newline at end of file
+}