Пример #1
0
 // Derivative rule
 public override Function Derivative()
 {
     if (RightFunc is Constant)
     {
         return(RightFunc * (LeftFunc ^ (RightFunc - new Constant(1))) * LeftFunc.Derivative());
     }
     return((RightFunc.Derivative() * Funcs.Ln(LeftFunc) + LeftFunc.Derivative() * RightFunc / LeftFunc) * this);
 }
Пример #2
0
 public override double Calculate(double X)
 {
     if (LeftFunc != null)
     {
         return(LeftFunc.Calculate(X) - RightFunc.Calculate(X));
     }
     else
     {
         return(-RightFunc.Calculate(X));
     }
 }
Пример #3
0
 public override Function SimplifyFunction()
 {
     if (this.LeftFunc is Digit && (this.LeftFunc as Digit).Data == 0)
     {
         return(this.LeftFunc.SimplifyFunction());
     }
     else if (this.RightFunc is Digit && (this.RightFunc as Digit).Data == 0)
     {
         return(this.RightFunc.SimplifyFunction());
     }
     else if (this.LeftFunc is Digit && (this.LeftFunc as Digit).Data == 1)
     {
         return(this.RightFunc.SimplifyFunction());
     }
     else if (this.RightFunc is Digit && (this.RightFunc as Digit).Data == 1)
     {
         return(this.LeftFunc.SimplifyFunction());
     }
     else
     {
         this.LeftFunc  = this.LeftFunc.SimplifyFunction();
         this.RightFunc = this.RightFunc.SimplifyFunction();
         //return this function if there is no x
         if ((this.LeftFunc is Digit || this.LeftFunc is n || this.LeftFunc is r) && (this.RightFunc is Digit || this.LeftFunc is n || this.LeftFunc is r))
         {
             r func = new r();
             (func as r).Data = this.Calculate(0);
             return(func);
         }
         else
         {
             if (this.LeftFunc is Digit && (this.LeftFunc as Digit).Data == 0)
             {
                 return(LeftFunc.SimplifyFunction());
             }
             else if (this.RightFunc is Digit && (this.RightFunc as Digit).Data == 0)
             {
                 return(RightFunc.SimplifyFunction());
             }
             else if (this.LeftFunc is Digit && (this.LeftFunc as Digit).Data == 1)
             {
                 return(RightFunc.SimplifyFunction());
             }
             else if (this.RightFunc is Digit && (this.RightFunc as Digit).Data == 1)
             {
                 return(LeftFunc.SimplifyFunction());
             }
             else
             {
                 return(this);
             }
         }
     }
 }
 public override decimal Calculate(decimal X)
 {
     if (LeftFunc != null)
     {
         return(LeftFunc.Calculate(X) - RightFunc.Calculate(X));
     }
     else
     {
         return(-RightFunc.Calculate(X));
     }
 }
Пример #5
0
        // Calculate function
        public override double Calc(double val)
        {
            var a = LeftFunc.Calc(val);

            if (Math.Abs(a) <= 10e-6)
            {
                return(a);
            }
            var b = RightFunc.Calc(val);

            if (Math.Abs(b) <= 10e-6)
            {
                return(b);
            }
            return(a * b);
        }
 public override decimal Calculate(decimal X)
 {
     return(LeftFunc.Calculate(X) + RightFunc.Calculate(X));
 }
Пример #7
0
 public override decimal Calculate(decimal X)
 {
     ThrowExceptionWithWrongInput();
     return((decimal)Math.Pow(Convert.ToDouble(LeftFunc.Calculate(X)), Convert.ToDouble(RightFunc.Calculate(X))));
 }
Пример #8
0
 // Latex view
 public override string Print()
 {
     return(LeftFunc.Print() + "+" + RightFunc.Print());
 }
Пример #9
0
 // Calculate function
 public override double Calc(double val)
 {
     return(LeftFunc.Calc(val) + RightFunc.Calc(val));
 }
Пример #10
0
 // Latex view
 public override string Print()
 {
     return(@"\frac{" + LeftFunc.Print() + "}{" + RightFunc.Print() + "}");
 }
Пример #11
0
 // Derivative rule
 public override Function Derivative()
 {
     return((LeftFunc.Derivative() * RightFunc - RightFunc.Derivative() * LeftFunc) / (RightFunc * RightFunc));
 }
Пример #12
0
 // Derivative rule
 public override Function Derivative()
 {
     return(LeftFunc.Derivative() * RightFunc + LeftFunc * RightFunc.Derivative());
 }
Пример #13
0
 public override decimal Calculate(decimal X)
 {
     ThrowExceptionWithDenominator0();
     return(LeftFunc.Calculate(X) / RightFunc.Calculate(X));
 }
Пример #14
0
 // Calculate function
 public override double Calc(double val)
 {
     return(Math.Pow(LeftFunc.Calc(val), RightFunc.Calc(val)));
 }
Пример #15
0
// Protected Functions

		/// <summary>
		///     Checks for user button presses and calls respective function
		/// </summary>
		/// <param name="left">Defined Left function</param>
		/// <param name="right">Defined Right function</param>
		/// <param name="up">Defined Up function</param>
		/// <param name="down">Defined Down function</param>
		protected void directionalMenuLogic(LeftFunc left, RightFunc right, UpFunc up, DownFunc down)
		{
            horiz = InputPlayers.player0.GetAxis(HorizontalButton);
            vert = InputPlayers.player0.GetAxis(VerticalButton);

            if (horiz < LIMIT && vert < LIMIT)
            {
                changeBumpers("off");
            }

			// Audio for each option if user holds down key for long enough
		//	if (!hasSounded) // To be used if the welcome instructions should be skippable if the user presses a button
			 if (horiz >= LIMIT) // Right
			 {
                if (!source.isPlaying) playDirectionalSound(rightSound);
                changeBumpers("Right");
			 }	
			 else if (horiz <= -(LIMIT) ) // Left
			 {
                if (!source.isPlaying) playDirectionalSound(leftSound);
                changeBumpers("Left");
            }	
           
			 if (vert >= LIMIT) // Up
			 {
                if (!source.isPlaying) playDirectionalSound(upSound);
                changeBumpers("Up");
            }
			 else if (vert <= -(LIMIT) ) // Down
			 {
                if (!source.isPlaying) playDirectionalSound(downSound);
                changeBumpers("Down");
            }

            if (InputPlayers.player0.GetButtonDown(SubmitButton))
            {
                if (horiz > LIMIT) // Right
                {
                    right();
                }
                else if (horiz < -1*LIMIT) // Left
                {
                    left();
                }

                if (vert > LIMIT) // Up
                {
                    up();
                }
                else if (vert < -1*LIMIT) // Down
                {
                    down();
                }
            }

        }
Пример #16
0
 public override double Calculate(double X)
 {
     ThrowExceptionWithWrongInput();
     return(Math.Pow(LeftFunc.Calculate(X), RightFunc.Calculate(X)));
 }
Пример #17
0
        public void PaintTopInGame(ClipState clipState)
        {
            if (clipState != ClipState.BeforeClip)
            {
                return;
            }

            var x = Hud.Window.Size.Width * RatioX;
            var y = Hud.Window.Size.Height * RatioY;
            var w = Hud.Window.Size.Height * RatioWidth;
            var s = Hud.Window.Size.Height * RatioSpacerY;
            var p = Hud.Window.Size.Height * RatioPaddingY;

            if (RightFunc != null)
            {
                x = RightFunc.Invoke(Hud);
            }

            switch (TextAlign)
            {
            case HorizontalAlign.Center:
                x -= w / 2;
                break;

            case HorizontalAlign.Right:
                x -= w;
                break;
            }

            var alerts = Alerts.Where(a => a.Enabled && a.Visible);

            if (VerticalCenter)
            {
                Up = false;
                var heigth = alerts.Select(a => a.Label.TextFont.GetTextLayout(":").Metrics.Height + s + p * 2).Sum() - s - p * 2;
                //y += Up ? heigth / 2 : -heigth / 2;
                y -= heigth / 2;
            }
            foreach (var alert in alerts)
            {
                var alertLayout = alert.Label.TextFont.GetTextLayout(":");
                var h           = alertLayout.Metrics.Height;

                if (alert.MultiLine && alert.LinesFunc != null)
                {
                    foreach (var line in alert.LinesFunc.Invoke())
                    {
                        alert.AlertText = line;
                        alert.Label.Paint(x, y - p, w, h + p * 2, TextAlign);
                        y += Up ? -h : h;
                    }
                    //h = h + s + p * 2;
                }
                else
                {
                    alert.Label.Paint(x, y - p, w, h + p * 2, TextAlign);
                    h  = h + s + p * 2;
                    y += Up ? -h : h;
                }
            }
        }
Пример #18
0
 public override double Calculate(double X)
 {
     return(LeftFunc.Calculate(X) + RightFunc.Calculate(X));
 }