Esempio n. 1
0
        public Expression Process(ParameterExpression ctxExpression, Type parameterType)
        {
            var leftExpression = ctxExpression.EvaluateExpression(Left, false);

            leftExpression = leftExpression.AddToStringWithEnumType();
            if (Operator != Operator.IsNull && Operator != Operator.NotIsNull)
            {
                leftExpression = leftExpression.AddValueWithNullableNumberType();
            }
            var        leftSideType = leftExpression.Type;
            Expression rightExpression;

            if (RightSideIsExpression)
            {
                rightExpression = ctxExpression.EvaluateExpression(Right);
                rightExpression = rightExpression.AddToStringWithEnumType().AddValueWithNullableNumberType();
            }
            else
            {
                rightExpression = GetRightConstantExpression(leftSideType);
            }

            Expression generatedExpression;

            switch (Operator)
            {
            case Operator.Equals:
                generatedExpression = Expression.Equal(leftExpression, rightExpression);
                break;

            case Operator.NotEquals:
                generatedExpression = Expression.Not(Expression.Equal(leftExpression, rightExpression));
                break;

            case Operator.GreaterThan:
                generatedExpression = leftExpression.Type == typeof(DateTime)
                        ? Expression.MakeBinary(ExpressionType.GreaterThan, leftExpression, rightExpression)
                        : Expression.GreaterThan(leftExpression, rightExpression);
                break;

            case Operator.GreaterOrEqual:
                generatedExpression = leftExpression.Type == typeof(DateTime)
                        ? Expression.MakeBinary(ExpressionType.GreaterThanOrEqual, leftExpression, rightExpression)
                        : Expression.GreaterThanOrEqual(leftExpression, rightExpression);
                break;

            case Operator.LessThan:
                generatedExpression = leftExpression.Type == typeof(DateTime)
                        ? Expression.MakeBinary(ExpressionType.LessThan, leftExpression, rightExpression)
                        : Expression.LessThan(leftExpression, rightExpression);
                break;

            case Operator.LessOrEqual:
                generatedExpression = leftExpression.Type == typeof(DateTime)
                        ? Expression.MakeBinary(ExpressionType.LessThanOrEqual, leftExpression, rightExpression)
                        : Expression.LessThanOrEqual(leftExpression, rightExpression);
                break;

            case Operator.Contains:
                generatedExpression = new Contains(leftExpression, rightExpression).Create();
                break;

            case Operator.NotContains:
                generatedExpression = Expression.Not(new Contains(leftExpression, rightExpression).Create());
                break;

            case Operator.ContainsAll:
                generatedExpression = new ContainsAll(leftExpression, rightExpression).Create();
                break;

            case Operator.NotContainsAll:
                generatedExpression = Expression.Not(new ContainsAll(leftExpression, rightExpression).Create());
                break;

            case Operator.StartsWith:
                generatedExpression = new StartsWith(leftExpression, rightExpression).Create();
                break;

            case Operator.NotStartsWith:
                generatedExpression = Expression.Not(new StartsWith(leftExpression, rightExpression).Create());
                break;

            case Operator.In:
                generatedExpression = new In(leftExpression, rightExpression).Create();
                break;

            case Operator.NotIn:
                generatedExpression = Expression.Not(new In(leftExpression, rightExpression).Create());
                break;

            case Operator.AllIn:
                generatedExpression = new AllIn(leftExpression, rightExpression).Create();
                break;

            case Operator.NotAllIn:
                generatedExpression = Expression.Not(new AllIn(leftExpression, rightExpression).Create());
                break;

            case Operator.AnyIn:
                generatedExpression = new AnyIn(leftExpression, rightExpression).Create();
                break;

            case Operator.NotAnyIn:
                generatedExpression = Expression.Not(new AnyIn(leftExpression, rightExpression).Create());
                break;

            case Operator.IsNull:
                if (leftSideType.IsPrimitiveType() && Nullable.GetUnderlyingType(leftSideType) != null)
                {
                    rightExpression = Expression.Constant(null, leftSideType);
                }
                generatedExpression = Expression.Equal(leftExpression, rightExpression);
                break;

            case Operator.NotIsNull:
                if (leftSideType.IsPrimitiveType() && Nullable.GetUnderlyingType(leftSideType) != null)
                {
                    rightExpression = Expression.Constant(null, leftSideType);
                }
                generatedExpression = Expression.Not(Expression.Equal(leftExpression, rightExpression));
                break;

            case Operator.IsEmpty:
                generatedExpression = new IsEmpty(leftExpression, rightExpression).Create();
                break;

            case Operator.NotIsEmpty:
                generatedExpression = Expression.Not(new IsEmpty(leftExpression, rightExpression).Create());
                break;

            case Operator.DiffWithinPct:
                generatedExpression = new DiffWithinPct(leftExpression, rightExpression, OperatorArgs).Create();
                break;

            case Operator.AllInRangePct:
                generatedExpression = new AllInRange(leftExpression, rightExpression, OperatorArgs).Create();
                break;

            default:
                throw new NotSupportedException($"operation {Operator} is not supported");
            }

            if (Operator == Operator.IsNull || Operator == Operator.NotIsNull)
            {
                return(generatedExpression);
            }

            return(leftExpression.AddNotNullCheck(out var nullCheckExpression)
                ? Expression.AndAlso(nullCheckExpression, generatedExpression)
                : generatedExpression);
        }
Esempio n. 2
0
        public static void DrawTrajectory(GameSession gameSession, ICelestialObject spaceShip, ICelestialObject targetObject, Graphics graphics, ScreenParameters screenParameters)
        {
            var pointCurrentLocation      = new PointF(spaceShip.PositionX, spaceShip.PositionY);
            var pointTargetLocation       = new PointF(targetObject.PositionX, targetObject.PositionY);
            var pointCenterTargetLocation = new PointF(targetObject.PositionX, targetObject.PositionY);
            var prevPointCurrentLocation  = new PointF(spaceShip.PositionX, spaceShip.PositionY);

            List <ObjectLocation> result = null;

            var movementType = gameSession.GetMovementType(spaceShip.Id);

            if (movementType == CommandTypes.Orbit)
            {
                var trajectoryOrbit = AllIn.GetRadiusPoint(spaceShip.GetLocation(), pointTargetLocation, 50, spaceShip.Direction, spaceShip.Speed);

                pointTargetLocation = new Point((int)trajectoryOrbit.StartPoint.X, (int)trajectoryOrbit.StartPoint.Y);

                result = AllIn.GetTrajectoryOrbit(pointCurrentLocation, pointTargetLocation, spaceShip.Direction, spaceShip.Speed, 200);
            }

            if (movementType == CommandTypes.AlignTo)
            {
                result = AllIn.GetTrajectoryApproach(pointCurrentLocation, pointTargetLocation, spaceShip.Direction, spaceShip.Speed, 200);
            }


            int temp      = 0;
            int iteration = 0;

            var screenCurrentObjectLocation  = new PointF(0, 0);
            var screenPreviousObjectLocation = new PointF(0, 0);

            bool isDrawConnectionLine = true;

            var points = new List <PointF>();;

            foreach (var objectLocation in result)
            {
                screenCurrentObjectLocation = UI.ToScreenCoordinates(screenParameters, objectLocation.Coordinates);

                points.Add(new PointF(screenCurrentObjectLocation.X, screenCurrentObjectLocation.Y));
            }


            if (points.Count < 2)
            {
                return;
            }

            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            // Draw arc to screen.
            graphics.DrawLines(new Pen(Color.FromArgb(18, 18, 18), 4), points.ToArray());
            graphics.DrawLines(new Pen(Color.FromArgb(22, 22, 22), 2), points.ToArray());
            graphics.DrawLines(new Pen(Color.FromArgb(28, 28, 28), 1), points.ToArray());

            var pen = new Pen(Color.Red, 1);// { StartCap = LineCap.ArrowAnchor };

            foreach (var objectLocation in result)
            {
                iteration++;

                screenCurrentObjectLocation  = UI.ToScreenCoordinates(screenParameters, objectLocation.Coordinates);
                screenPreviousObjectLocation = UI.ToScreenCoordinates(screenParameters, prevPointCurrentLocation);

                PointF[] linePoints =
                {
                    new PointF(screenCurrentObjectLocation.X,  screenCurrentObjectLocation.Y),
                    new PointF(screenPreviousObjectLocation.X, screenPreviousObjectLocation.Y)
                };

                graphics.DrawLines(pen, linePoints);

                prevPointCurrentLocation = new PointF(objectLocation.Coordinates.X, objectLocation.Coordinates.Y);

                //temp++;
                //if (temp == 1)
                //{
                //    temp = 0;
                //    graphics.FillEllipse(new SolidBrush(Color.DarkOliveGreen), screenCurrentObjectLocation.X - 1, screenCurrentObjectLocation.Y - 1, 3, 3);
                //}

                if (objectLocation.IsLinearMotion && isDrawConnectionLine)
                {
                    //graphics.FillEllipse(new SolidBrush(Color.Yellow), screenCurrentObjectLocation.X - 1, screenCurrentObjectLocation.Y - 1, 3, 3);

                    //isDrawConnectionLine = false;
                }

                //Logger.Debug($"iteration = {iteration} Coordinates = {objectLocation.Coordinates} IsLinearMotion = {objectLocation.IsLinearMotion} VectorToTarget = {objectLocation.VectorToTarget} Direction = {objectLocation.Direction} ScanRange = {objectLocation.ScanRange}");
            }



            if (movementType == CommandTypes.Orbit)
            {
                var trajectoryOrbit = AllIn.GetRadiusPoint(spaceShip.GetLocation(), pointTargetLocation, 50, spaceShip.Direction, spaceShip.Speed);

                var orbitRadius = 50;

                var lastPoint = points[points.Count - 1];

                var pointTargetCenter = UI.ToScreenCoordinates(screenParameters, pointCenterTargetLocation);

                //graphics.DrawLine(pen, lastWeyPointLocation.X, lastWeyPointLocation.Y, pointTargetCenter.X, pointTargetCenter.Y);
                graphics.DrawEllipse(pen, pointTargetCenter.X - orbitRadius, pointTargetCenter.Y - orbitRadius, orbitRadius * 2, orbitRadius * 2);

                var pointOrbitPoint = UI.ToScreenCoordinates(screenParameters, pointCenterTargetLocation);

                graphics.DrawEllipse(new Pen(new SolidBrush(Color.Coral), 1), pointOrbitPoint.X - 1, pointOrbitPoint.Y - 1, 5, 5);
                graphics.DrawEllipse(new Pen(new SolidBrush(Color.Goldenrod), 1), lastPoint.X - 1, lastPoint.Y - 1, 5, 5);

                var lastPointCoordinates = UI.ToMapCoordinates(screenParameters, lastPoint);

                var angleFirstOrbitPoint = Coordinates.GetRotation(lastPointCoordinates, pointCenterTargetLocation);

                for (int i = 0; i < 15; i++)
                {
                    var secondOrbitPoint = Coordinates.RotatePoint(pointCenterTargetLocation, orbitRadius, angleFirstOrbitPoint + trajectoryOrbit.Direction * i * 10);

                    var secondOrbitPointCoordinates = UI.ToScreenCoordinates(screenParameters, secondOrbitPoint);

                    graphics.DrawEllipse(new Pen(new SolidBrush(Color.GreenYellow), 1), secondOrbitPointCoordinates.X - 1, secondOrbitPointCoordinates.Y - 1, 5, 5);
                }


                //var thirdOrbitPointCoordinates = UI.ToScreenCoordinates(screenParameters, thirdOrbitPoint);



                ////double theta = Math.Tan(Math.atan2(y - cy, x - cx));
                //var X = thirdOrbitPointCoordinates.X + 100 * Math.Cos(angleFirstOrbitPoint);
                //var Y = thirdOrbitPointCoordinates.Y + 100 * Math.Sin(angleFirstOrbitPoint);

                //graphics.DrawEllipse(new Pen(new SolidBrush(Color.BlueViolet), 1), (int)(X - 1), (int)(Y - 1), 5, 5);
            }
        }