public void SuccessfullyCalculateSineOfPositiveAngle()
        {
            var value    = 60;
            var function = new SineFunction();

            var phase = function.Calculate();

            Assert.NotNull(phase);
            Assert.Equal("Specify Argument", phase.Name);
            Assert.Equal("Specify angle to find the sine of.", phase.Description);
            Assert.Collection(phase.Inputs,
                              i =>
            {
                Assert.Equal("Angle", i.Info.Name);
                Assert.Null(i.Info.Description);
                Assert.Equal(new RadianUnit(), i.Info.Unit);
            });

            phase.Inputs[0].Value = value;

            Assert.Null(function.Calculate(phase));

            Assert.Collection(function.CurrentResult,
                              i =>
            {
                Assert.Equal(typeof(double), i.ValueType);
                Assert.Equal(Math.Sin(value), TypeConverter.ToObject <double>(i.Value));
            });
        }
        private void ButtonCreate_Click(object sender, RoutedEventArgs e)
        {
            SineFunction sineFunc = new SineFunction()
            {
                Amplitude = 1,
                Frequency = 1,
                Phase     = 0,
                LinePen   = PadUtility.RandomColorPen(DefaultLineThickness)
            };

            SineScene.FunctionList.Add(sineFunc);
        }
        public void SuccessfullySetFunctionInfo()
        {
            var function = new SineFunction();

            Assert.NotNull(function.FunctionInfo);
            Assert.Equal("Sine", function.FunctionInfo.Name);
            Assert.Equal(new Version("1.0.0"), function.FunctionInfo.Version);
            Assert.Equal("Find the sine of an angle.", function.FunctionInfo.Description);
            Assert.Collection(function.FunctionInfo.Tags,
                              i => Assert.Equal("sine", i),
                              i => Assert.Equal("sin", i));
        }
Example #4
0
        public override Geometry CreateFunctionGeometry(IFunction function)
        {
            SineFunction sinFunc = function as SineFunction;

            Point        startPoint;
            PathGeometry sineGeometry = new PathGeometry();
            PathFigure   figure       = new PathFigure();
            PathSegment  sineSegement = this.CreateSineSegement(sinFunc, out startPoint);

            figure.Segments.Add(sineSegement);
            figure.StartPoint = startPoint;
            sineGeometry.Figures.Add(figure);
            return(sineGeometry);
        }
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            SineFunction selectedFunc = DataGridSineList.SelectedItem as SineFunction;

            if (selectedFunc == null)
            {
                return;
            }

            if (!PadMessage.Confirm("确定要删除选中的函数图像吗?"))
            {
                return;
            }

            SineScene.FunctionList.Remove(selectedFunc);
        }
Example #6
0
        public void HashTestProgram()
        {
            var const1   = new Constant(0);
            var const2   = new Constant(1);
            var variable = new Variable("a");
            var sine     = new SineFunction(const2);
            var pow      = new PowerFunction(const1, variable);
            var subtr    = new SubtractionFunction(const2, pow);
            var min      = new MinFunction(subtr, const1);
            var div      = new DivisionFunction(pow, variable);
            var prog     = new IfFunction(div, min, subtr, sine);
            var hashCode = prog.GetHashCode();

            Console.WriteLine($"{prog}:{hashCode}");
            Assert.AreNotEqual(hashCode, 0, double.Epsilon, $"Hash code of {prog} should not be 0.");
        }
        public void TestSine()
        {
            //Arrange
            VariableNode variableNode = new VariableNode();
            PiNode       piNode       = new PiNode();
            SineFunction sineNode1    = new SineFunction(variableNode);
            SineFunction sineNode2    = new SineFunction(piNode);

            //Act
            double result1 = sineNode1.Calculate(0);
            double result2 = sineNode2.Calculate(0);

            //Assert
            Assert.AreEqual(0, result1);
            Assert.AreEqual(0, Math.Round(result2, 15));
        }
        public void SuccessfullyCalculateSineWithNoAngleSpecified()
        {
            var function = new SineFunction();

            var phase = function.Calculate();

            Assert.NotNull(phase);

            Assert.Null(function.Calculate(phase));

            Assert.Collection(function.CurrentResult,
                              i =>
            {
                Assert.Equal(typeof(double), function.CurrentResult[0].ValueType);
                Assert.Equal(Math.Sin(0.0), TypeConverter.ToObject <double>(function.CurrentResult[0].Value));
            });
        }
        public void SuccessfullyCalculateSineOfNegativeAngle()
        {
            var value    = -54;
            var function = new SineFunction();

            var phase = function.Calculate();

            Assert.NotNull(phase);

            phase.Inputs[0].Value = value;

            Assert.Null(function.Calculate(phase));

            Assert.Collection(function.CurrentResult,
                              i =>
            {
                Assert.Equal(typeof(double), i.ValueType);
                Assert.Equal(Math.Sin(value), TypeConverter.ToObject <double>(i.Value));
            });
        }
Example #10
0
        public override void Create()
        {
            Factory.BallSprite = "red-circle_frank-tschakert";
            for (float x = 250f; x < 800f; x += 200f)
            {
                for (float y = 150f; y < 668f; y += 200f)
                {
                    var b = Factory.CreateMovingBall(new Vector2(x, y), Vector2.Zero);
                    b.AddComponent(new ScaleComp());

                    // to each ball, we add a sinusoid based modification of the Scale parameter.
                    var m = new SineFunction();
                    m.Amplitude = RandomMath.RandomBetween(0.05f, 0.4f);
                    m.Frequency = RandomMath.RandomBetween(0.04f, 0.3f);
                    m.Phase = RandomMath.RandomBetween(0f, MathHelper.TwoPi);
                    m.Offset = RandomMath.RandomBetween(0.45f, 0.8f);
                    TestFactory.AddModifier(b, delegate(ScriptContext ctx, double value)
                        {ctx.Entity.GetComponent<ScaleComp>().Scale = value;} , m);
                }
            }
        }
Example #11
0
        private PathSegment CreateSineSegement(SineFunction sinFunc, out Point firstPoint)
        {
            PolyBezierSegment segement = new PolyBezierSegment();

            for (int angle = 0; angle < 360; angle++)
            {
                double x = Math.PI / 180 * angle;   // 自变量X的值

                double y = sinFunc.Calculate(x);

                y = this.OriginalPoint.Y + y * this.UnitPerPixel;

                //QuadraticBezierSegment qb = new QuadraticBezierSegment();
                //qb.Point1 = new Point(x, y);
                //qb.Point2 = new Point(x, y);
                //figure.Segments.Add(qb);
                segement.Points.Add(new Point(this.OriginalPoint.X + angle, y));
            }

            firstPoint = segement.Points[0];

            return(segement);
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SineOperNode"/> class.
 /// </summary>
 /// <param name="func">The sine function of the <see cref="SineOperNode"/>.</param>
 public SineOperNode(SineFunction func)
 {
     SineFunction = func;
 }
        /// <summary>
        /// Tries to create an Leviathan Function expression if the function Uri correseponds to a supported Leviathan Function
        /// </summary>
        /// <param name="u">Function Uri</param>
        /// <param name="args">Function Arguments</param>
        /// <param name="scalarArgs">Scalar Arguments</param>
        /// <param name="expr">Generated Expression</param>
        /// <returns>Whether an expression was successfully generated</returns>
        public bool TryCreateExpression(Uri u, List <ISparqlExpression> args, Dictionary <String, ISparqlExpression> scalarArgs, out ISparqlExpression expr)
        {
            // If any Scalar Arguments are present then can't possibly be a Leviathan Function
            if (scalarArgs.Count > 0)
            {
                expr = null;
                return(false);
            }

            String func = u.ToString();

            if (func.StartsWith(LeviathanFunctionsNamespace))
            {
                func = func.Substring(LeviathanFunctionsNamespace.Length);
                ISparqlExpression lvnFunc = null;

                switch (func)
                {
                case All:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new AllAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new AllAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for Leviathan all() aggregate");
                    }
                    break;

                case Any:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new AnyAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new AnyAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for Leviathan any() aggregate");
                    }
                    break;

                case Cartesian:
                    if (args.Count == 4)
                    {
                        lvnFunc = new CartesianFunction(args[0], args[1], args[2], args[3]);
                    }
                    else if (args.Count == 6)
                    {
                        lvnFunc = new CartesianFunction(args[0], args[1], args[2], args[3], args[4], args[5]);
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for Leviathan cartesian() function");
                    }
                    break;

                case Cube:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CubeFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan cube() function");
                    }
                    break;

                case DegreesToRadians:
                    if (args.Count == 1)
                    {
                        lvnFunc = new DegreesToRadiansFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan degrees-to-radians() function");
                    }
                    break;

                case E:
                    if (args.Count == 1)
                    {
                        lvnFunc = new EFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan e() function");
                    }
                    break;

                case Factorial:
                    if (args.Count == 1)
                    {
                        lvnFunc = new FactorialFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan factorial() function");
                    }
                    break;

                case Ln:
                    if (args.Count == 1)
                    {
                        lvnFunc = new LeviathanNaturalLogFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan ln() function");
                    }
                    break;

                case Log:
                    if (args.Count == 1)
                    {
                        lvnFunc = new LogFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new LogFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan log() function");
                    }
                    break;

                case MD5Hash:
                    if (args.Count == 1)
                    {
                        lvnFunc = new MD5HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan md5hash() function");
                    }
                    break;

                case Median:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new MedianAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new MedianAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan median() aggregate");
                    }
                    break;

                case Mode:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new ModeAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new ModeAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan mode() aggregate");
                    }
                    break;

                case None:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new NoneAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new NoneAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan none() aggregate");
                    }
                    break;

                case NumericMax:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new NumericMaxAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new NumericMaxAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan nmax() aggregate");
                    }
                    break;

                case NumericMin:
                    if (args.Count == 1)
                    {
                        lvnFunc = new AggregateTerm(new NumericMinAggregate(args.First()));
                    }
                    else if (args.Count == 2 && args.First() is DistinctModifier)
                    {
                        lvnFunc = new AggregateTerm(new NumericMinAggregate(args.Last(), true));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan nmin() aggregate");
                    }
                    break;

                case Power:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new PowerFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan pow() function");
                    }
                    break;

                case Pythagoras:
                    if (args.Count == 2)
                    {
                        lvnFunc = new PythagoreanDistanceFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan pythagoras() function");
                    }
                    break;

                case RadiansToDegrees:
                    if (args.Count == 1)
                    {
                        lvnFunc = new RadiansToDegreesFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan radians-to-degrees() function");
                    }
                    break;

                case Random:
                    if (args.Count == 0)
                    {
                        lvnFunc = new RandomFunction();
                    }
                    else if (args.Count == 1)
                    {
                        lvnFunc = new RandomFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new RandomFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan rnd() function");
                    }
                    break;

                case Reciprocal:
                    if (args.Count == 1)
                    {
                        lvnFunc = new ReciprocalFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan reciprocal() function");
                    }
                    break;

                case Root:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareRootFunction(args.First());
                    }
                    else if (args.Count == 2)
                    {
                        lvnFunc = new RootFunction(args.First(), args.Last());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan root() function");
                    }
                    break;

                case Sha256Hash:
                    if (args.Count == 1)
                    {
                        lvnFunc = new Sha256HashFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan sha256hash() function");
                    }
                    break;

                case Square:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan sq() function");
                    }
                    break;

                case SquareRoot:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SquareRootFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan sqrt() function");
                    }
                    break;

                case Ten:
                    if (args.Count == 1)
                    {
                        lvnFunc = new TenFunction(args.First());
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan ten() function");
                    }
                    break;

                case TrigCos:
                case TrigCosInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CosineFunction(args.First(), func.Equals(TrigCosInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case TrigCosec:
                case TrigCosecInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CosecantFunction(args.First(), func.Equals(TrigCosecInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case TrigCotan:
                case TrigCotanInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new CotangentFunction(args.First(), func.Equals(TrigCotanInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case TrigSec:
                case TrigSecInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SecantFunction(args.First(), func.Equals(TrigSecInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case TrigSin:
                case TrigSinInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new SineFunction(args.First(), func.Equals(TrigSinInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;

                case TrigTan:
                case TrigTanInv:
                    if (args.Count == 1)
                    {
                        lvnFunc = new TangentFunction(args.First(), func.Equals(TrigTanInv));
                    }
                    else
                    {
                        throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function");
                    }
                    break;
                }

                if (lvnFunc != null)
                {
                    expr = lvnFunc;
                    return(true);
                }
            }
            expr = null;
            return(false);
        }