// Token: 0x060003FC RID: 1020 RVA: 0x00011CEC File Offset: 0x0000FEEC
        public bool Test()
        {
            Vector2 vector = this.segment.Origin - this.box.Center;

            double[] array  = new double[2];
            double[] array2 = new double[2];
            array[0]  = Math.Abs(this.segment.Direction.Dot(this.box.Axis0));
            array2[0] = Math.Abs(vector.Dot(this.box.Axis0));
            double num = this.box.Extent0 + this.segment.Extent * array[0];

            if (array2[0] > num + 1E-08)
            {
                return(false);
            }
            array[1]  = Math.Abs(this.segment.Direction.Dot(this.box.Axis1));
            array2[1] = Math.Abs(vector.Dot(this.box.Axis1));
            num       = this.box.Extent1 + this.segment.Extent * array[1];
            if (array2[1] > num + 1E-08)
            {
                return(false);
            }
            UnitVector2 unitVector = this.segment.Direction.Perpendicular();
            double      num2       = Math.Abs(unitVector.Dot(vector));
            double      num3       = Math.Abs(unitVector.Dot(this.box.Axis0));
            double      num4       = Math.Abs(unitVector.Dot(this.box.Axis1));

            num = this.box.Extent0 * num3 + this.box.Extent1 * num4;
            return(num2 < num + 1E-08);
        }
Exemple #2
0
        internal static bool DoClipping(double t0, double t1, Vector2 origin, UnitVector2 direction, Box2 box, bool solid, out int quantity, out Vector2 point0, out Vector2 point1, out Intersection.Type intrType)
        {
            Vector2 vector  = origin - box.Center;
            Vector2 vector2 = new Vector2(vector.Dot(box.Axis0), vector.Dot(box.Axis1));
            Vector2 vector3 = new Vector2(direction.Dot(box.Axis0), direction.Dot(box.Axis1));
            double  num     = t0;
            double  num2    = t1;
            bool    flag    = Intersection.Clip(vector3.X, -vector2.X - box.Extent0, ref t0, ref t1) && Intersection.Clip(-vector3.X, vector2.X - box.Extent0, ref t0, ref t1) && Intersection.Clip(vector3.Y, -vector2.Y - box.Extent1, ref t0, ref t1) && Intersection.Clip(-vector3.Y, vector2.Y - box.Extent1, ref t0, ref t1);

            point0 = Vector2.Zero;
            point1 = Vector2.Zero;
            if (flag && (solid || t0 != num || t1 != num2))
            {
                if (t1 > t0)
                {
                    intrType = Intersection.Type.IT_SEGMENT;
                    quantity = 2;
                    point0   = origin + t0 * direction;
                    point1   = origin + t1 * direction;
                }
                else
                {
                    intrType = Intersection.Type.IT_POINT;
                    quantity = 1;
                    point0   = origin + t0 * direction;
                }
            }
            else
            {
                intrType = Intersection.Type.IT_EMPTY;
                quantity = 0;
            }
            return(intrType > Intersection.Type.IT_EMPTY);
        }
        // Token: 0x060004C7 RID: 1223 RVA: 0x00018A10 File Offset: 0x00016C10
        public static Line2 Transform(this AffineTransform2 transformer, Line2 line)
        {
            Vector2     origin    = transformer.Transform(line.Origin);
            UnitVector2 direction = transformer.Transform(line.Direction);

            return(new Line2(origin, direction));
        }
Exemple #4
0
 // Token: 0x0600035F RID: 863 RVA: 0x0000E6D8 File Offset: 0x0000C8D8
 internal static void TriangleLineRelations(Vector2 origin, UnitVector2 direction, Triangle2 triangle, ref double[] dist, ref int[] sign, out int positive, out int negative, out int zero)
 {
     positive = 0;
     negative = 0;
     zero     = 0;
     for (int i = 0; i < 3; i++)
     {
         Vector2 vector = triangle[i] - origin;
         dist[i] = vector.DotPerpendicular((Vector2)direction);
         if (dist[i] > 1E-08)
         {
             sign[i] = 1;
             positive++;
         }
         else if (dist[i] < -1E-08)
         {
             sign[i] = -1;
             negative++;
         }
         else
         {
             dist[i] = 0.0;
             sign[i] = 0;
             zero++;
         }
     }
 }
        // Token: 0x060004C9 RID: 1225 RVA: 0x00018A70 File Offset: 0x00016C70
        public static Ray2 Transform(this AffineTransform2 transformer, Ray2 ray)
        {
            Vector2     origin    = transformer.Transform(ray.Origin);
            UnitVector2 direction = transformer.Transform(ray.Direction);

            return(new Ray2(origin, direction));
        }
        // Token: 0x060004CB RID: 1227 RVA: 0x00018AE0 File Offset: 0x00016CE0
        public static Segment2 Transform(this AffineTransform2 transformer, Segment2 segment)
        {
            Vector2     origin    = transformer.Transform(segment.Origin);
            UnitVector2 direction = transformer.Transform(segment.Direction);

            return(new Segment2(origin, direction, transformer.Scale * segment.Extent));
        }
        /// <summary>
        /// 执行当前的节点检测
        /// </summary>
        /// <param name="p0"></param>
        /// <param name="d0"></param>
        /// <param name="p1"></param>
        /// <param name="d1"></param>
        /// <param name="dotThreshold"></param>
        /// <param name="s"></param>
        /// <returns></returns>
        internal static Intersection.Type Classify(Vector2 p0, UnitVector2 d0, Vector2 p1, UnitVector2 d1, double dotThreshold, ref double[] s)
        {
            Vector2 vector = p1 - p0;
            //进行叉乘
            double num = d0.DotPerpendicular(d1);

            if (Math.Abs(num) > dotThreshold)
            {
                if (s.Length >= 2)
                {
                    double num2 = 1.0 / num;
                    double num3 = vector.DotPerpendicular((Vector2)d0);
                    double num4 = vector.DotPerpendicular((Vector2)d1);
                    s[0] = num4 * num2;
                    s[1] = num3 * num2;
                }
                return(Intersection.Type.IT_POINT);
            }
            UnitVector2 unitVector;

            if (!vector.TryGetNormalized(out unitVector))
            {
                return(Intersection.Type.IT_LINE);
            }
            if (Math.Abs(unitVector.DotPerpendicular(d1)) <= dotThreshold)
            {
                return(Intersection.Type.IT_LINE);
            }
            return(Intersection.Type.IT_EMPTY);
        }
Exemple #8
0
        // Token: 0x060002F3 RID: 755 RVA: 0x0000BD54 File Offset: 0x00009F54
        internal static bool Find(Vector2 origin, UnitVector2 direction, Vector2 center, double radius, out int rootCount, out double[] t)
        {
            t = new double[2];
            Vector2 vector = origin - center;
            double  num    = vector.SquaredLength - radius * radius;
            double  num2   = direction.Dot(vector);
            double  num3   = num2;
            double  num4   = num3 * num3 - num;

            if (num4 > 1E-08)
            {
                rootCount = 2;
                num4      = Math.Sqrt(num4);
                t[0]      = -num2 - num4;
                t[1]      = -num2 + num4;
            }
            else if (num4 < -1E-08)
            {
                rootCount = 0;
            }
            else
            {
                rootCount = 1;
                t[0]      = -num2;
            }
            return(rootCount != 0);
        }
        // Token: 0x060004B1 RID: 1201 RVA: 0x00018060 File Offset: 0x00016260
        public static AffineTransform2 GetInversed(this AffineTransform2 transform)
        {
            UnitVector2 axisX  = new UnitVector2(transform.AxisX.X, transform.AxisY.X);
            UnitVector2 axisY  = new UnitVector2(transform.AxisX.Y, transform.AxisY.Y);
            Vector2     origin = new Vector2(-transform.AxisX.Dot(transform.Origin), -transform.AxisY.Dot(transform.Origin)) / transform.Scale;

            return(new AffineTransform2(axisX, axisY, origin, 1.0 / transform.Scale));
        }
Exemple #10
0
 // Token: 0x060001C7 RID: 455 RVA: 0x0000A0C3 File Offset: 0x000082C3
 public Segment2(Vector2 origin, UnitVector2 direction, double extent)
 {
     this = default(Segment2);
     MathBase.AssertValid(extent);
     this.Origin    = origin;
     this.Direction = direction;
     this.Extent    = extent;
 }
        // Token: 0x06000352 RID: 850 RVA: 0x0000E29C File Offset: 0x0000C49C
        public bool Test()
        {
            Vector2     vector     = this.line.Origin - this.box.Center;
            UnitVector2 unitVector = this.line.Direction.Perpendicular();
            double      num        = Math.Abs(unitVector.Dot(vector));
            double      num2       = Math.Abs(unitVector.Dot(this.box.Axis0));
            double      num3       = Math.Abs(unitVector.Dot(this.box.Axis1));
            double      num4       = this.box.Extent0 * num2 + this.box.Extent1 * num3;

            return(num < num4 + 1E-08);
        }
Exemple #12
0
        public bool TryGetNormalized(out UnitVector2 normalized)
        {
            double length = this.Length;

            if (length > 1E-08)
            {
                normalized = new UnitVector2(this.x / length, this.y / length);
                return(true);
            }
            normalized = UnitVector2.UnitX;
            return(false);
        }
Exemple #13
0
        // Token: 0x06000360 RID: 864 RVA: 0x0000E774 File Offset: 0x0000C974
        internal static void GetInterval(Vector2 origin, UnitVector2 direction, Triangle2 triangle, double[] dist, int[] sign, ref double[] param)
        {
            double[] array = new double[3];
            for (int i = 0; i < 3; i++)
            {
                Vector2 vector = triangle[i] - origin;
                array[i] = direction.Dot(vector);
            }
            int num  = 0;
            int num2 = 2;
            int j    = 0;

            while (j < 3)
            {
                if (sign[num2] * sign[j] < 0)
                {
                    MathBase.Assert(num < 2, "Line2Triangle2.GetInterval(): iQuantity < 2 failed");
                    double num3 = dist[num2] * array[j] - dist[j] * array[num2];
                    double num4 = dist[num2] - dist[j];
                    param[num++] = num3 / num4;
                }
                num2 = j++;
            }
            if (num < 2)
            {
                int k = 0;
                while (k < 3)
                {
                    if (sign[k] == 0)
                    {
                        MathBase.Assert(num < 2, "Line2Triangle2.GetInterval(): iQuantity < 2 failed");
                        param[num++] = array[k];
                    }
                    int num5 = k++;
                }
            }
            MathBase.Assert(num >= 1, "Line2Triangle2.GetInterval(): iQuantity >= 1 failed");
            if (num == 2)
            {
                if (param[0] > param[1])
                {
                    double num6 = param[0];
                    param[0] = param[1];
                    param[1] = num6;
                    return;
                }
            }
            else
            {
                param[1] = param[0];
            }
        }
Exemple #14
0
 public AffineTransform2(UnitVector2 axisX, UnitVector2 axisY, Vector2 origin, double scale)
 {
     this = default(AffineTransform2);
     MathBase.Assert(Math.Abs(axisX.Dot(axisY)) < 1E-08, "AffineTransform2 constructor: axes not perpendicular.");
     if (axisX.Dot(UnitVector2.UnitX) >= 0.0)
     {
         MathBase.Assert(axisY.Dot(UnitVector2.UnitY) >= 0.0, "AffineTransform2 constructor: axes not right-handed.");
     }
     else
     {
         MathBase.Assert(axisY.Dot(UnitVector2.UnitY) < 0.0, "AffineTransform2 constructor: axes not right-handed.");
     }
     this.AxisX  = axisX;
     this.AxisY  = axisY;
     this.Scale  = scale;
     this.Origin = origin;
 }
Exemple #15
0
 // Token: 0x0600007F RID: 127 RVA: 0x00003480 File Offset: 0x00001680
 public Box2(Vector2 center, UnitVector2 axis0, UnitVector2 axis1, double extent0, double extent1)
 {
     this = default(Box2);
     MathBase.Assert(Math.Abs(axis0.Dot(axis1)) < 1E-08, "Box2 constructor: axes not perpendicular.");
     if (axis0.Dot(UnitVector2.UnitX) >= 0.0)
     {
         MathBase.Assert(axis1.Dot(UnitVector2.UnitY) >= 0.0, "Box2 constructor: axes not right-handed.");
     }
     else
     {
         MathBase.Assert(axis1.Dot(UnitVector2.UnitY) < 0.0, "Box2 constructor: axes not right-handed.");
     }
     this.Center  = center;
     this.Axis0   = axis0;
     this.Axis1   = axis1;
     this.Extent0 = extent0;
     this.Extent1 = extent1;
 }
Exemple #16
0
        // Token: 0x0600032A RID: 810 RVA: 0x0000CF30 File Offset: 0x0000B130
        public bool Test()
        {
            UnitVector2 axis    = this.box0.Axis0;
            UnitVector2 axis2   = this.box0.Axis1;
            UnitVector2 axis3   = this.box1.Axis0;
            UnitVector2 axis4   = this.box1.Axis1;
            double      extent  = this.box0.Extent0;
            double      extent2 = this.box0.Extent1;
            double      extent3 = this.box1.Extent0;
            double      extent4 = this.box1.Extent1;
            Vector2     vector  = this.box1.Center - this.box0.Center;

            double[,] array = new double[2, 2];
            array[0, 0]     = Math.Abs(axis.Dot(axis3));
            array[0, 1]     = Math.Abs(axis.Dot(axis4));
            double num  = Math.Abs(axis.Dot(vector));
            double num2 = extent + extent3 * array[0, 0] + extent4 * array[0, 1];

            if (num > num2)
            {
                return(false);
            }
            array[1, 0] = Math.Abs(axis2.Dot(axis3));
            array[1, 1] = Math.Abs(axis2.Dot(axis4));
            double num3 = Math.Abs(axis2.Dot(vector));

            num2 = extent2 + extent3 * array[1, 0] + extent4 * array[1, 1];
            if (num3 > num2)
            {
                return(false);
            }
            double num4 = Math.Abs(axis3.Dot(vector));

            num2 = extent3 + extent * array[0, 0] + extent2 * array[1, 0];
            if (num4 > num2)
            {
                return(false);
            }
            double num5 = Math.Abs(axis4.Dot(vector));

            num2 = extent4 + extent * array[0, 1] + extent2 * array[1, 1];
            return(num5 <= num2);
        }
        // Token: 0x060004B3 RID: 1203 RVA: 0x00018118 File Offset: 0x00016318
        public static AffineTransform2 Transform(this AffineTransform2 transformer, AffineTransform2 source)
        {
            UnitVector2 axisX   = transformer.AxisX;
            UnitVector2 axisY   = transformer.AxisY;
            double      scale   = transformer.Scale;
            UnitVector2 axisX2  = source.AxisX;
            UnitVector2 axisY2  = source.AxisY;
            Vector2     origin  = transformer.Origin;
            Vector2     origin2 = source.Origin;
            double      x       = axisX.X * axisX2.X + axisY.X * axisX2.Y;
            double      x2      = axisX.X * axisY2.X + axisY.X * axisY2.Y;
            double      y       = axisX.Y * axisX2.X + axisY.Y * axisX2.Y;
            double      y2      = axisX.Y * axisY2.X + axisY.Y * axisY2.Y;
            double      x3      = scale * (axisX.X * origin2.X + axisY.X * origin2.Y) + origin.X;
            double      y3      = scale * (axisX.Y * origin2.X + axisY.Y * origin2.Y) + origin.Y;
            UnitVector2 axisX3  = new UnitVector2(x, y);
            UnitVector2 axisY3  = new UnitVector2(x2, y2);
            Vector2     origin3 = new Vector2(x3, y3);

            return(new AffineTransform2(axisX3, axisY3, origin3, transformer.Scale * source.Scale));
        }
Exemple #18
0
 public double Dot(UnitVector2 vector)
 {
     return(vector.X * this.X + vector.Y * this.Y);
 }
Exemple #19
0
 // Token: 0x060000C6 RID: 198 RVA: 0x000043B3 File Offset: 0x000025B3
 public Ray2(Vector2 origin, UnitVector2 direction)
 {
     this           = default(Ray2);
     this.Origin    = origin;
     this.Direction = direction;
 }
 // Token: 0x060004B7 RID: 1207 RVA: 0x00018380 File Offset: 0x00016580
 public static UnitVector2 Transform(this AffineTransform2 transformer, UnitVector2 input)
 {
     return((transformer.AxisX * input.X + transformer.AxisY * input.Y).GetNormalized());
 }
Exemple #21
0
 // Token: 0x0600021C RID: 540 RVA: 0x0000B054 File Offset: 0x00009254
 public double Dot(UnitVector2 vector)
 {
     return(this.v.Dot((Vector2)vector));
 }
Exemple #22
0
 // Token: 0x0600021F RID: 543 RVA: 0x0000B0D8 File Offset: 0x000092D8
 public bool Equals(UnitVector2 other)
 {
     return(this.v.Equals(other.v));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="unitVector"></param>
 /// <param name="other"></param>
 /// <returns></returns>
 public static double DotPerpendicular(this UnitVector2 unitVector, UnitVector2 other)
 {
     return(unitVector.X * other.Y - unitVector.Y * other.X);
 }
Exemple #24
0
 public Line2(Vector2 origin, UnitVector2 direction)
 {
     this           = default(Line2);
     this.Origin    = origin;
     this.Direction = direction;
 }