示例#1
0
        public ViewModel()
        {
            _plot = new Plots();

            Cosinus cosinus = new Cosinus();

            cosinus.PropertyChanged += (s, e) => { RaisePropertyChanged("Amplitude_Cos"); };
            MyFunction.Add(cosinus);

            Sinus sinus = new Sinus();

            sinus.PropertyChanged += (s, e) => { RaisePropertyChanged("Amplitude_Sin"); };
            MyFunction.Add(sinus);

            Tangens tangens = new Tangens();

            tangens.PropertyChanged += (s, e) => { RaisePropertyChanged("Amplitude_Tan"); };
            MyFunction.Add(tangens);

            Cotangens cotangens = new Cotangens();

            cotangens.PropertyChanged += (s, e) => { RaisePropertyChanged("Amplitude_Cot"); };
            MyFunction.Add(cotangens);

            plotModel = new PlotModel();
            plotModel = _plot._PlotModel;
        }
示例#2
0
        public void CalculateTest(double firstValue, double expected)
        {
            var calculator   = new Sinus();
            var actualResult = calculator.Calculate(firstValue);

            Assert.AreEqual(expected, actualResult, 0.0001);
        }
示例#3
0
        public void SinusTest()
        {
            Sinus  calculator = new Sinus();
            double result     = calculator.Calculate(0);

            Assert.AreEqual(0, result);
        }
示例#4
0
        public void CalculateTest(double first, double second, double expected)
        {
            var calculator   = new Sinus();
            var actualresult = calculator.Calculate(first);

            Assert.AreEqual(expected, actualresult, 0.01);
        }
示例#5
0
        public void Calculate(double argument, double result)
        {
            var calculator = new Sinus();
            var testresult = calculator.Calculate(argument);

            Assert.AreEqual(result, testresult);
        }
示例#6
0
        public void CalculateSinTest(double firstValue, double expected)
        {
            IOneArgumentCalculator calculator = new Sinus();
            double result = calculator.Calculate(firstValue);

            Assert.AreEqual(expected, result);
        }
示例#7
0
        public void CalculateTest()
        {
            IOneArgumentCalculator calculator = new Sinus();
            double result = calculator.Calculate(1);

            Assert.AreEqual(0.84, result, 0.01);
        }
示例#8
0
        public void SinusTest(double first, double expected)
        {
            var    calc   = new Sinus();
            double result = calc.Calculate(first);

            Assert.AreEqual(expected, result);
        }
示例#9
0
文件: Sinus.cs 项目: csetzkorn/GeMoea
        public override object Clone()
        {
            var returnObject = new Sinus
            {
                FunctionName = string.Copy(FunctionName),
                Middle       = Middle
            };

            return(returnObject);
        }
示例#10
0
    static void Main()
    {
        Stopwatch watch = new Stopwatch();

        // SQRT
        Console.WriteLine("SQRT:");
        watch.Restart();
        Sqrt.FloatSqrt(1f, 10000000f, 1f);
        watch.Stop();
        Console.WriteLine("Float: " + watch.ElapsedMilliseconds);

        watch.Restart();
        Sqrt.DoubleSqrt(1d, 10000000d, 1d);
        watch.Stop();
        Console.WriteLine("Double: " + watch.ElapsedMilliseconds);

        watch.Restart();
        Sqrt.DecimalSqrt(1m, 10000000m, 1m);
        watch.Stop();
        Console.WriteLine("Decimal: " + watch.ElapsedMilliseconds);

        // Sinus
        Console.WriteLine("Sinus:");
        watch.Restart();
        Sinus.FloatSinus(1f, 10000000f, 1f);
        watch.Stop();
        Console.WriteLine("Float: " + watch.ElapsedMilliseconds);

        watch.Restart();
        Sinus.DoubleSinus(1d, 10000000d, 1d);
        watch.Stop();
        Console.WriteLine("Double: " + watch.ElapsedMilliseconds);

        watch.Restart();
        Sinus.DecimalSinus(1m, 10000000m, 1m);
        watch.Stop();
        Console.WriteLine("Decimal: " + watch.ElapsedMilliseconds);

        // Logarithm
        Console.WriteLine("Logarithm:");
        watch.Restart();
        Logarithm.FloatLogarithm(1f, 10000000f, 1f);
        watch.Stop();
        Console.WriteLine("Float: " + watch.ElapsedMilliseconds);

        watch.Restart();
        Logarithm.DoubleLogarithm(1d, 10000000d, 1d);
        watch.Stop();
        Console.WriteLine("Double: " + watch.ElapsedMilliseconds);

        watch.Restart();
        Logarithm.DecimalLogarithm(1m, 10000000m, 1m);
        watch.Stop();
        Console.WriteLine("Decimal: " + watch.ElapsedMilliseconds);
    }
        public void Sinus_Is_Replaced_By_Result()
        {
            var input = new Sinus {
                Value = 9
            };

            new ExpressionsWithOnlyConstantChildrenSimplifier().Simplify(input)
            .Should()
            .BeOfType <Constant>()
            .Which.Value.Should()
            .Be(9);
        }
示例#12
0
        static void Main(string[] args)
        {
            Sqrt.DisplayAll();
            Console.WriteLine("----------------------------");

            //Logarithm throws StackOverflowException
            // Logarithm.DisplayAll();
            Console.WriteLine("----------------------------");

            Sinus.DisplayAll();
            Console.WriteLine("----------------------------");
        }
示例#13
0
 protected override void EvaluateSinus(Sinus sinusExpression) => ChangeResultIfTreeDepthIsHigher(sinusExpression);
示例#14
0
 public void Visit(Sinus sinusExpression)
 {
     SetDepth(sinusExpression);
 }
 public void Visit(Sinus sinusExpression)
 {
     Result = UseSinus(sinusExpression.Value);
 }
示例#16
0
 public void Visit(Sinus sinusExpression)
 {
     mListOfMultipliableExpressions.Add(sinusExpression);
 }
示例#17
0
 public void Visit(Sinus sinusExpression)
 {
     mSecondExpressions.Add(sinusExpression);
 }
 protected override IExpression ReplaceSinus(Sinus sinus) => new Constant
 {
     Value = sinus.Value
 };
 private void ParseNextPart(ref OperationClass a, ref bool isExpressionNotEnded)
 {
     if (l < expression.Length)
     {
         string s = expression.Substring(l);
         if (Regex.IsMatch(s, digits, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, digits, RegexOptions.IgnoreCase);
             s  = s.Substring(0, digit.Length);
             a  = new Value(float.Parse(s));
             l += digit.Length;
         }
         else if (Regex.IsMatch(s, cos, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, cos, RegexOptions.IgnoreCase);
             l += digit.Length;
             OperationClass b = new Value(0);
             Parse(ref b);
             a = new Cosinus(b);
         }
         else if (Regex.IsMatch(s, sin, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, sin, RegexOptions.IgnoreCase);
             l += digit.Length;
             OperationClass b = new Value(0);
             Parse(ref b);
             a = new Sinus(b);
         }
         else if (Regex.IsMatch(s, tangent, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, tangent, RegexOptions.IgnoreCase);
             l += digit.Length;
             OperationClass b = new Value(0);
             Parse(ref b);
             a = new Tangent(b);
         }
         else if (Regex.IsMatch(s, plus, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, plus, RegexOptions.IgnoreCase);
             l += digit.Length;
             Plus b = new Plus();
             b.FirstOperand = a;
             ParseNextPart(ref b.SecondOperand, ref isExpressionNotEnded);
             a = b;
         }
         else if (Regex.IsMatch(s, minus, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, minus, RegexOptions.IgnoreCase);
             l += digit.Length;
             Minus b = new Minus();
             b.FirstOperand = a;
             ParseNextPart(ref b.SecondOperand, ref isExpressionNotEnded);
             a = b;
         }
         else if (Regex.IsMatch(s, multipl, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, multipl, RegexOptions.IgnoreCase);
             l += digit.Length;
             Multiplication b = new Multiplication();
             ParseNextPart(ref b.SecondOperand, ref isExpressionNotEnded);
             if (a.Priority > 2)
             {
                 BasicOperations buff = a as BasicOperations;
                 b.FirstOperand     = buff.SecondOperand;
                 buff.SecondOperand = b;
                 a = buff;
             }
             else
             {
                 b.FirstOperand = a;
                 a = b;
             }
         }
         else if (Regex.IsMatch(s, divide, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, divide, RegexOptions.IgnoreCase);
             l += digit.Length;
             Division b = new Division();
             ParseNextPart(ref b.SecondOperand, ref isExpressionNotEnded);
             if (a.Priority > 2)
             {
                 BasicOperations buff = a as BasicOperations;
                 b.FirstOperand     = buff.SecondOperand;
                 buff.SecondOperand = b;
                 a = buff;
             }
             else
             {
                 b.FirstOperand = a;
                 a = b;
             }
         }
         else if (Regex.IsMatch(s, power, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, power, RegexOptions.IgnoreCase);
             l += digit.Length;
             Power b = new Power();
             ParseNextPart(ref b.SecondOperand, ref isExpressionNotEnded);
             if (a.Priority == -3)
             {
                 b.FirstOperand = a;
                 a = b;
             }
             //BasicOperations buff = a as BasicOperations;
             //b.FirstOperand = buff.SecondOperand;
             //buff.SecondOperand = b;
             //a = buff;
         }
         else if (Regex.IsMatch(s, e, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, e, RegexOptions.IgnoreCase);
             l += digit.Length;
             a  = new E();
         }
         else if (Regex.IsMatch(s, pi, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, pi, RegexOptions.IgnoreCase);
             l += digit.Length;
             a  = new PI();
         }
         else if (Regex.IsMatch(s, openingbracket, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, openingbracket, RegexOptions.IgnoreCase);
             l += digit.Length;
             Parse(ref a);
         }
         else if (Regex.IsMatch(s, closingbracket, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, closingbracket, RegexOptions.IgnoreCase);
             l += digit.Length;
             if (Regex.IsMatch(s, power, RegexOptions.IgnoreCase))
             {
                 digit = Regex.Match(s, power, RegexOptions.IgnoreCase);
                 l    += digit.Length;
                 Power b = new Power();
                 ParseNextPart(ref b.SecondOperand, ref isExpressionNotEnded);
                 b.FirstOperand = a;
                 a = b;
             }
             isExpressionNotEnded = false;
         }
         else if (Regex.IsMatch(s, t, RegexOptions.IgnoreCase))
         {
             Match digit = Regex.Match(s, t, RegexOptions.IgnoreCase);
             l += digit.Length;
             a  = new Tparam();
         }
     }
     else
     {
         isExpressionNotEnded = false;
     }
 }
示例#20
0
 // Use this for initialization
 void Awake()
 {
     sinus = GetComponent <Sinus>();
     sinus.SetOn(true);
 }
示例#21
0
 protected override void EvaluateSinus(Sinus sinusExpression) => IncreaseCount();
示例#22
0
        /// <summary>
        ///     Function expression
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Function VisitFunction(CalculatorParser.FunctionContext context)
        {
            Function res = null;

            //Trigonometric functions
            if (FunctionMap[context.fun.Type] is Sinus)
            {
                res = new Sinus(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is Cosinus)
            {
                res = new Cosinus(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is Tangens)
            {
                res = new Tangens(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is Cotangens)
            {
                res = new Cotangens(Visit(context.expr()));
            }

            //Elementary functions
            if (FunctionMap[context.fun.Type] is Sqrt)
            {
                res = new Sqrt(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is Logarithm)
            {
                res = new Logarithm(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is Exponenta)
            {
                res = new Exponenta(Visit(context.expr()));
            }

            //Inverse Trigonometric functions
            if (FunctionMap[context.fun.Type] is ArcSinus)
            {
                res = new ArcSinus(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is ArcCosinus)
            {
                res = new ArcCosinus(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is ArcTangens)
            {
                res = new ArcTangens(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is ArcCotangens)
            {
                res = new ArcCotangens(Visit(context.expr()));
            }

            //Hyperbolic functions
            if (FunctionMap[context.fun.Type] is HypSinus)
            {
                res = new HypSinus(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is HypCosinus)
            {
                res = new HypCosinus(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is HypTangens)
            {
                res = new HypTangens(Visit(context.expr()));
            }
            if (FunctionMap[context.fun.Type] is HypCotangens)
            {
                res = new HypCotangens(Visit(context.expr()));
            }

            return(res);
        }
示例#23
0
 public void Visit(Sinus sinusExpression)
 {
     mExpressionCount++;
 }
 public void Visit(Sinus sinusExpression)
 {
 }
示例#25
0
        private UniversalOperation ParsingAnExpression_VeryHighPriority()
        {
            UniversalOperation result;

            if (MatchSearch('-'))
            {
                result = new Negation(ParsingAnExpression_LowPriority());
            }
            else if (MatchSearch('('))
            {
                result = ParsingAnExpression_LowPriority();

                if (!MatchSearch(')'))
                {
                    throw new System.Exception("Missing ')'");
                }
            }
            else if (MatchSearch('x'))
            {
                return(X);
            }
            else if (position < _currentExpression.Length && char.IsDigit(_currentExpression[position]))
            {
                result = ParsingAnExpression_Number();
            }
            #region Functions
            else if (MatchSearch("sin("))
            {
                result = new Sinus(ParsingAnExpression_LowPriority());
                if (!MatchSearch(')'))
                {
                    throw new System.Exception("Missing ')' for sin");
                }
            }
            else if (MatchSearch("cos("))
            {
                result = new Cosine(ParsingAnExpression_LowPriority());
                if (!MatchSearch(')'))
                {
                    throw new System.Exception("Missing ')' for cos");
                }
            }
            else if (MatchSearch("tan("))
            {
                result = new Tangent(ParsingAnExpression_LowPriority());
                if (!MatchSearch(')'))
                {
                    throw new System.Exception("Missing ')' for tan");
                }
            }
            else if (MatchSearch("sqrt("))
            {
                result = new Sqrt(ParsingAnExpression_LowPriority());
                if (!MatchSearch(')'))
                {
                    throw new System.Exception("Missing ')' for sqrt");
                }
            }
            else if (MatchSearch("exp("))
            {
                result = new Exp(ParsingAnExpression_LowPriority());
                if (!MatchSearch(')'))
                {
                    throw new System.Exception("Missing ')' for exp");
                }
            }
            else if (MatchSearch("ln("))
            {
                result = new Ln(ParsingAnExpression_LowPriority());
                if (!MatchSearch(')'))
                {
                    throw new System.Exception("Missing ')' for ln");
                }
            }
            #endregion
            #region Constants
            else if (MatchSearch("PI"))
            {
                return(new PI());
            }
            else if (MatchSearch("E"))
            {
                return(new E());
            }
            #endregion
            else
            {
                throw new System.Exception("Can't parse character at pos " + position.ToString() + "");
            }
            return(result);
        }
示例#26
0
 void IExpressionVisitor.Visit(Sinus sinus) => mResult = ReplaceSinus(sinus);
示例#27
0
        public void CalculateTestExceptionTest()
        {
            IOneArgumentCalculator calculator = new Sinus();

            Assert.Throws <Exception>(() => calculator.Calculate(3));
        }
 public Moving(int start, int finish)
 {
     Start = start;
     Finish = finish;
     int mlt = Math.Sign(start - finish);
     sinus = new Sinus(0, (random.Next(6) + 2) * mlt);
 }
示例#29
0
 protected virtual IExpression ReplaceSinus(Sinus sinus) => sinus;
示例#30
0
        public Node <INode> GetNode(string nodeName)
        {
            switch (nodeName)
            {
            case Absolute.NAME:
                INode nodeAbsolute = new Absolute() as INode;
                return(new Node <INode>(nodeAbsolute));

            case Approx.NAME:
                INode nodeAprox = new Approx() as INode;
                return(new Node <INode>(nodeAprox));

            case ArcCos.NAME:
                INode nodeArcCos = new ArcCos() as INode;
                return(new Node <INode>(nodeArcCos));

            case ArcSin.NAME:
                INode nodeArcSin = new ArcSin() as INode;
                return(new Node <INode>(nodeArcSin));

            case ArcTan2.NAME:
                INode nodeArcTan2 = new ArcTan2() as INode;
                return(new Node <INode>(nodeArcTan2));

            case Ceil.NAME:
                INode nodeCeil = new Ceil() as INode;
                return(new Node <INode>(nodeCeil));

            case CeilToInt.NAME:
                INode nodeCeilToInt = new CeilToInt() as INode;
                return(new Node <INode>(nodeCeilToInt));

            case Clamp.NAME:
                INode nodeClamp = new Clamp() as INode;
                return(new Node <INode>(nodeClamp));

            case Clamp01.NAME:
                INode nodeClamp01 = new Clamp01() as INode;
                return(new Node <INode>(nodeClamp01));

            case ClosestPowerOf2.NAME:
                INode nodeClosestPowerOf2 = new ClosestPowerOf2() as INode;
                return(new Node <INode>(nodeClosestPowerOf2));

            case Cosinus.NAME:
                INode nodeCosinus = new Cosinus() as INode;
                return(new Node <INode>(nodeCosinus));

            case DeltaAngle.NAME:
                INode nodeDeltaAngle = new DeltaAngle() as INode;
                return(new Node <INode>(nodeDeltaAngle));

            case Exp.NAME:
                INode nodeExp = new Exp() as INode;
                return(new Node <INode>(nodeExp));

            case Floor.NAME:
                INode nodeFloor = new Floor() as INode;
                return(new Node <INode>(nodeFloor));

            case FloorToInt.NAME:
                INode nodeFloorToInt = new FloorToInt() as INode;
                return(new Node <INode>(nodeFloorToInt));

            case Lerp.NAME:
                INode nodeLerp = new Lerp() as INode;
                return(new Node <INode>(nodeLerp));

            case LerpAngle.NAME:
                INode nodeLerpAngle = new LerpAngle() as INode;
                return(new Node <INode>(nodeLerpAngle));

            case Log10.NAME:
                INode nodeLog10 = new Log10() as INode;
                return(new Node <INode>(nodeLog10));

            case Logarithm.NAME:
                INode nodeLogarithm = new Logarithm() as INode;
                return(new Node <INode>(nodeLogarithm));

            case Sinus.NAME:
                INode nodeSinus_ = new Sinus() as INode;
                return(new Node <INode>(nodeSinus_));

            case Max.NAME:
                INode nodeMax = new Max() as INode;
                return(new Node <INode>(nodeMax));

            case Min.NAME:
                INode nodeMin = new Min() as INode;
                return(new Node <INode>(nodeMin));

            case MoveTowards.NAME:
                INode nodeMoveTowards = new MoveTowards() as INode;
                return(new Node <INode>(nodeMoveTowards));

            case MoveTowardsAngle.NAME:
                INode nodeMoveTowardsAngle = new MoveTowardsAngle() as INode;
                return(new Node <INode>(nodeMoveTowardsAngle));

            case NextPowerOfTwo.NAME:
                INode nodeNextPowerOfTwo = new NextPowerOfTwo() as INode;
                return(new Node <INode>(nodeNextPowerOfTwo));

            case PerlinNoise.NAME:
                INode nodePerlinNoise = new PerlinNoise() as INode;
                return(new Node <INode>(nodePerlinNoise));

            case PingPong.NAME:
                INode nodePingPong = new PingPong() as INode;
                return(new Node <INode> (nodePingPong));

            case Pow.NAME:
                INode nodePow = new Pow() as INode;
                return(new Node <INode>(nodePow));

            case SquareRoot.NAME:
                INode nodeSqrt = new SquareRoot() as INode;
                return(new Node <INode>(nodeSqrt));

            case Tan.NAME:
                INode nodeTan = new Tan() as INode;
                return(new Node <INode>(nodeTan));

            case Random.NAME:
                INode nodeRandom = new Random() as INode;
                return(new Node <INode>(nodeRandom));

            default:
                return(null);
            }
        }
示例#31
0
 // Use this for initialization
 void Awake()
 {
     sinus = GetComponent <Sinus>();
 }