123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using UnityEngine;
- using M = System.Math;
- namespace ARLocation
- {
- [System.Serializable]
- public struct DVector2
- {
- public double x;
- public double y;
-
-
-
-
- public double magnitude
- {
- get
- {
- return M.Sqrt(x * x + y * y);
- }
- }
-
-
-
-
- public DVector2 normalized
- {
- get
- {
- var m = magnitude;
- if (m < 0.00000001)
- {
- return new DVector2();
- }
- return new DVector2(x, y) / magnitude;
- }
- }
- public DVector2 Clone()
- {
- return new DVector2(x, y);
- }
-
-
-
-
-
- public DVector2(double x = 0.0, double y = 0.0)
- {
- this.x = x;
- this.y = y;
- }
-
-
-
-
- public Vector2 toVector2()
- {
- return new Vector2((float)x, (float)y);
- }
-
-
-
-
-
-
- public bool Equals(DVector2 v, double e = 0.00005)
- {
- return (M.Abs(x - v.x) <= e) && (M.Abs(y - v.y) <= e);
- }
-
-
-
- public void Normalize()
- {
- double m = magnitude;
- x /= m;
- y /= m;
- }
-
-
-
-
-
- public void Set(double newX = 0.0, double newY = 0.0)
- {
- x = newX;
- y = newY;
- }
-
-
-
-
- override public string ToString()
- {
- return "(" + x + ", " + y + ")";
- }
-
-
-
-
-
-
- public static double Dot(DVector2 a, DVector2 b)
- {
- return a.x * b.x + a.y * b.y;
- }
-
-
-
-
-
-
- public static double Distance(DVector2 a, DVector2 b)
- {
- return M.Sqrt(a.x * b.x + a.y * b.y);
- }
-
-
-
-
-
-
-
- public static DVector2 Lerp(DVector2 a, DVector2 b, double t)
- {
- double s = M.Max(0, M.Min(t, 1));
- return a * (1 - s) + b * s;
- }
-
-
-
-
-
-
- public static DVector2 operator *(DVector2 a, double b)
- {
- return new DVector2(
- b * a.x,
- b * a.y
- );
- }
-
-
-
-
-
-
- public static DVector2 operator /(DVector2 a, double b)
- {
- return new DVector2(
- a.x / b,
- a.y / b
- );
- }
-
-
-
-
-
-
- public static DVector2 operator +(DVector2 a, DVector2 b)
- {
- return new DVector2(
- a.x + b.x,
- a.y + b.y
- );
- }
-
-
-
-
-
-
- public static DVector2 operator -(DVector2 a, DVector2 b)
- {
- return new DVector2(
- a.x - b.x,
- a.y - b.y
- );
- }
- }
- }
|