/// <summary>
        /// Subtracts the minimum of the two constituent vectors from the maximum vector.
        /// </summary>
        /// <param name="backdrop">The backdrop vector.</param>
        /// <param name="source">The source vector.</param>
        /// <returns>
        /// The <see cref="Vector4"/>.
        /// </returns>
        public static Vector4 Difference(Vector4 backdrop, Vector4 source)
        {
            Vector4 result = Vector4.Abs(backdrop - source);

            result.W = backdrop.W;
            return(result);
        }
Exemple #2
0
        /// <inheritdoc/>
        public bool AlmostEquals(Cmyk other, float precision)
        {
            Vector4 result = Vector4.Abs(this.backingVector - other.backingVector);

            return(result.X < precision &&
                   result.Y < precision &&
                   result.Z < precision &&
                   result.W < precision);
        }
Exemple #3
0
        public static float Maximum(ReadOnlySpan <float> vec1, ReadOnlySpan <float> vec2)
        {
            Debug.Assert(vec1.Length == vec2.Length);

            // @Info: Changed Vector<float>.Count to Vector4 4 because
            // Vector<float>.Count == 8 but takes only 4 floats
            var slots      = 4; // Vector<float>.Count;
            var allignment = 0;
            var distance   = float.MinValue;
            var maxs       = new Vector4(float.MinValue);

            for (;
                 allignment + slots < vec1.Length;
                 allignment += slots)
            {
                var v1 = new Vector4(vec1[allignment],
                                     vec1[allignment + 1],
                                     vec1[allignment + 2],
                                     vec1[allignment + 3]);

                var v2 = new Vector4(vec2[allignment],
                                     vec2[allignment + 1],
                                     vec2[allignment + 2],
                                     vec2[allignment + 3]);

                maxs = Vector4.Max(Vector4.Abs(v1 - v2), maxs);
            }


            distance = MathF.Max(distance, maxs.X);
            distance = MathF.Max(distance, maxs.Y);
            distance = MathF.Max(distance, maxs.Z);
            distance = MathF.Max(distance, maxs.W);

            for (;
                 allignment < vec1.Length;
                 ++allignment)
            {
                distance = MathF.Max(distance, MathF.Abs(vec1[allignment] - vec2[allignment]));
            }

            return(distance);
        }
Exemple #4
0
 public void AbsTest()
 {
     for (var x = -10; x < 10; x++)
     {
         for (var y = -10; y < 10; y++)
         {
             for (var z = -10; z < 10; z++)
             {
                 for (var w = -10; w < 10; w++)
                 {
                     var v = new Vector4(x, y, z, w);
                     v = v.Abs();
                     Assert.LessOrEqual(0, v.X);
                     Assert.LessOrEqual(0, v.Y);
                     Assert.LessOrEqual(0, v.Z);
                 }
             }
         }
     }
 }
Exemple #5
0
        public static int VectorAbs()
        {
            Vector4 A = new Vector4(-1f);
            Vector4 B = Vector4.Abs(A);

            if (!(CheckValue <float>(B.X, 1f)))
            {
                return(Fail);
            }
            if (!(CheckValue <float>(B.Y, 1f)))
            {
                return(Fail);
            }
            if (!(CheckValue <float>(B.Z, 1f)))
            {
                return(Fail);
            }
            if (!(CheckValue <float>(B.W, 1f)))
            {
                return(Fail);
            }
            return(Pass);
        }
Exemple #6
0
        public static float Manhattan(ReadOnlySpan <float> vec1, ReadOnlySpan <float> vec2)
        {
            Debug.Assert(vec1.Length == vec2.Length);

            // @Info: Changed Vector<float>.Count to Vector4 4 because
            // Vector<float>.Count == 8 but takes only 4 floats
            var slots      = 4; // Vector<float>.Count;
            var allignment = 0;
            var distance   = 0.0f;

            for (;
                 allignment + slots < vec1.Length;
                 allignment += slots)
            {
                var v1 = new Vector4(vec1[allignment],
                                     vec1[allignment + 1],
                                     vec1[allignment + 2],
                                     vec1[allignment + 3]);

                var v2 = new Vector4(vec2[allignment],
                                     vec2[allignment + 1],
                                     vec2[allignment + 2],
                                     vec2[allignment + 3]);

                distance += Vector4.Dot(Vector4.Abs(v1 - v2), Vector4.One);
            }

            for (;
                 allignment < vec1.Length;
                 ++allignment)
            {
                distance += MathF.Abs(vec1[allignment] - vec2[allignment]);
            }

            return(distance);
        }
Exemple #7
0
        /// plane encode the 4 coefficients (a,b,c,d) of a plane i.e. 0 = ax + by + cz + d
        /// Assuming positive halfspace is "inside" of the plane i.e. normal pointing inwards
        /// Intersection with respect to the AABB
        /// Realtime Rendering Third Editin p. 756
        //TODO: Investigate error bound for intersection
        public static IntersectionResult PlaneIntersection(AABB aabb, Vector4 plane)
        {
            var intersection   = IntersectionResult.Intersecting;
            var c              = Center(aabb);
            var d              = plane.W;
            var h              = (Diagonal(aabb)) / 2.0f;
            var planeNormalAbs = Vector4.Abs(plane);
            var e              = h.X * planeNormalAbs.X + h.Y * planeNormalAbs.Y + h.Z * planeNormalAbs.Z;
            var s              = Numerics.Vector.InMemoryDotProduct3(c, plane) + d;
            var eps            = 0.0f;

            var isInside  = s - e > eps;
            var isOutside = s + e < eps;

            if (isInside)
            {
                intersection = IntersectionResult.Inside;
            }
            else if (isOutside)
            {
                intersection = IntersectionResult.Outside;
            }
            return(intersection);
        }
Exemple #8
0
 public static Vector4 vector4_abs(Vector4 v1)
 {
     return(Vector4.Abs(v1));
 }
Exemple #9
0
 /// <summary>Returns a vector whose elements are the absolute values of each of the specified vector&#39;s elements.</summary>
 public static Vector4 absolute(this Vector4 vec) => Vector4.Abs(vec);
Exemple #10
0
        Position4 VS(Position4 input)
        {
            Vector2 v2 = new Vector2(1, 2);
            Vector2 r2 = Vector2.Abs(v2);

            r2 = Vector2.Add(v2, v2);
            r2 = Vector2.Clamp(v2, v2, v2);
            float r = Vector2.Distance(v2, v2);

            r  = Vector2.DistanceSquared(v2, v2);
            r2 = Vector2.Divide(v2, v2);
            r2 = Vector2.Divide(v2, r);
            r  = Vector2.Dot(v2, v2);
            r2 = Vector2.Lerp(v2, v2, 0.75f);
            r2 = Vector2.Max(v2, v2);
            r2 = Vector2.Min(v2, v2);
            r2 = Vector2.Multiply(v2, v2);
            r2 = Vector2.Multiply(v2, r);
            r2 = Vector2.Multiply(r, v2);
            r2 = Vector2.Negate(v2);
            r2 = Vector2.Normalize(v2);
            r2 = Vector2.Reflect(v2, v2);
            r2 = Vector2.SquareRoot(v2);
            r2 = Vector2.Subtract(v2, v2);
            r  = v2.Length();
            r  = v2.LengthSquared();

            Vector3 v3 = new Vector3(1, 2, 3);
            Vector3 r3 = Vector3.Abs(v3);

            r3 = Vector3.Add(v3, v3);
            r3 = Vector3.Clamp(v3, v3, v3);
            r3 = Vector3.Cross(v3, v3);
            r  = Vector3.Distance(v3, v3);
            r  = Vector3.DistanceSquared(v3, v3);
            r3 = Vector3.Divide(v3, v3);
            r3 = Vector3.Divide(v3, r);
            r  = Vector3.Dot(v3, v3);
            r3 = Vector3.Lerp(v3, v3, 0.75f);
            r3 = Vector3.Max(v3, v3);
            r3 = Vector3.Min(v3, v3);
            r3 = Vector3.Multiply(v3, v3);
            r3 = Vector3.Multiply(v3, r);
            r3 = Vector3.Multiply(r, v3);
            r3 = Vector3.Negate(v3);
            r3 = Vector3.Normalize(v3);
            r3 = Vector3.Reflect(v3, v3);
            r3 = Vector3.SquareRoot(v3);
            r3 = Vector3.Subtract(v3, v3);
            r  = v3.Length();
            r  = v3.LengthSquared();

            Vector4 v4 = new Vector4(1, 2, 3, 4);
            Vector4 r4 = Vector4.Abs(v4);

            r4 = Vector4.Add(v4, v4);
            r4 = Vector4.Clamp(v4, v4, v4);
            r  = Vector4.Distance(v4, v4);
            r  = Vector4.DistanceSquared(v4, v4);
            r4 = Vector4.Divide(v4, v4);
            r4 = Vector4.Divide(v4, r);
            r  = Vector4.Dot(v4, v4);
            r4 = Vector4.Lerp(v4, v4, 0.75f);
            r4 = Vector4.Max(v4, v4);
            r4 = Vector4.Min(v4, v4);
            r4 = Vector4.Multiply(v4, v4);
            r4 = Vector4.Multiply(v4, r);
            r4 = Vector4.Multiply(r, v4);
            r4 = Vector4.Negate(v4);
            r4 = Vector4.Normalize(v4);
            r4 = Vector4.SquareRoot(v4);
            r4 = Vector4.Subtract(v4, v4);
            r  = v4.Length();
            r  = v4.LengthSquared();

            return(input);
        }
Exemple #11
0
 public Vector4 AbsBenchmark() => Vector4.Abs(VectorTests.Vector4Value);
        /// <summary>
        /// Applies the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="targetLocation">The target location.</param>
        /// <returns>The image</returns>
        public unsafe Image Apply(Image image, Rectangle targetLocation = default(Rectangle))
        {
            targetLocation = targetLocation == default(Rectangle) ? new Rectangle(0, 0, image.Width, image.Height) : targetLocation.Clamp(image);

            var tempPixels = new Color[image.Pixels.Length];

            Array.Copy(image.Pixels, tempPixels, image.Pixels.Length);
            Parallel.For(targetLocation.Bottom, targetLocation.Top, y =>
            {
                fixed(Color * Pointer = &image.Pixels[(y * image.Width) + targetLocation.Left])
                {
                    Color *OutputPointer = Pointer;
                    for (int x = targetLocation.Left; x < targetLocation.Right; ++x)
                    {
                        var XValue    = new Vector4(0, 0, 0, 0);
                        var YValue    = new Vector4(0, 0, 0, 0);
                        float WeightX = 0;
                        float WeightY = 0;
                        int XCurrent  = -Width >> 1;
                        int YCurrent  = -Height >> 1;
                        int Start     = 0;
                        fixed(float *XMatrixPointer = &XMatrix[0])
                        {
                            fixed(float *YMatrixPointer = &YMatrix[0])
                            {
                                float *XMatrixValue = XMatrixPointer;
                                float *YMatrixValue = YMatrixPointer;
                                for (int MatrixIndex = 0; MatrixIndex < XMatrix.Length; ++MatrixIndex)
                                {
                                    if (MatrixIndex % Width == 0 && MatrixIndex != 0)
                                    {
                                        ++YCurrent;
                                        XCurrent = 0;
                                    }
                                    if (XCurrent + x < image.Width && XCurrent + x >= 0 &&
                                        YCurrent + y < image.Height && YCurrent + y >= 0)
                                    {
                                        if (*XMatrixValue != 0 || *YMatrixValue != 0)
                                        {
                                            Start         = ((YCurrent + y) * image.Width) + (x + XCurrent);
                                            var TempPixel = tempPixels[Start];
                                            XValue        = XValue + new Vector4((*XMatrixValue * TempPixel.Red),
                                                                                 (*XMatrixValue * TempPixel.Green),
                                                                                 (*XMatrixValue * TempPixel.Blue),
                                                                                 (*XMatrixValue * TempPixel.Alpha));
                                            YValue = YValue + new Vector4((*YMatrixValue * TempPixel.Red),
                                                                          (*YMatrixValue * TempPixel.Green),
                                                                          (*YMatrixValue * TempPixel.Blue),
                                                                          (*YMatrixValue * TempPixel.Alpha));
                                            WeightX += *XMatrixValue;
                                            WeightY += *YMatrixValue;
                                        }
                                        ++XMatrixValue;
                                        ++YMatrixValue;
                                    }
                                    ++XCurrent;
                                }
                            }
                        }
                        if (WeightX == 0)
                        {
                            WeightX = 1;
                        }
                        if (WeightY == 0)
                        {
                            WeightY = 1;
                        }
                        if (WeightX > 0 && WeightY > 0)
                        {
                            if (Absolute)
                            {
                                YValue = Vector4.Abs(YValue);
                                XValue = Vector4.Abs(XValue);
                            }
                            XValue        /= WeightX;
                            YValue        /= WeightY;
                            var TempResult = Vector4.SquareRoot((XValue * XValue) + (YValue * YValue));
                            TempResult     = Vector4.Clamp(TempResult, Vector4.Zero, new Vector4(255, 255, 255, 255)) / 255f;
                            *OutputPointer = TempResult;
                            ++OutputPointer;
                        }
                        else
                        {
                            ++OutputPointer;
                        }
                    }
                }
            });
            return(image);
        }
        private BuiltInExpressionFfi()
        {
            _registry = new DelegateExpressionFfi
            {
                { "Abs", (float f) => Math.Abs(f) },
                { "Abs", (Vector2 v) => Vector2.Abs(v) },
                { "Abs", (Vector3 v) => Vector3.Abs(v) },
                { "Abs", (Vector4 v) => Vector4.Abs(v) },

                { "ACos", (float f) => (float)Math.Acos(f) },
                { "ASin", (float f) => (float)Math.Asin(f) },
                { "ATan", (float f) => (float)Math.Atan(f) },
                { "Ceil", (float f) => (float)Math.Ceiling(f) },

                { "Clamp", (float a1, float a2, float a3) => MathUtilities.Clamp(a1, a2, a3) },
                { "Clamp", (Vector2 a1, Vector2 a2, Vector2 a3) => Vector2.Clamp(a1, a2, a3) },
                { "Clamp", (Vector3 a1, Vector3 a2, Vector3 a3) => Vector3.Clamp(a1, a2, a3) },
                { "Clamp", (Vector4 a1, Vector4 a2, Vector4 a3) => Vector4.Clamp(a1, a2, a3) },

                { "Concatenate", (Quaternion a1, Quaternion a2) => Quaternion.Concatenate(a1, a2) },
                { "Cos", (float a) => (float)Math.Cos(a) },

                /*
                 * TODO:
                 *  ColorHsl(Float h, Float s, Float l)
                 *  ColorLerpHSL(Color colorTo, CompositionColorcolorFrom, Float progress)
                 */

                {
                    "ColorLerp", (Avalonia.Media.Color to, Avalonia.Media.Color from, float progress) =>
                    ColorInterpolator.LerpRGB(to, from, progress)
                },
                {
                    "ColorLerpRGB", (Avalonia.Media.Color to, Avalonia.Media.Color from, float progress) =>
                    ColorInterpolator.LerpRGB(to, from, progress)
                },
                {
                    "ColorRGB", (float a, float r, float g, float b) => Avalonia.Media.Color.FromArgb(
                        (byte)MathUtilities.Clamp(a, 0, 255),
                        (byte)MathUtilities.Clamp(r, 0, 255),
                        (byte)MathUtilities.Clamp(g, 0, 255),
                        (byte)MathUtilities.Clamp(b, 0, 255)
                        )
                },

                { "Distance", (Vector2 a1, Vector2 a2) => Vector2.Distance(a1, a2) },
                { "Distance", (Vector3 a1, Vector3 a2) => Vector3.Distance(a1, a2) },
                { "Distance", (Vector4 a1, Vector4 a2) => Vector4.Distance(a1, a2) },

                { "DistanceSquared", (Vector2 a1, Vector2 a2) => Vector2.DistanceSquared(a1, a2) },
                { "DistanceSquared", (Vector3 a1, Vector3 a2) => Vector3.DistanceSquared(a1, a2) },
                { "DistanceSquared", (Vector4 a1, Vector4 a2) => Vector4.DistanceSquared(a1, a2) },

                { "Floor", (float v) => (float)Math.Floor(v) },

                { "Inverse", (Matrix3x2 v) => Inverse(v) },
                { "Inverse", (Matrix4x4 v) => Inverse(v) },


                { "Length", (Vector2 a1) => a1.Length() },
                { "Length", (Vector3 a1) => a1.Length() },
                { "Length", (Vector4 a1) => a1.Length() },
                { "Length", (Quaternion a1) => a1.Length() },

                { "LengthSquared", (Vector2 a1) => a1.LengthSquared() },
                { "LengthSquared", (Vector3 a1) => a1.LengthSquared() },
                { "LengthSquared", (Vector4 a1) => a1.LengthSquared() },
                { "LengthSquared", (Quaternion a1) => a1.LengthSquared() },

                { "Lerp", (float a1, float a2, float a3) => Lerp(a1, a2, a3) },
                { "Lerp", (Vector2 a1, Vector2 a2, float a3) => Vector2.Lerp(a1, a2, a3) },
                { "Lerp", (Vector3 a1, Vector3 a2, float a3) => Vector3.Lerp(a1, a2, a3) },
                { "Lerp", (Vector4 a1, Vector4 a2, float a3) => Vector4.Lerp(a1, a2, a3) },


                { "Ln", (float f) => (float)Math.Log(f) },
                { "Log10", (float f) => (float)Math.Log10(f) },

                { "Matrix3x2.CreateFromScale", (Vector2 v) => Matrix3x2.CreateScale(v) },
                { "Matrix3x2.CreateFromTranslation", (Vector2 v) => Matrix3x2.CreateTranslation(v) },
                { "Matrix3x2.CreateRotation", (float v) => Matrix3x2.CreateRotation(v) },
                { "Matrix3x2.CreateScale", (Vector2 v) => Matrix3x2.CreateScale(v) },
                { "Matrix3x2.CreateSkew", (float a1, float a2, Vector2 a3) => Matrix3x2.CreateSkew(a1, a2, a3) },
                { "Matrix3x2.CreateTranslation", (Vector2 v) => Matrix3x2.CreateScale(v) },
                {
                    "Matrix3x2", (float m11, float m12, float m21, float m22, float m31, float m32) =>
                    new Matrix3x2(m11, m12, m21, m22, m31, m32)
                },
                { "Matrix4x4.CreateFromAxisAngle", (Vector3 v, float angle) => Matrix4x4.CreateFromAxisAngle(v, angle) },
                { "Matrix4x4.CreateFromScale", (Vector3 v) => Matrix4x4.CreateScale(v) },
                { "Matrix4x4.CreateFromTranslation", (Vector3 v) => Matrix4x4.CreateTranslation(v) },
                { "Matrix4x4.CreateScale", (Vector3 v) => Matrix4x4.CreateScale(v) },
                { "Matrix4x4.CreateTranslation", (Vector3 v) => Matrix4x4.CreateScale(v) },
                { "Matrix4x4", (Matrix3x2 m) => new Matrix4x4(m) },
                {
                    "Matrix4x4",
                    (float m11, float m12, float m13, float m14,
                     float m21, float m22, float m23, float m24,
                     float m31, float m32, float m33, float m34,
                     float m41, float m42, float m43, float m44) =>
                    new Matrix4x4(
                        m11, m12, m13, m14,
                        m21, m22, m23, m24,
                        m31, m32, m33, m34,
                        m41, m42, m43, m44)
                },


                { "Max", (float a1, float a2) => Math.Max(a1, a2) },
                { "Max", (Vector2 a1, Vector2 a2) => Vector2.Max(a1, a2) },
                { "Max", (Vector3 a1, Vector3 a2) => Vector3.Max(a1, a2) },
                { "Max", (Vector4 a1, Vector4 a2) => Vector4.Max(a1, a2) },


                { "Min", (float a1, float a2) => Math.Min(a1, a2) },
                { "Min", (Vector2 a1, Vector2 a2) => Vector2.Min(a1, a2) },
                { "Min", (Vector3 a1, Vector3 a2) => Vector3.Min(a1, a2) },
                { "Min", (Vector4 a1, Vector4 a2) => Vector4.Min(a1, a2) },

                { "Mod", (float a, float b) => a % b },

                { "Normalize", (Quaternion a) => Quaternion.Normalize(a) },
                { "Normalize", (Vector2 a) => Vector2.Normalize(a) },
                { "Normalize", (Vector3 a) => Vector3.Normalize(a) },
                { "Normalize", (Vector4 a) => Vector4.Normalize(a) },

                { "Pow", (float a, float b) => (float)Math.Pow(a, b) },
                { "Quaternion.CreateFromAxisAngle", (Vector3 a, float b) => Quaternion.CreateFromAxisAngle(a, b) },
                { "Quaternion", (float a, float b, float c, float d) => new Quaternion(a, b, c, d) },

                { "Round", (float a) => (float)Math.Round(a) },

                { "Scale", (Matrix3x2 a, float b) => a * b },
                { "Scale", (Matrix4x4 a, float b) => a * b },
                { "Scale", (Vector2 a, float b) => a * b },
                { "Scale", (Vector3 a, float b) => a * b },
                { "Scale", (Vector4 a, float b) => a * b },

                { "Sin", (float a) => (float)Math.Sin(a) },

                { "SmoothStep", (float a1, float a2, float a3) => SmoothStep(a1, a2, a3) },
                { "SmoothStep", (Vector2 a1, Vector2 a2, Vector2 a3) => SmoothStep(a1, a2, a3) },
                { "SmoothStep", (Vector3 a1, Vector3 a2, Vector3 a3) => SmoothStep(a1, a2, a3) },
                { "SmoothStep", (Vector4 a1, Vector4 a2, Vector4 a3) => SmoothStep(a1, a2, a3) },

                // I have no idea how to do a spherical interpolation for a scalar value, so we are doing a linear one
                { "Slerp", (float a1, float a2, float a3) => Lerp(a1, a2, a3) },
                { "Slerp", (Quaternion a1, Quaternion a2, float a3) => Quaternion.Slerp(a1, a2, a3) },

                { "Sqrt", (float a) => (float)Math.Sqrt(a) },
                { "Square", (float a) => a * a },
                { "Tan", (float a) => (float)Math.Tan(a) },

                { "ToRadians", (float a) => (float)(a * Math.PI / 180) },
                { "ToDegrees", (float a) => (float)(a * 180d / Math.PI) },

                { "Transform", (Vector2 a, Matrix3x2 b) => Vector2.Transform(a, b) },
                { "Transform", (Vector3 a, Matrix4x4 b) => Vector3.Transform(a, b) },

                { "Vector2", (float a, float b) => new Vector2(a, b) },
                { "Vector3", (float a, float b, float c) => new Vector3(a, b, c) },
                { "Vector3", (Vector2 v2, float z) => new Vector3(v2, z) },
                { "Vector4", (float a, float b, float c, float d) => new Vector4(a, b, c, d) },
                { "Vector4", (Vector2 v2, float z, float w) => new Vector4(v2, z, w) },
                { "Vector4", (Vector3 v3, float w) => new Vector4(v3, w) },
            };
        }
        /// <summary>
        /// Applies the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="targetLocation">The target location.</param>
        /// <returns>The image</returns>
        public unsafe Image Apply(Image image, Rectangle targetLocation = default(Rectangle))
        {
            targetLocation = targetLocation == default(Rectangle) ? new Rectangle(0, 0, image.Width, image.Height) : targetLocation.Clamp(image);
            var tempPixels = new Color[image.Pixels.Length];

            Array.Copy(image.Pixels, tempPixels, image.Pixels.Length);
            Parallel.For(targetLocation.Bottom, targetLocation.Top, y =>
            {
                fixed(Color * Pointer = &image.Pixels[(y * image.Width) + targetLocation.Left])
                {
                    Color *OutputPointer = Pointer;
                    for (int x = targetLocation.Left; x < targetLocation.Right; ++x)
                    {
                        var Values   = new Vector4(0, 0, 0, 0);
                        float Weight = 0;
                        int XCurrent = -Width >> 1;
                        int YCurrent = -Height >> 1;
                        int Start    = 0;
                        fixed(float *MatrixPointer = &Matrix[0])
                        {
                            float *MatrixValue = MatrixPointer;
                            for (int MatrixIndex = 0; MatrixIndex < Matrix.Length; ++MatrixIndex)
                            {
                                if (MatrixIndex % Width == 0 && MatrixIndex != 0)
                                {
                                    ++YCurrent;
                                    XCurrent = 0;
                                }
                                if (XCurrent + x < image.Width && XCurrent + x >= 0 &&
                                    YCurrent + y < image.Height && YCurrent + y >= 0)
                                {
                                    if (*MatrixValue != 0)
                                    {
                                        Start         = ((YCurrent + y) * image.Width) + (x + XCurrent);
                                        var TempPixel = tempPixels[Start];
                                        Values       += new Vector4(*MatrixValue * TempPixel.Red,
                                                                    *MatrixValue * TempPixel.Green,
                                                                    *MatrixValue * TempPixel.Blue,
                                                                    TempPixel.Alpha);
                                        Weight += *MatrixValue;
                                    }
                                    ++MatrixValue;
                                }
                                ++XCurrent;
                            }
                        }
                        if (Weight == 0)
                        {
                            Weight = 1;
                        }
                        if (Weight > 0)
                        {
                            if (Absolute)
                            {
                                Values = Vector4.Abs(Values);
                            }
                            Values /= Weight;
                            Values  = new Vector4(Values.X + Offset, Values.Y + Offset, Values.Z + Offset, 1);
                            Values  = Vector4.Clamp(Values, Vector4.Zero, new Vector4(255, 255, 255, 255));
                            (*OutputPointer).Red   = (byte)Values.X;
                            (*OutputPointer).Green = (byte)Values.Y;
                            (*OutputPointer).Blue  = (byte)Values.Z;
                            ++OutputPointer;
                        }
                        else
                        {
                            ++OutputPointer;
                        }
                    }
                }
            });
            return(image);
        }
Exemple #15
0
        SystemPosition4 VS(Position4 input)
        {
            Vector2 r2 = Vector2.Abs(VH.V2);

            r2 = Vector2.Add(VH.V2, VH.V2);
            r2 = Vector2.Clamp(VH.V2, VH.V2, VH.V2);
            float r = Vector2.Distance(VH.V2, VH.V2);

            r  = Vector2.DistanceSquared(VH.V2, VH.V2);
            r2 = Vector2.Divide(VH.V2, VH.V2);
            r2 = Vector2.Divide(VH.V2, r);
            r  = Vector2.Dot(VH.V2, VH.V2);
            r2 = Vector2.Lerp(VH.V2, VH.V2, 0.75f);
            r2 = Vector2.Max(VH.V2, VH.V2);
            r2 = Vector2.Min(VH.V2, VH.V2);
            r2 = Vector2.Multiply(VH.V2, VH.V2);
            r2 = Vector2.Multiply(VH.V2, r);
            r2 = Vector2.Multiply(r, VH.V2);
            r2 = Vector2.Negate(VH.V2);
            r2 = Vector2.Normalize(VH.V2);
            r2 = Vector2.Reflect(VH.V2, VH.V2);
            r2 = Vector2.SquareRoot(VH.V2);
            r2 = Vector2.Subtract(VH.V2, VH.V2);
            r  = VH.V2.Length();
            r  = VH.V2.LengthSquared();
            r2 = Vector2.Transform(VH.V2, VH.M4x4);

            Vector3 V3 = new Vector3(1, 2, 3);
            Vector3 r3 = Vector3.Abs(VH.V3);

            r3 = Vector3.Add(VH.V3, VH.V3);
            r3 = Vector3.Clamp(VH.V3, VH.V3, VH.V3);
            r3 = Vector3.Cross(VH.V3, VH.V3);
            r  = Vector3.Distance(VH.V3, VH.V3);
            r  = Vector3.DistanceSquared(VH.V3, VH.V3);
            r3 = Vector3.Divide(VH.V3, VH.V3);
            r3 = Vector3.Divide(VH.V3, r);
            r  = Vector3.Dot(VH.V3, VH.V3);
            r3 = Vector3.Lerp(VH.V3, VH.V3, 0.75f);
            r3 = Vector3.Max(VH.V3, VH.V3);
            r3 = Vector3.Min(VH.V3, VH.V3);
            r3 = Vector3.Multiply(VH.V3, VH.V3);
            r3 = Vector3.Multiply(VH.V3, r);
            r3 = Vector3.Multiply(r, VH.V3);
            r3 = Vector3.Negate(VH.V3);
            r3 = Vector3.Normalize(VH.V3);
            r3 = Vector3.Reflect(VH.V3, VH.V3);
            r3 = Vector3.SquareRoot(VH.V3);
            r3 = Vector3.Subtract(VH.V3, VH.V3);
            r  = VH.V3.Length();
            r  = VH.V3.LengthSquared();
            r3 = Vector3.Transform(VH.V3, VH.M4x4);

            Vector4 V4 = new Vector4(1, 2, 3, 4);
            Vector4 r4 = Vector4.Abs(VH.V4);

            r4 = Vector4.Add(VH.V4, VH.V4);
            r4 = Vector4.Clamp(VH.V4, VH.V4, VH.V4);
            r  = Vector4.Distance(VH.V4, VH.V4);
            r  = Vector4.DistanceSquared(VH.V4, VH.V4);
            r4 = Vector4.Divide(VH.V4, VH.V4);
            r4 = Vector4.Divide(VH.V4, r);
            r  = Vector4.Dot(VH.V4, VH.V4);
            r4 = Vector4.Lerp(VH.V4, VH.V4, 0.75f);
            r4 = Vector4.Max(VH.V4, VH.V4);
            r4 = Vector4.Min(VH.V4, VH.V4);
            r4 = Vector4.Multiply(VH.V4, VH.V4);
            r4 = Vector4.Multiply(VH.V4, r);
            r4 = Vector4.Multiply(r, VH.V4);
            r4 = Vector4.Negate(VH.V4);
            r4 = Vector4.Normalize(VH.V4);
            r4 = Vector4.SquareRoot(VH.V4);
            r4 = Vector4.Subtract(VH.V4, VH.V4);
            r  = VH.V4.Length();
            r  = VH.V4.LengthSquared();
            r4 = Vector4.Transform(VH.V2, VH.M4x4);
            r4 = Vector4.Transform(VH.V3, VH.M4x4);
            r4 = Vector4.Transform(VH.V4, VH.M4x4);

            SystemPosition4 output;

            output.Position = input.Position;
            return(output);
        }
        SystemPosition4 VS(Position4 input)
        {
            Matrix4x4 testMatrix = new Matrix4x4(
                1, 0, 0, 0,
                0, 1, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1);

            Vector2 v2 = new Vector2(1, 2);
            Vector2 r2 = Vector2.Abs(v2);

            r2 = Vector2.Add(v2, v2);
            r2 = Vector2.Clamp(v2, v2, v2);
            float r = Vector2.Distance(v2, v2);

            r  = Vector2.DistanceSquared(v2, v2);
            r2 = Vector2.Divide(v2, v2);
            r2 = Vector2.Divide(v2, r);
            r  = Vector2.Dot(v2, v2);
            r2 = Vector2.Lerp(v2, v2, 0.75f);
            r2 = Vector2.Max(v2, v2);
            r2 = Vector2.Min(v2, v2);
            r2 = Vector2.Multiply(v2, v2);
            r2 = Vector2.Multiply(v2, r);
            r2 = Vector2.Multiply(r, v2);
            r2 = Vector2.Negate(v2);
            r2 = Vector2.Normalize(v2);
            r2 = Vector2.Reflect(v2, v2);
            r2 = Vector2.SquareRoot(v2);
            r2 = Vector2.Subtract(v2, v2);
            r  = v2.Length();
            r  = v2.LengthSquared();
            r2 = Vector2.Transform(v2, testMatrix);

            Vector3 v3 = new Vector3(1, 2, 3);
            Vector3 r3 = Vector3.Abs(v3);

            r3 = Vector3.Add(v3, v3);
            r3 = Vector3.Clamp(v3, v3, v3);
            r3 = Vector3.Cross(v3, v3);
            r  = Vector3.Distance(v3, v3);
            r  = Vector3.DistanceSquared(v3, v3);
            r3 = Vector3.Divide(v3, v3);
            r3 = Vector3.Divide(v3, r);
            r  = Vector3.Dot(v3, v3);
            r3 = Vector3.Lerp(v3, v3, 0.75f);
            r3 = Vector3.Max(v3, v3);
            r3 = Vector3.Min(v3, v3);
            r3 = Vector3.Multiply(v3, v3);
            r3 = Vector3.Multiply(v3, r);
            r3 = Vector3.Multiply(r, v3);
            r3 = Vector3.Negate(v3);
            r3 = Vector3.Normalize(v3);
            r3 = Vector3.Reflect(v3, v3);
            r3 = Vector3.SquareRoot(v3);
            r3 = Vector3.Subtract(v3, v3);
            r  = v3.Length();
            r  = v3.LengthSquared();
            r3 = Vector3.Transform(v3, testMatrix);

            Vector4 v4 = new Vector4(1, 2, 3, 4);
            Vector4 r4 = Vector4.Abs(v4);

            r4 = Vector4.Add(v4, v4);
            r4 = Vector4.Clamp(v4, v4, v4);
            r  = Vector4.Distance(v4, v4);
            r  = Vector4.DistanceSquared(v4, v4);
            r4 = Vector4.Divide(v4, v4);
            r4 = Vector4.Divide(v4, r);
            r  = Vector4.Dot(v4, v4);
            r4 = Vector4.Lerp(v4, v4, 0.75f);
            r4 = Vector4.Max(v4, v4);
            r4 = Vector4.Min(v4, v4);
            r4 = Vector4.Multiply(v4, v4);
            r4 = Vector4.Multiply(v4, r);
            r4 = Vector4.Multiply(r, v4);
            r4 = Vector4.Negate(v4);
            r4 = Vector4.Normalize(v4);
            r4 = Vector4.SquareRoot(v4);
            r4 = Vector4.Subtract(v4, v4);
            r  = v4.Length();
            r  = v4.LengthSquared();
            r4 = Vector4.Transform(v2, testMatrix);
            r4 = Vector4.Transform(v3, testMatrix);
            r4 = Vector4.Transform(v4, testMatrix);

            SystemPosition4 output;

            output.Position = input.Position;
            return(output);
        }