示例#1
0
        public void TestConvert_Int()
        {
            // 2D - vectors

            {
                ITuple2_Float v = VectorUtils.Convert <ITuple2_Float>(new Vector2i(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Integer v = VectorUtils.Convert <ITuple2_Integer>(new Vector2i(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Byte v = VectorUtils.Convert <ITuple2_Byte>(new Vector2i(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }

            // 2D - points

            {
                ITuple2_Float v = VectorUtils.Convert <ITuple2_Float>(new Point2i(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Integer v = VectorUtils.Convert <ITuple2_Integer>(new Point2i(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Byte v = VectorUtils.Convert <ITuple2_Byte>(new Point2i(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
        }
示例#2
0
        public static ITuple2_Integer AsTupleInteger(this IVector2 v)
        {
            ITuple2_Integer ret = v as ITuple2_Integer;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <ITuple2_Integer>(v));
        }
示例#3
0
        public static IOpTuple4_Integer AsOpTupleInteger(this IOpTuple4 v)
        {
            IOpTuple4_Integer ret = v as IOpTuple4_Integer;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <IOpTuple4_Integer>(v));
        }
示例#4
0
        public static ITuple4_Byte AsTupleByte(this IColor4 v)
        {
            ITuple4_Byte ret = v as ITuple4_Byte;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <ITuple4_Byte>(v));
        }
示例#5
0
        public static IOpTuple4_Byte AsOpTupleByte(this IOpTuple4 v)
        {
            IOpTuple4_Byte ret = v as IOpTuple4_Byte;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <IOpTuple4_Byte>(v));
        }
示例#6
0
        public static ITuple4_Float AsTupleFloat(this IColor4 v)
        {
            ITuple4_Float ret = v as ITuple4_Float;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <IColor4, ITuple4_Float>(v));
        }
示例#7
0
        public static IOpTuple4_Float AsOpTupleFloat(this IOpTuple4 v)
        {
            IOpTuple4_Float ret = v as IOpTuple4_Float;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <IOpTuple4_Float>(v));
        }
示例#8
0
        public static ITuple2_Double AsTupleDouble(this IPoint2 v)
        {
            ITuple2_Double ret = v as ITuple2_Double;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <ITuple2_Double>(v));
        }
示例#9
0
        public static IOpTuple3_Double AsOpTupleDouble(this IOpTuple3 v)
        {
            IOpTuple3_Double ret = v as IOpTuple3_Double;

            if (ret != null)
            {
                return(ret);
            }
            return(VectorUtils.Convert <IOpTuple3_Double>(v));
        }
示例#10
0
        public void TestConvert_ColorByte()
        {
            // Colors

            {
                ITuple3_Float v = VectorUtils.Convert <ITuple3_Float>(new Color3b(0, 128, 255));
                Assert.IsTrue(v.X.EpsilonEquals(0) && v.Y.EpsilonEquals(0.5f, 0.01f) && v.Z.EpsilonEquals(1));
            }
            {
                ITuple3_Byte v = VectorUtils.Convert <ITuple3_Byte>(new Color3b(0, 128, 255));
                Assert.IsTrue(v.X == 0 && v.Y == 128 && v.Z == 255);
            }
        }
示例#11
0
        public void TestConvert_Double()
        {
            // 2D - vectors

            {
                ITuple2_Float v = VectorUtils.Convert <ITuple2_Float>(new Vector2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Integer v = VectorUtils.Convert <ITuple2_Integer>(new Vector2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Byte v = VectorUtils.Convert <ITuple2_Byte>(new Vector2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }

            {
                ITuple2_Float v = VectorUtils.Convert <ITuple2_Float>(new BuffVector2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Integer v = VectorUtils.Convert <ITuple2_Integer>(new BuffVector2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Byte v = VectorUtils.Convert <ITuple2_Byte>(new BuffVector2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }

            // 2D - points

            {
                ITuple2_Float v = VectorUtils.Convert <ITuple2_Float>(new Point2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Integer v = VectorUtils.Convert <ITuple2_Integer>(new Point2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Byte v = VectorUtils.Convert <ITuple2_Byte>(new Point2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }

            {
                ITuple2_Float v = VectorUtils.Convert <ITuple2_Float>(new BuffPoint2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Integer v = VectorUtils.Convert <ITuple2_Integer>(new BuffPoint2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }
            {
                ITuple2_Byte v = VectorUtils.Convert <ITuple2_Byte>(new BuffPoint2d(1, 2));
                Assert.IsTrue(v.X == 1 && v.Y == 2);
            }

            // 3D - vectors

            {
                ITuple3_Float v = VectorUtils.Convert <ITuple3_Float>(new Vector3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }
            {
                ITuple3_Byte v = VectorUtils.Convert <ITuple3_Byte>(new Vector3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }

            {
                ITuple3_Float v = VectorUtils.Convert <ITuple3_Float>(new BuffVector3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }
            {
                ITuple3_Byte v = VectorUtils.Convert <ITuple3_Byte>(new BuffVector3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }

            // 3D - points

            {
                ITuple3_Float v = VectorUtils.Convert <ITuple3_Float>(new Point3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }
            {
                ITuple3_Byte v = VectorUtils.Convert <ITuple3_Byte>(new Point3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }

            {
                ITuple3_Float v = VectorUtils.Convert <ITuple3_Float>(new BuffPoint3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }
            {
                ITuple3_Byte v = VectorUtils.Convert <ITuple3_Byte>(new BuffPoint3d(1, 2, 3));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3);
            }

            // 4D - vectors

            {
                ITuple4_Float v = VectorUtils.Convert <ITuple4_Float>(new Vector4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }
            {
                ITuple4_Byte v = VectorUtils.Convert <ITuple4_Byte>(new Vector4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }

            {
                ITuple4_Float v = VectorUtils.Convert <ITuple4_Float>(new BuffVector4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }
            {
                ITuple4_Byte v = VectorUtils.Convert <ITuple4_Byte>(new BuffVector4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }

            // 4D - points

            {
                ITuple4_Float v = VectorUtils.Convert <ITuple4_Float>(new Point4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }
            {
                ITuple4_Byte v = VectorUtils.Convert <ITuple4_Byte>(new Point4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }

            {
                ITuple4_Float v = VectorUtils.Convert <ITuple4_Float>(new BuffPoint4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }
            {
                ITuple4_Byte v = VectorUtils.Convert <ITuple4_Byte>(new BuffPoint4d(1, 2, 3, 4));
                Assert.IsTrue(v.X == 1 && v.Y == 2 && v.Z == 3 && v.W == 4);
            }
        }
示例#12
0
        public static IEnumerable <TPoint> GetPoints <TPoint>(IPathIterator2 path)
            where TPoint : IPoint2
        {
            List <TPoint> points = new List <TPoint>();

            TPoint pFirst;
            TPoint p0;

            while (path.Next())
            {
                SegmentType segmentType = path.GetType();
                switch (segmentType)
                {
                case SegmentType.MoveTo:
                {
                    p0 = VectorUtils.Convert <TPoint>(path.GetP1());
                    points.Add(p0);

                    pFirst = p0;
                    break;
                }

                case SegmentType.LineTo:
                {
                    TPoint p1 = VectorUtils.Convert <TPoint>(path.GetP1());
                    points.Add(p1);

                    p0 = p1;
                    break;
                }

                case SegmentType.CubicTo:
                {
                    TPoint p1 = VectorUtils.Convert <TPoint>(path.GetP1());
                    points.Add(p1);

                    TPoint p2 = VectorUtils.Convert <TPoint>(path.GetP2());
                    points.Add(p2);

                    p0 = p1;
                    break;
                }

                case SegmentType.CuadTo:
                {
                    TPoint p1 = VectorUtils.Convert <TPoint>(path.GetP1());
                    points.Add(p1);

                    TPoint p2 = VectorUtils.Convert <TPoint>(path.GetP2());
                    points.Add(p2);

                    TPoint p3 = VectorUtils.Convert <TPoint>(path.GetP3());
                    points.Add(p3);

                    p0 = p1;
                    break;
                }

                case SegmentType.Close:
                {
                    break;
                }
                }
            }
            return(points);
        }