Esempio n. 1
0
        //========= INTERACTION ==========

        /** <summary> Returns true if the specified point is on the line. </summary> */
        public bool IsPointOnLine(Vector2F v)
        {
            double a = Height / Width;
            double b = Y1 - (a * X1);

            return(GMath.Abs(v.Y - (a * v.X + b)) == 0);
        }
Esempio n. 2
0
 public static GVector3 operator /(GVector3 v1, float v)
 {
     if (GMath.Abs(v) > GMath.EPS)
     {
         return(new GVector3(v1.x / v, v1.y / v, v1.z / v));
     }
     return(v1);
 }
Esempio n. 3
0
 public static GVector2 Divide(GVector2 v1, float divider)
 {
     if (GMath.Abs(divider) > GMath.EPS)
     {
         return(new GVector2(v1.x / divider, v1.y / divider));
     }
     return(v1);
 }
Esempio n. 4
0
 public bool IsSoftMeetingEntity(Entity other, int maxZDistance = 10)
 {
     if (CanCollideWithEntity(other) && GMath.Abs(entity.ZPosition - other.ZPosition) < maxZDistance)
     {
         return(PositionedSoftCollisionBox.Intersects(other.Physics.PositionedSoftCollisionBox));
     }
     return(false);
 }
Esempio n. 5
0
        //public CircularTrack(Point center, double radius, double angularVelocity, double creationTime, double annihilationTime, Angle phaseOrigin, Color color)
        //{
        //    Center = center;
        //    Radius = radius;
        //    AngularVelocity = angularVelocity;
        //    CreationTime = creationTime;
        //    AnnihilationTime = annihilationTime;
        //    PhaseOrigin = phaseOrigin;
        //    Color = color;
        //}

        public CircularTrack(Point origin, Vector velocity, double curvature, double creationTime, double annihilationTime, Color color)
        {
            Contract.Requires <ArgumentOutOfRangeException>(curvature != 0);
            Radius = 1 / GMath.Abs(curvature);
            if (curvature < 0)
            {
                Center = origin + new Vector(Radius, velocity.Direction - Angle.Deg(90));
            }
            else
            {
                Center = origin + new Vector(Radius, velocity.Direction + Angle.Deg(90));
            }
            AngularVelocity  = GMath.Sign(curvature) * velocity.Magnitude / Radius;
            PhaseOrigin      = GMath.Atan2(velocity - Angle.Deg(90 * GMath.Sign(curvature)));
            CreationTime     = creationTime;
            AnnihilationTime = annihilationTime;
            Color            = color;
        }
Esempio n. 6
0
        public void Polygon_ContainsPoint()
        {
            double[,] actualMask = (double[, ])expectedMask.Clone();

            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    actualMask[x, y] -= thePolygon.ContainsPoint(x, y) ? 1 : 0;
                }
            }

            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    Assert.True(GMath.Abs(actualMask[x, y]) < 1, $"Element ({x}, {y}) is equal to {actualMask[x, y]}");
                }
            }

            var unitSquare = new Polygon(new Point[] { (0, 0), (1, 0), (1, 1), (0, 1) });
 public double CouplingStrength(ParticleType other, ParticleType forceParticle)
 {
     if (forceParticle == Photon)
     {
         return(30 / GMath.Abs(Charge));
     }
     else if (forceParticle == Gluon)
     {
         return((ColorCharge == ColorCharge.Neutral || other.ColorCharge == ColorCharge.Neutral || ColorCharge == other.ColorCharge) ? 0 : 1);
     }
     else if (forceParticle == WPlus)
     {
         return((this == other.Complementary) ? 50 : (this.Class == other.Class && (GMath.Abs(this.Charge) + GMath.Abs(other.Charge) == 3)) ? 100 : 0);
     }
     else if (forceParticle == ParticleType.Higgs)
     {
         return(HiggsCoupling);
     }
     else
     {
         return(0);//throw new NotSupportedException();// if (forceParticle == ParticleType.
     }
 }
Esempio n. 8
0
        public static void gmathtest(float[] c)
        {
            int i = 0;

            c[i++] = GMath.Abs((long)-42.3F);
            c[i++] = GMath.Acos(42.3F);
            c[i++] = GMath.Asin(42.3F);
            c[i++] = GMath.Atan(42.3F);
            c[i++] = GMath.Atan2(42.3F, 3.8F);
            c[i++] = GMath.Ceiling(42.3F);
            c[i++] = GMath.Cos(42.3F);
            c[i++] = GMath.Cosh(2.3F);
            c[i++] = GMath.E;
            c[i++] = GMath.Exp(1.3F);
            c[i++] = GMath.Floor(3.9F);
            c[i++] = GMath.Log(5.8F);
            c[i++] = GMath.Log10(3.5F);
            c[i++] = GMath.Max(4.8F, 4.9F);
            c[i++] = GMath.Min(4.8F, 4.9F);
            c[i++] = GMath.PI;
            c[i++] = GMath.Pow(4.4F, 2.3F);
            c[i++] = GMath.Round(5.5F);
            c[i++] = GMath.Sin(4.2F);
            c[i++] = GMath.Sinh(3.1F);
            c[i++] = GMath.Sqrt(8.1F);
            c[i++] = GMath.Sqrt(-1.0F);
            c[i++] = GMath.Tan(4.3F);
            c[i++] = GMath.Tanh(8.1F);
            //c[i++] = (float)(Single.IsNaN(GMath.Sqrt(-1.0F)) ? 1.0F : 0.0F);//GMath.Sqrt(-1.0F)
            c[i++] = GMath.Truncate(10.14334325F);
            float zero = 0.0F;

            c[i++] = Single.IsInfinity(1 / zero) ? 1.0F : 0.0F;
            c[60]  = Single.PositiveInfinity;
            c[61]  = Single.NegativeInfinity;
            c[62]  = Single.NaN;
        }
Esempio n. 9
0
        public static void EdgeFilterKernel(GThread thread,
                                            byte[] source, int stride, int imageWidth, int imageHeight, int filterSize)
        {
            int x = thread.blockIdx.x * thread.blockDim.x + thread.threadIdx.x;
            int y = thread.blockIdx.y * thread.blockDim.y + thread.threadIdx.y;

            if (x >= imageWidth || y >= imageHeight)
            {
                return;
            }

            var index = 3 * x + y * stride;

            //take the pixel above, left, right, below and compare to the middle pixel
            var colorDifference = 0.0;

            var xLeft  = x - filterSize;
            var xRight = x + filterSize;
            var yUp    = y - filterSize;
            var yDown  = y + filterSize;

            var middleB = source[x * 3 + y * stride];
            var middleG = source[x * 3 + y * stride + 1];
            var middleR = source[x * 3 + y * stride + 2];

            if (xLeft >= 0)
            {
                colorDifference +=
                    GMath.Abs(middleB - source[xLeft * 3 + y * stride]) +
                    GMath.Abs(middleG - source[xLeft * 3 + y * stride + 1]) +
                    GMath.Abs(middleR - source[xLeft * 3 + y * stride + 2]);
            }

            if (xRight < imageWidth)
            {
                colorDifference +=
                    GMath.Abs(middleB - source[xRight * 3 + y * stride]) +
                    GMath.Abs(middleG - source[xRight * 3 + y * stride + 1]) +
                    GMath.Abs(middleR - source[xRight * 3 + y * stride + 2]);
            }

            if (yUp >= 0)
            {
                colorDifference +=
                    GMath.Abs(middleB - source[x * 3 + yUp * stride]) +
                    GMath.Abs(middleG - source[x * 3 + yUp * stride + 1]) +
                    GMath.Abs(middleR - source[x * 3 + yUp * stride + 2]);
            }

            if (yDown < imageHeight)
            {
                colorDifference +=
                    GMath.Abs(middleB - source[x * 3 + yDown * stride]) +
                    GMath.Abs(middleG - source[x * 3 + yDown * stride + 1]) +
                    GMath.Abs(middleR - source[x * 3 + yDown * stride + 2]);
            }

            //This will only work within blocks, pixels across block edge based on scheduling
            //That's ok for this task, as it will have small impact
            thread.SyncThreads();

            source[index] = source[index + 1] = source[index + 2] =
                (byte)(colorDifference / 12);
        }
Esempio n. 10
0
 public static TweenFunction Bounce(int bounces) =>
 bounces == -1
                 ? (TweenFunction)(t => (t == 1 ? 1 : 0))
                 : (TweenFunction)(t => GMath.Ceiling(t * (bounces + 0.5)) / (bounces + 1) * GMath.Abs(GMath.Sin(t * (bounces + 0.5) * GMath.Pi)));